# ise-uiuc/magicoder architecture

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

- Interactive diagram: https://gitdiagram.com/ise-uiuc/magicoder
- Repository: https://github.com/ise-uiuc/magicoder

## Overview

1. **Repository purpose**
   - This is an ML/research repository for **Magicoder**, a family of code-generation models and the **OSS-Instruct** data pipeline used to train them.
   - The repo is not a full application; it is a **data generation, filtering, training, and evaluation** stack around code LLMs.

2. **Top-level architecture**
   - The codebase splits into three main surfaces:
     - **`src/magicoder/`**: reusable library code for data processing, decontamination, prompting, model I/O, and training.
     - **`experiments/`**: one-off analysis and ablation scripts used in the paper.
     - **`demo/`**: a local Gradio inference demo for serving a trained checkpoint.
   - `README.md` also documents external Hugging Face checkpoints and datasets, which are outputs of the pipeline rather than core code.

3. **Core data-generation pipeline**
   - The central flow is: **open-source code snippets → prompt construction → LLM synthesis → cleaning/deduplication → training data**.
   - `src/magicoder/prompt_template.py` defines the instruction format used to turn code references into OSS-Instruct-style prompts.
   - `src/magicoder/llm_wrapper.py` abstracts calls to the generator model used during data synthesis.
   - `src/magicoder/generate_data.py` is the orchestration layer that produces synthetic instruction-code pairs.

4. **Data preparation and quality control**
   - `src/magicoder/clean_data.py` handles post-generation cleanup of raw synthetic examples.
   - `src/magicoder/minhash_deduplication.py` provides near-duplicate removal, which is important because the generation process can produce repeated or overly similar samples.
   - `src/magicoder/preprocess_data.py` prepares cleaned data into the format expected by downstream training.

5. **Decontamination boundary**
   - The `src/magicoder/decontamination/` package is a separate subsystem used to prevent benchmark leakage.
   - `benchmark_data.py` loads benchmark references, `find_substrings.py` searches for overlap, and `utils.py` supports the matching workflow.
   - This boundary exists to ensure training or synthetic data does not contain benchmark solutions or near-copies from tasks like HumanEval, MBPP, or related evaluation sets.

6. **Training subsystem**
   - `src/magicoder/train.py` is the model fine-tuning entry point.
   - It consumes the prepared instruction-code dataset and trains the Magicoder variants described in the README.
   - The repo does not appear to define the base model architecture itself; it assumes a pretrained code LLM checkpoint and fine-tunes it on OSS-Instruct-style data.

7. **Evaluation and experiment workflows**
   - `experiments/` contains analysis scripts used to justify the data design and compare variants.
   - The scripts suggest several experiment families:
     - `text2code.py` and `lang_ablation.py` for model/data ablations,
     - `train_comment_code_pairs.py` and `extract_function_comment_pairs.py` for alternative supervision sources,
     - `ds_1000.py` for benchmark-oriented evaluation,
     - `avg_multipl_e.py`, `collect_seed_documents.py`, and `data_embedding/*` for similarity and embedding analyses.
   - These are research-side workflows, not production runtime code.

8. **Demo/inference path**
   - `demo/magicoder_demo.py` provides a local **Gradio** app for interactive generation.
   - The demo loads a Hugging Face model checkpoint and runs text generation through the Transformers stack, typically on GPU.
   - This is the only visible serving surface; it is separate from training and data-generation internals.

9. **External dependencies and integration points**
   - The repository is tightly coupled to the **Hugging Face ecosystem** for model checkpoints and datasets.
   - The README explicitly calls out synthetic data generation with **`gpt-3.5-turbo-1106`** and model families based on **DeepSeek-Coder** and **CodeLlama**.
   - Evaluation is centered on code benchmarks such as **HumanEval**, **MBPP**, and **EvalPlus**.

10. **Repository-level boundaries**
    - **Library code (`src/magicoder`)**: reusable logic for prompting, cleaning, decontamination, and training.
    - **Experiment scripts (`experiments`)**: paper-specific analysis and ablation studies.
    - **Demo (`demo`)**: inference-only UI layer.
    - **Data/assets (`data`, `assets`)**: prompt text, figures, and reference materials used by the pipeline and documentation.

11. **Likely end-to-end flow for architecture diagrams**
    - A source-code corpus is sampled or assembled, then passed through OSS-Instruct prompting and LLM generation.
    - Generated samples are cleaned, deduplicated, and decontaminated against benchmark data.
    - The resulting dataset is preprocessed and used to fine-tune a pretrained code model.
    - The trained checkpoint is then evaluated on code benchmarks or exposed through the Gradio demo.

12. **Tooling footprint**
    - The project is Python-based, managed with **PDM** (`pyproject.toml`, `pdm.lock`).
    - There is a lightweight test scaffold under `tests/`, but the main repo identity is research code rather than a heavily test-driven application.

Main entry points: [`src/magicoder/train.py`](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/train.py) (Train), [`src/magicoder/decontamination/find_substrings.py`](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/find_substrings.py) (Overlap search), [`src/magicoder/generate_data.py`](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/generate_data.py) (Data synth), [`README.md`](https://github.com/ise-uiuc/magicoder/blob/main/README.md) (README)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_src["Library"]
  node_node_prompt["Prompt format<br/>prompting<br/>[prompt_template.py]"]
  node_node_llm["LLM wrapper<br/>generation api<br/>[llm_wrapper.py]"]
  node_node_generate["Data synth<br/>orchestration<br/>[generate_data.py]"]
  node_node_clean["Clean data<br/>postprocess<br/>[clean_data.py]"]
  node_node_dedup["Deduplication<br/>near-duplicate filter"]
  node_node_preprocess["Preprocess<br/>dataset prep<br/>[preprocess_data.py]"]
  node_node_train["Train<br/>fine-tuning<br/>[train.py]"]
  node_node_decon_bench[("Benchmark refs<br/>decontamination data<br/>[benchmark_data.py]")]
  node_node_decon_find["Overlap search<br/>decontamination<br/>[find_substrings.py]"]
  node_node_decon_utils["Decon utils<br/>supporting logic<br/>[utils.py]"]
end

subgraph group_group_exp["Experiments"]
  node_node_text2code["Text2code<br/>ablation script<br/>[text2code.py]"]
  node_node_lang_ablation["Lang ablation<br/>analysis script<br/>[lang_ablation.py]"]
  node_node_pairs["Comment pairs<br/>alternative supervision"]
  node_node_ds1000["DS-1000 eval<br/>benchmark eval<br/>[ds_1000.py]"]
  node_node_embedding["Embedding analysis<br/>similarity analysis"]
  node_node_collect["Seed docs<br/>analysis script"]
end

subgraph group_group_demo["Demo"]
  node_node_demo["Gradio demo<br/>inference ui<br/>[magicoder_demo.py]"]
end

subgraph group_group_data["Data & assets"]
  node_node_promptfile["Prompt text<br/>asset<br/>[prompt.txt]"]
  node_node_readme["README<br/>documentation<br/>[README.md]"]
end

node_node_promptfile -->|"template source"| node_node_prompt
node_node_prompt -->|"constructs prompts"| node_node_generate
node_node_llm -->|"generates samples"| node_node_generate
node_node_generate -->|"raw data"| node_node_clean
node_node_clean -->|"cleaned data"| node_node_dedup
node_node_dedup -->|"check leakage"| node_node_decon_find
node_node_decon_bench -->|"benchmark corpus"| node_node_decon_find
node_node_decon_utils -->|"helpers"| node_node_decon_find
node_node_decon_find -->|"filtered data"| node_node_preprocess
node_node_preprocess -->|"train set"| node_node_train
node_node_train -->|"checkpoint"| node_node_demo
node_node_train -->|"evaluate"| node_node_ds1000
node_node_collect -->|"seed corpus"| node_node_embedding
node_node_embedding -.->|"analysis inputs"| node_node_text2code
node_node_pairs -.->|"alt supervision"| node_node_train
node_node_lang_ablation -.->|"compare variants"| node_node_text2code
node_node_readme -.->|"usage notes"| node_node_demo
node_node_readme -.->|"workflow docs"| node_node_train

click node_node_prompt "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/prompt_template.py"
click node_node_llm "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/llm_wrapper.py"
click node_node_generate "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/generate_data.py"
click node_node_clean "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/clean_data.py"
click node_node_dedup "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/minhash_deduplication.py"
click node_node_preprocess "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/preprocess_data.py"
click node_node_train "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/train.py"
click node_node_decon_bench "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/benchmark_data.py"
click node_node_decon_find "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/find_substrings.py"
click node_node_decon_utils "https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/utils.py"
click node_node_text2code "https://github.com/ise-uiuc/magicoder/blob/main/experiments/text2code.py"
click node_node_lang_ablation "https://github.com/ise-uiuc/magicoder/blob/main/experiments/lang_ablation.py"
click node_node_pairs "https://github.com/ise-uiuc/magicoder/blob/main/experiments/extract_function_comment_pairs.py"
click node_node_ds1000 "https://github.com/ise-uiuc/magicoder/blob/main/experiments/ds_1000.py"
click node_node_embedding "https://github.com/ise-uiuc/magicoder/blob/main/experiments/data_embedding/instructor_embedding.py"
click node_node_collect "https://github.com/ise-uiuc/magicoder/blob/main/experiments/collect_seed_documents.py"
click node_node_demo "https://github.com/ise-uiuc/magicoder/blob/main/demo/magicoder_demo.py"
click node_node_promptfile "https://github.com/ise-uiuc/magicoder/blob/main/data/prompt.txt"
click node_node_readme "https://github.com/ise-uiuc/magicoder/blob/main/README.md"

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_prompt,node_node_llm,node_node_generate,node_node_clean,node_node_dedup,node_node_preprocess,node_node_train,node_node_decon_bench,node_node_decon_find,node_node_decon_utils toneBlue
class node_node_text2code,node_node_lang_ablation,node_node_pairs,node_node_ds1000,node_node_embedding,node_node_collect toneAmber
class node_node_demo toneMint
class node_node_promptfile,node_node_readme toneRose
```

## Components

### Library

Reusable Magicoder pipeline code under src/magicoder

- [Prompt format](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/prompt_template.py): prompting · Builds OSS-Instruct-style instructions from code references · `src/magicoder/prompt_template.py`
- [LLM wrapper](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/llm_wrapper.py): generation api · Abstracts calls to the synthesis model · `src/magicoder/llm_wrapper.py`
- [Data synth](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/generate_data.py): orchestration · Coordinates prompt creation and synthetic example generation · `src/magicoder/generate_data.py`
- [Clean data](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/clean_data.py): postprocess · Cleans and normalizes raw generated examples · `src/magicoder/clean_data.py`
- [Deduplication](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/minhash_deduplication.py): near-duplicate filter · Removes similar or repeated samples with MinHash · `src/magicoder/minhash_deduplication.py`
- [Preprocess](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/preprocess_data.py): dataset prep · Converts cleaned data into training-ready format · `src/magicoder/preprocess_data.py`
- [Train](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/train.py): fine-tuning · Fine-tunes pretrained code LLM checkpoints on prepared data · `src/magicoder/train.py`
- [Benchmark refs](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/benchmark_data.py): decontamination data · Loads benchmark examples for leakage checks · `src/magicoder/decontamination/benchmark_data.py`
- [Overlap search](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/find_substrings.py): decontamination · Finds substring matches and benchmark overlap · `src/magicoder/decontamination/find_substrings.py`
- [Decon utils](https://github.com/ise-uiuc/magicoder/blob/main/src/magicoder/decontamination/utils.py): supporting logic · Helpers for the decontamination workflow · `src/magicoder/decontamination/utils.py`

### Experiments

Research scripts for ablations and analysis

- [Text2code](https://github.com/ise-uiuc/magicoder/blob/main/experiments/text2code.py): ablation script · Runs model and data ablations for code generation · `experiments/text2code.py`
- [Lang ablation](https://github.com/ise-uiuc/magicoder/blob/main/experiments/lang_ablation.py): analysis script · Compares language or data variants · `experiments/lang_ablation.py`
- [Comment pairs](https://github.com/ise-uiuc/magicoder/blob/main/experiments/extract_function_comment_pairs.py): alternative supervision · Extracts and trains on function-comment pairs · `experiments/extract_function_comment_pairs.py`
- [DS-1000 eval](https://github.com/ise-uiuc/magicoder/blob/main/experiments/ds_1000.py): benchmark eval · Benchmark-oriented evaluation workflow · `experiments/ds_1000.py`
- [Embedding analysis](https://github.com/ise-uiuc/magicoder/blob/main/experiments/data_embedding/instructor_embedding.py): similarity analysis · Similarity and document embedding experiments · `experiments/data_embedding/instructor_embedding.py`
- [Seed docs](https://github.com/ise-uiuc/magicoder/blob/main/experiments/collect_seed_documents.py): analysis script · Collects source documents for analysis and comparison · `experiments/collect_seed_documents.py`

### Demo

Interactive inference surface

- [Gradio demo](https://github.com/ise-uiuc/magicoder/blob/main/demo/magicoder_demo.py): inference ui · Interactive local generation interface for a trained checkpoint · `demo/magicoder_demo.py`

### Data & assets

Prompt text and repository materials

- [Prompt text](https://github.com/ise-uiuc/magicoder/blob/main/data/prompt.txt): asset · Repository prompt template text used by the pipeline · `data/prompt.txt`
- [README](https://github.com/ise-uiuc/magicoder/blob/main/README.md): documentation · Documents checkpoints, datasets, and workflow context · `README.md`

## Connections

- Prompt text → Prompt format: template source · Prompt text informs instruction formatting
- Prompt format → Data synth: constructs prompts · Instruction format is used during synthesis
- LLM wrapper → Data synth: generates samples · Wrapper is invoked by the orchestration layer
- Data synth → Clean data: raw data · Synthetic examples are cleaned after generation
- Clean data → Deduplication: cleaned data · Post-cleanup data is deduplicated
- Deduplication → Overlap search: check leakage · Near-duplicate filtered data is checked against benchmarks
- Benchmark refs → Overlap search: benchmark corpus · Reference benchmarks are loaded for overlap detection
- Decon utils → Overlap search: helpers · Utility functions support substring matching
- Overlap search → Preprocess: filtered data · Decontaminated examples move into preprocessing
- Preprocess → Train: train set · Prepared data is consumed by fine-tuning
- Train → Gradio demo: checkpoint · Trained model is served in the demo
- Train → DS-1000 eval: evaluate · Trained variants are evaluated on benchmarks
- Seed docs → Embedding analysis: seed corpus · Collected documents feed similarity analysis
- Embedding analysis → Text2code: analysis inputs · Embedding outputs support ablation studies
- Comment pairs → Train: alt supervision · Alternative training scripts compare supervision sources
- Lang ablation → Text2code: compare variants · Ablation scripts form a research workflow
- README → Gradio demo: usage notes · Documentation describes demo and checkpoints
- README → Train: workflow docs · Documentation describes training and outputs
