drengskapur/midi-classical-music
Viewer β’ Updated β’ 4.8k β’ 10.6k β’ 19
A LLaMA-style Transformer model for symbolic music generation, trained on MIDI data.
drengskapur/midi-classical-music β 4,796 classical MIDI files (~50MB)# Install dependencies
pip install -r requirements.txt
# Train + Generate (default)
python3 -m src.s00_main train+generate
# Train only
python3 -m src.s00_main train --epochs 20 --batch-size 4
# Generate from checkpoint
python3 -m src.s00_main generate --temperature 0.85
music_gen_llm/
βββ src/
β βββ s00_main.py # Entry point β orchestrates pipeline
β βββ s01_config.py # All configuration dataclasses
β βββ s02_tokenizer.py # REMI MIDI tokenizer
β βββ s03_dataset.py # Data download + tokenization + DataLoader
β βββ s04_model.py # MusicTransformer (LLaMA-style)
β βββ s05_trainer.py # Training loop with AMP + checkpointing
β βββ s06_generator.py # Autoregressive generation with KV-cache
β βββ s07_utils.py # Logging, memory monitoring, seeding
βββ tests/
β βββ test_pipeline.py # 7 unit tests covering all components
βββ scripts/
β βββ download_data.sh # Dataset setup
β βββ train.sh # Training launcher
β βββ generate.sh # Generation launcher
βββ docs/
β βββ README.md # This file
β βββ HLD.md # High-Level Design
β βββ LLD.md # Low-Level Design
β βββ flow_diagram.drawio # Execution flow diagram
βββ data/ # Downloaded MIDI + tokenized cache
βββ checkpoints/ # Saved model weights
βββ output/ # Generated MIDI files
βββ requirements.txt
βββ Dockerfile
βββ .gitignore
s00_main.py β s01_config.py β s02_tokenizer.py β s03_dataset.py β s04_model.py β s05_trainer.py β s06_generator.py
β β β β β β β
Entry point Load configs Init tokenizer Download & tokenize Build model Train loop Generate MIDI
| Parameter | Value |
|---|---|
| Dim | 256 |
| Layers | 6 |
| Heads | 8 (Q) / 4 (KV) β GQA |
| Hidden (FFN) | 448 (SwiGLU) |
| Max Seq Len | 1024 |
| Vocab Size | 485 (REMI tokens) |
| Parameters | ~5M |
| Precision | BF16/FP16 (AMP) |