How lliutianc/roselora works
1. What this repo is
- This is a Python research codebase for knowledge editing / fine-tuning of pretrained language models.
- The core implementation is RoseLoRA: a sparse low-rank adaptation method with a warmup stage that gradually increases sparsity to the target level.
- The repo is adapted from EasyEdit, but this fork is trimmed to the pieces needed for RoseLoRA.
2. Primary execution path
- The main experiment flow is driven from examples/run_zsre.sh and examples/run_zsre.py.
- The ZsRE example dataset under examples/data/ZsRE/ is the included concrete benchmark path.
- Runtime parameters such as edit method, GPU, sample count, sequential edit length, and model choice are controlled by the shell script and YAML hparams.
3. Configuration boundary
- Experiment settings live in hparams/, especially hparams/RoseLoRA/llama-7b.yaml.
- easyeditor/util/hparams.py and related config files provide the shared hyperparameter loading layer.
- This is the repo’s main boundary between “experiment definition” and “training/editing code.”
4. Dataset subsystem
- easyeditor/dataset/ contains loaders for multiple editing/evaluation datasets: counterfact, zsre, knowedit, mquake, wiki_recent, personality, safety, vqa, coco_caption, and others.
- easyeditor/dataset/processor/ normalizes raw examples into task-specific formats through base processor/dataset abstractions and image processors for multimodal tasks.
- Even though the README says RoseLoRA is the supported path, the dataset layer is still a shared abstraction for text and multimodal editing tasks.
5. Editing orchestration layer
- easyeditor/editors/ provides the high-level editing interfaces: Editor, BatchEditor, and helper utilities.
- This layer is the boundary that takes a prepared edit request, applies the chosen algorithm, and returns edited model behavior.
- Conceptually, it sits above the training algorithms and below the dataset/task runner.
6. RoseLoRA model implementation
- easyeditor/models/roselora/ holds the RoseLoRA-specific implementation: hyperparameters and the main algorithm entry logic.
- This is the algorithm-specific center of the repo, where sparse low-rank adaptation is realized.
- The README’s mention of execute_roselora in roselora_main.py indicates this is where the warmup-to-target-sparsity schedule is executed.
7. Training subsystem
- easyeditor/trainer/ contains the training framework and algorithm implementations.
- BaseTrainer.py, EditTrainer.py, MultiTaskTrainer.py, MultimodalTrainer.py, and PerTrainer.py provide different orchestration modes.
- easyeditor/trainer/algs/ includes algorithm modules such as MEND, MALMEN, SERAC, and ft, but in this repo they are mostly part of the inherited framework rather than the README-supported focus.
- training_hparams/ defines algorithm-specific training configurations.
8. Model-backbone support
- easyeditor/trainer/blip2_models/ contains the multimodal model stack: BLIP2, Q-former, CLIP ViT, EVA ViT, MiniGPT-4, and OPT/LLaMA-related model wrappers.
- This indicates the framework was designed to support both text-only and multimodal editing.
- For RoseLoRA’s advertised use case, the main backbone path is the LLaMA-2-7B-Chat model referenced in the README.
9. Evaluation subsystem
- easyeditor/evaluate/ computes task-specific metrics for editing quality.
- There are separate evaluation modules for standard editing, multimodal editing, personality, safety, and concept-based evaluation.
- This is the repo’s output boundary: after editing, metrics are computed for edit success, locality/generalization, and other task-specific behaviors.
10. Shared utilities and runtime helpers
- easyeditor/util/ contains cross-cutting helpers: generation, hooks into model internals, perplexity, running statistics, logit-lens tools, and algorithm registries.
- These utilities are what make model inspection and controlled editing possible without duplicating model-specific code across trainers and evaluators.
11. Data flow at a high level
- A dataset example is loaded and normalized by the dataset/processor layer.
- The editor/trainer loads the chosen backbone and RoseLoRA hyperparameters.
- RoseLoRA applies a sparsity-aware low-rank update during the edit pass.
- Evaluation then measures edit outcomes on the edited model and logs the results.
12. Important architectural takeaway
- The repo is organized as a three-layer pipeline: data preparation → editing/training algorithm → evaluation.
- RoseLoRA is the only officially supported edit method in this fork, while the rest of the tree preserves the reusable EasyEdit architecture around it.
Main entry points: run_zsre.py Experiment runner · editor.py Editor · roselora_main.py RoseLoRA core · BaseTrainer.py Trainer base
Components 18
Examples
Entry scripts and included benchmark data
- Run script · Launches the ZsRE experiment with runtime flags and hparams selection
examples/run_zsre.sh - Experiment runner · Coordinates dataset loading, editor setup, and evaluation for ZsRE runs
examples/run_zsre.py - ZsRE data · Included editing benchmark examples and training splits
examples/data/ZsRE/zsre_mend_edit.json
Config
Experiment and hyperparameter definitions
- RoseLoRA hparams · Primary RoseLoRA experiment configuration for LLaMA-7B
hparams/RoseLoRA/llama-7b.yaml - Shared config · Top-level shared configuration defaults
hparams/config.yaml
EasyEditor core
Shared editing, dataset, training, and evaluation layers
- Hparams loader · Loads and normalizes hyperparameter definitions for experiments
easyeditor/util/hparams.py - Dataset layer · Dataset registry for editing and evaluation tasks across text and multimodal benchmarks
easyeditor/dataset/__init__.py - Processors · Base dataset and processor abstractions for task-specific example normalization
easyeditor/dataset/processor/base_processor.py - Editor · High-level single-edit orchestration over a selected algorithm
easyeditor/editors/editor.py - Batch editor · Batched editing interface for repeated or sequential edits
easyeditor/editors/batch_editor.py - Trainer base · Shared training orchestration for editing algorithms
easyeditor/trainer/BaseTrainer.py - Edit trainer · Main trainer for editing workflows and algorithm execution
easyeditor/trainer/EditTrainer.py - Multimodal trainer · Trainer path for multimodal editing workloads
easyeditor/trainer/MultimodalTrainer.py - Evaluation · Computes edit success, locality, generalization, and task-specific metrics
easyeditor/evaluate/evaluate.py - Multimodal eval · Evaluation routines for multimodal editing tasks
easyeditor/evaluate/multimodal_evaluate.py - Runtime utils · Generation, hooks, perplexity, logit-lens, and other model-inspection helpers
easyeditor/util/generate.py
RoseLoRA
Algorithm-specific implementation
- RoseLoRA core · Implements RoseLoRA execution including warmup and target sparsity scheduling
easyeditor/models/roselora/roselora_main.py - RoseLoRA params · RoseLoRA-specific hyperparameter definitions and schema
easyeditor/models/roselora/roselora_hparams.py
Connections 22
- Run script → Experiment runner: invokes · Shell wrapper starts the Python experiment runner
- Experiment runner → RoseLoRA hparams: loads · Runner selects the RoseLoRA hyperparameter preset
- Experiment runner → ZsRE data: reads · Runner consumes the included ZsRE benchmark data
- RoseLoRA hparams → Hparams loader: parsed by · Algorithm config is loaded through the shared hyperparameter layer
- Shared config → Hparams loader: parsed by · Shared defaults are also normalized by the loader
- Hparams loader → Editor: configures · Loaded settings initialize the editing interface
- ZsRE data → Dataset layer: normalized by · Raw benchmark records flow through the dataset abstraction
- Dataset layer → Processors: uses · Dataset layer relies on processors to standardize examples
- Experiment runner → Editor: orchestrates · Main runner constructs and drives the editor
- Editor → Batch editor: delegates batch work · Editor can route repeated edits through batch orchestration
- Editor → RoseLoRA core: applies · Editor calls the RoseLoRA algorithm to perform the edit
- RoseLoRA core → RoseLoRA params: reads · Algorithm execution is parameterized by RoseLoRA-specific settings
- RoseLoRA core → Runtime utils: uses · Algorithm relies on shared hooks and generation utilities
- Editor → Trainer base: can train via · Editing interface connects to the trainer framework for optimization-based paths
- Trainer base → Edit trainer: specializes into · EditTrainer is the primary editing training mode
- Trainer base → Multimodal trainer: specializes into · MultimodalTrainer handles image-text editing flows
- Edit trainer → RoseLoRA core: executes · Training path can invoke the RoseLoRA algorithm implementation
- Edit trainer → Evaluation: reports to · Trainer output is measured by the evaluation subsystem
- Multimodal trainer → Multimodal eval: reports to · Multimodal training path is assessed by multimodal metrics
- Evaluation → Runtime utils: uses · Evaluation depends on shared generation and analysis helpers
- Multimodal eval → Runtime utils: uses · Multimodal metrics reuse common runtime helpers
- Experiment runner → Evaluation: triggers · Experiment runner finishes by computing evaluation metrics