Hugging FaceLeandro von WerraTutorial
Training CodeParrot 🦜 from Scratch
Summary
Training code generation models from scratch requires careful data filtering, tokenization, and compute management. To build CodeParrot, a 1.5-billion-parameter Python generation model, engineers extracted 20 million Python files from BigQuery and cleaned the resulting 180 GB corpus down to 50 GB after discovering extreme duplication. A custom GPT-2 tokenizer was trained over streamed samples, and the GPT-2 large architecture was initialized with layer-scaled, full-precision attention mechanisms. The training pipeline leveraged Hugging Face Accelerate alongside gradient checkpointing and a streaming iterable dataset designed to yield fixed-length concatenated token sequences. CodeParrot was trained on roughly 25 to 30 billion tokens and evaluated on coding tasks using the pass@k metric.
Context
Building a dedicated Python code completion model required training a large model from scratch. Raw GitHub dumps contained extensive duplicates that severely degraded model performance, and handling tens of gigabytes of training data introduced storage and memory constraints during tokenization and training.
Approach / What changed
A 180 GB Python dataset was extracted from BigQuery and cleaned down to 50 GB using Codex heuristics and deduplication. A GPT-2 tokenizer was trained over streamed data, and a 1.5B parameter GPT-2 large architecture was configured with attention scaling and full-precision attention computation. Training was scaled using Hugging Face Accelerate, gradient checkpointing, and an iterable dataset that concatenated and chunked samples to fixed context lengths.
Takeaways
Severe duplication in the raw 180 GB dataset impacted model performance, with 0.1% of unique files representing 15% of all files and 10% making up 66%.
Deduplicating and applying Codex cleaning heuristics reduced the raw 20-million-file dataset from 180 GB down to 50 GB.
Training stability and memory efficiency were managed using layer-indexed attention scaling, full-precision attention computation, and gradient checkpointing.
Source and freshness
- Source
- huggingface.co
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.