How ise-uiuc/magicoder works
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: train.py Train · find_substrings.py Overlap search · generate_data.py Data synth · README.md README
Components 19
Library
Reusable Magicoder pipeline code under src/magicoder
- Prompt format · Builds OSS-Instruct-style instructions from code references
src/magicoder/prompt_template.py - LLM wrapper · Abstracts calls to the synthesis model
src/magicoder/llm_wrapper.py - Data synth · Coordinates prompt creation and synthetic example generation
src/magicoder/generate_data.py - Clean data · Cleans and normalizes raw generated examples
src/magicoder/clean_data.py - Deduplication · Removes similar or repeated samples with MinHash
src/magicoder/minhash_deduplication.py - Preprocess · Converts cleaned data into training-ready format
src/magicoder/preprocess_data.py - Train · Fine-tunes pretrained code LLM checkpoints on prepared data
src/magicoder/train.py - Benchmark refs · Loads benchmark examples for leakage checks
src/magicoder/decontamination/benchmark_data.py - Overlap search · Finds substring matches and benchmark overlap
src/magicoder/decontamination/find_substrings.py - Decon utils · Helpers for the decontamination workflow
src/magicoder/decontamination/utils.py
Experiments
Research scripts for ablations and analysis
- Text2code · Runs model and data ablations for code generation
experiments/text2code.py - Lang ablation · Compares language or data variants
experiments/lang_ablation.py - Comment pairs · Extracts and trains on function-comment pairs
experiments/extract_function_comment_pairs.py - DS-1000 eval · Benchmark-oriented evaluation workflow
experiments/ds_1000.py - Embedding analysis · Similarity and document embedding experiments
experiments/data_embedding/instructor_embedding.py - Seed docs · Collects source documents for analysis and comparison
experiments/collect_seed_documents.py
Demo
Interactive inference surface
- Gradio demo · Interactive local generation interface for a trained checkpoint
demo/magicoder_demo.py
Data & assets
Prompt text and repository materials
- Prompt text · Repository prompt template text used by the pipeline
data/prompt.txt - README · Documents checkpoints, datasets, and workflow context
README.md
Connections 18
- 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