# lliutianc/roselora architecture

> Architecture diagram of the GitHub repository lliutianc/roselora, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lliutianc/roselora
- Repository: https://github.com/lliutianc/roselora

## Overview

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: [`examples/run_zsre.py`](https://github.com/lliutianc/roselora/blob/main/examples/run_zsre.py) (Experiment runner), [`easyeditor/editors/editor.py`](https://github.com/lliutianc/roselora/blob/main/easyeditor/editors/editor.py) (Editor), [`easyeditor/models/roselora/roselora_main.py`](https://github.com/lliutianc/roselora/blob/main/easyeditor/models/roselora/roselora_main.py) (RoseLoRA core), [`easyeditor/trainer/BaseTrainer.py`](https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/BaseTrainer.py) (Trainer base)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_examples["Examples"]
  node_node_run_script["Run script<br/>shell entrypoint<br/>[run_zsre.sh]"]
  node_node_run_py["Experiment runner<br/>python entrypoint<br/>[run_zsre.py]"]
  node_node_zsre_data[("ZsRE data<br/>benchmark data")]
end

subgraph group_group_config["Config"]
  node_node_roselora_yaml["RoseLoRA hparams<br/>yaml config<br/>[llama-7b.yaml]"]
  node_node_config_yaml["Shared config<br/>yaml config<br/>[config.yaml]"]
end

subgraph group_group_easyeditor["EasyEditor core"]
  node_node_hparams_loader["Hparams loader<br/>config loader<br/>[hparams.py]"]
  node_node_dataset_core["Dataset layer<br/>dataset subsystem<br/>[__init__.py]"]
  node_node_processor_core["Processors<br/>normalization layer<br/>[base_processor.py]"]
  node_node_editor["Editor<br/>edit orchestration<br/>[editor.py]"]
  node_node_batch_editor["Batch editor<br/>edit orchestration<br/>[batch_editor.py]"]
  node_node_trainer_base["Trainer base<br/>training framework<br/>[BaseTrainer.py]"]
  node_node_edit_trainer["Edit trainer<br/>training mode<br/>[EditTrainer.py]"]
  node_node_multimodal_trainer["Multimodal trainer<br/>training mode"]
  node_node_eval_core["Evaluation<br/>metrics layer<br/>[evaluate.py]"]
  node_node_multimodal_eval["Multimodal eval<br/>metrics layer"]
  node_node_utilities["Runtime utils<br/>shared utilities<br/>[generate.py]"]
end

subgraph group_group_roselora["RoseLoRA"]
  node_node_roselora_main["RoseLoRA core<br/>edit algorithm<br/>[roselora_main.py]"]
  node_node_roselora_hparams["RoseLoRA params<br/>algorithm hparams"]
end

node_node_run_script -->|"invokes"| node_node_run_py
node_node_run_py -->|"loads"| node_node_roselora_yaml
node_node_run_py -->|"reads"| node_node_zsre_data
node_node_roselora_yaml -->|"parsed by"| node_node_hparams_loader
node_node_config_yaml -->|"parsed by"| node_node_hparams_loader
node_node_hparams_loader -->|"configures"| node_node_editor
node_node_zsre_data -->|"normalized by"| node_node_dataset_core
node_node_dataset_core -->|"uses"| node_node_processor_core
node_node_run_py -->|"orchestrates"| node_node_editor
node_node_editor -->|"delegates batch work"| node_node_batch_editor
node_node_editor -->|"applies"| node_node_roselora_main
node_node_roselora_main -->|"reads"| node_node_roselora_hparams
node_node_roselora_main -->|"uses"| node_node_utilities
node_node_editor -->|"can train via"| node_node_trainer_base
node_node_trainer_base -->|"specializes into"| node_node_edit_trainer
node_node_trainer_base -->|"specializes into"| node_node_multimodal_trainer
node_node_edit_trainer -->|"executes"| node_node_roselora_main
node_node_edit_trainer -->|"reports to"| node_node_eval_core
node_node_multimodal_trainer -->|"reports to"| node_node_multimodal_eval
node_node_eval_core -->|"uses"| node_node_utilities
node_node_multimodal_eval -->|"uses"| node_node_utilities
node_node_run_py -->|"triggers"| node_node_eval_core

click node_node_run_script "https://github.com/lliutianc/roselora/blob/main/examples/run_zsre.sh"
click node_node_run_py "https://github.com/lliutianc/roselora/blob/main/examples/run_zsre.py"
click node_node_zsre_data "https://github.com/lliutianc/roselora/blob/main/examples/data/ZsRE/zsre_mend_edit.json"
click node_node_roselora_yaml "https://github.com/lliutianc/roselora/blob/main/hparams/RoseLoRA/llama-7b.yaml"
click node_node_config_yaml "https://github.com/lliutianc/roselora/blob/main/hparams/config.yaml"
click node_node_hparams_loader "https://github.com/lliutianc/roselora/blob/main/easyeditor/util/hparams.py"
click node_node_dataset_core "https://github.com/lliutianc/roselora/blob/main/easyeditor/dataset/__init__.py"
click node_node_processor_core "https://github.com/lliutianc/roselora/blob/main/easyeditor/dataset/processor/base_processor.py"
click node_node_editor "https://github.com/lliutianc/roselora/blob/main/easyeditor/editors/editor.py"
click node_node_batch_editor "https://github.com/lliutianc/roselora/blob/main/easyeditor/editors/batch_editor.py"
click node_node_roselora_main "https://github.com/lliutianc/roselora/blob/main/easyeditor/models/roselora/roselora_main.py"
click node_node_roselora_hparams "https://github.com/lliutianc/roselora/blob/main/easyeditor/models/roselora/roselora_hparams.py"
click node_node_trainer_base "https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/BaseTrainer.py"
click node_node_edit_trainer "https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/EditTrainer.py"
click node_node_multimodal_trainer "https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/MultimodalTrainer.py"
click node_node_eval_core "https://github.com/lliutianc/roselora/blob/main/easyeditor/evaluate/evaluate.py"
click node_node_multimodal_eval "https://github.com/lliutianc/roselora/blob/main/easyeditor/evaluate/multimodal_evaluate.py"
click node_node_utilities "https://github.com/lliutianc/roselora/blob/main/easyeditor/util/generate.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_run_script,node_node_run_py,node_node_zsre_data toneBlue
class node_node_roselora_yaml,node_node_config_yaml toneAmber
class node_node_hparams_loader,node_node_dataset_core,node_node_processor_core,node_node_editor,node_node_batch_editor,node_node_trainer_base,node_node_edit_trainer,node_node_multimodal_trainer,node_node_eval_core,node_node_multimodal_eval,node_node_utilities toneMint
class node_node_roselora_main,node_node_roselora_hparams toneRose
```

## Components

### Examples

Entry scripts and included benchmark data

- [Run script](https://github.com/lliutianc/roselora/blob/main/examples/run_zsre.sh): shell entrypoint · Launches the ZsRE experiment with runtime flags and hparams selection · `examples/run_zsre.sh`
- [Experiment runner](https://github.com/lliutianc/roselora/blob/main/examples/run_zsre.py): python entrypoint · Coordinates dataset loading, editor setup, and evaluation for ZsRE runs · `examples/run_zsre.py`
- [ZsRE data](https://github.com/lliutianc/roselora/blob/main/examples/data/ZsRE/zsre_mend_edit.json): benchmark data · Included editing benchmark examples and training splits · `examples/data/ZsRE/zsre_mend_edit.json`

### Config

Experiment and hyperparameter definitions

- [RoseLoRA hparams](https://github.com/lliutianc/roselora/blob/main/hparams/RoseLoRA/llama-7b.yaml): yaml config · Primary RoseLoRA experiment configuration for LLaMA-7B · `hparams/RoseLoRA/llama-7b.yaml`
- [Shared config](https://github.com/lliutianc/roselora/blob/main/hparams/config.yaml): yaml config · Top-level shared configuration defaults · `hparams/config.yaml`

### EasyEditor core

Shared editing, dataset, training, and evaluation layers

- [Hparams loader](https://github.com/lliutianc/roselora/blob/main/easyeditor/util/hparams.py): config loader · Loads and normalizes hyperparameter definitions for experiments · `easyeditor/util/hparams.py`
- [Dataset layer](https://github.com/lliutianc/roselora/blob/main/easyeditor/dataset/__init__.py): dataset subsystem · Dataset registry for editing and evaluation tasks across text and multimodal benchmarks · `easyeditor/dataset/__init__.py`
- [Processors](https://github.com/lliutianc/roselora/blob/main/easyeditor/dataset/processor/base_processor.py): normalization layer · Base dataset and processor abstractions for task-specific example normalization · `easyeditor/dataset/processor/base_processor.py`
- [Editor](https://github.com/lliutianc/roselora/blob/main/easyeditor/editors/editor.py): edit orchestration · High-level single-edit orchestration over a selected algorithm · `easyeditor/editors/editor.py`
- [Batch editor](https://github.com/lliutianc/roselora/blob/main/easyeditor/editors/batch_editor.py): edit orchestration · Batched editing interface for repeated or sequential edits · `easyeditor/editors/batch_editor.py`
- [Trainer base](https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/BaseTrainer.py): training framework · Shared training orchestration for editing algorithms · `easyeditor/trainer/BaseTrainer.py`
- [Edit trainer](https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/EditTrainer.py): training mode · Main trainer for editing workflows and algorithm execution · `easyeditor/trainer/EditTrainer.py`
- [Multimodal trainer](https://github.com/lliutianc/roselora/blob/main/easyeditor/trainer/MultimodalTrainer.py): training mode · Trainer path for multimodal editing workloads · `easyeditor/trainer/MultimodalTrainer.py`
- [Evaluation](https://github.com/lliutianc/roselora/blob/main/easyeditor/evaluate/evaluate.py): metrics layer · Computes edit success, locality, generalization, and task-specific metrics · `easyeditor/evaluate/evaluate.py`
- [Multimodal eval](https://github.com/lliutianc/roselora/blob/main/easyeditor/evaluate/multimodal_evaluate.py): metrics layer · Evaluation routines for multimodal editing tasks · `easyeditor/evaluate/multimodal_evaluate.py`
- [Runtime utils](https://github.com/lliutianc/roselora/blob/main/easyeditor/util/generate.py): shared utilities · Generation, hooks, perplexity, logit-lens, and other model-inspection helpers · `easyeditor/util/generate.py`

### RoseLoRA

Algorithm-specific implementation

- [RoseLoRA core](https://github.com/lliutianc/roselora/blob/main/easyeditor/models/roselora/roselora_main.py): edit algorithm · Implements RoseLoRA execution including warmup and target sparsity scheduling · `easyeditor/models/roselora/roselora_main.py`
- [RoseLoRA params](https://github.com/lliutianc/roselora/blob/main/easyeditor/models/roselora/roselora_hparams.py): algorithm hparams · RoseLoRA-specific hyperparameter definitions and schema · `easyeditor/models/roselora/roselora_hparams.py`

## Connections

- 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
