| <mxfile host="65bd71144e"> |
| <diagram name="Execution Flow" id="exec-flow"> |
| <mxGraphModel dx="1363" dy="1186" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="900" math="0" shadow="0"> |
| <root> |
| <mxCell id="0"/> |
| <mxCell id="1" parent="0"/> |
| <mxCell id="title" value="Music Generation LLM β Execution Flow" style="text;html=1;align=center;verticalAlign=middle;fontSize=18;fontStyle=1;" parent="1" vertex="1"> |
| <mxGeometry x="400" y="20" width="400" height="40" as="geometry"/> |
| </mxCell> |
| <mxCell id="s00" value="s00_main.py Entry Point CLI Args Parser" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="520" y="80" width="160" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s01" value="s01_config.py ModelConfig, TrainConfig DataConfig, GenConfig" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="520" y="180" width="160" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s02" value="s02_tokenizer.py REMI Tokenizer 485 token vocab" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="520" y="280" width="160" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s03" value="s03_dataset.py HF Download β Parse β Tokenize β DataLoader" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="520" y="380" width="160" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s04" value="s04_model.py MusicTransformer RoPE+GQA+SwiGLU+RMSNorm" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="300" y="480" width="180" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s05" value="s05_trainer.py AMP + Grad Ckpt AdamW + Cosine LR" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="300" y="580" width="180" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s06" value="s06_generator.py KV-Cache Decoding Top-p/k + RepPenalty" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;" parent="1" vertex="1"> |
| <mxGeometry x="720" y="580" width="180" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="out_ckpt" value="checkpoints/ best.pt" style="shape=cylinder3;whiteSpace=wrap;html=1;size=8;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;" parent="1" vertex="1"> |
| <mxGeometry x="340" y="680" width="100" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="out_midi" value="output/ generated_*.mid" style="shape=cylinder3;whiteSpace=wrap;html=1;size=8;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;" parent="1" vertex="1"> |
| <mxGeometry x="760" y="680" width="100" height="60" as="geometry"/> |
| </mxCell> |
| <mxCell id="s07" value="s07_utils.py β’ Logging β’ Memory Monitor β’ Seeding" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;" parent="1" vertex="1"> |
| <mxGeometry x="80" y="380" width="140" height="80" as="geometry"/> |
| </mxCell> |
| <mxCell id="e1" parent="1" source="s00" target="s01" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e2" parent="1" source="s01" target="s02" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e3" parent="1" source="s02" target="s03" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e4" parent="1" source="s03" target="s04" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e5" value="train" style="edgeStyle=orthogonalEdgeStyle;" parent="1" source="s04" target="s05" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e6" value="generate" style="edgeStyle=orthogonalEdgeStyle;" parent="1" source="s04" target="s06" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e7" parent="1" source="s05" target="out_ckpt" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e8" parent="1" source="s06" target="out_midi" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e9" style="dashed=1;" parent="1" source="s07" target="s03" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="e10" value="loads best.pt" style="dashed=1;" parent="1" source="out_ckpt" target="s06" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| </root> |
| </mxGraphModel> |
| </diagram> |
| <diagram name="Model Architecture" id="model-arch"> |
| <mxGraphModel dx="477" dy="415" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1200" pageHeight="800" math="0" shadow="0"> |
| <root> |
| <mxCell id="0"/> |
| <mxCell id="1" parent="0"/> |
| <mxCell id="t2" value="MusicTransformer Architecture" style="text;html=1;align=center;fontSize=16;fontStyle=1;" parent="1" vertex="1"> |
| <mxGeometry x="350" y="20" width="300" height="30" as="geometry"/> |
| </mxCell> |
| <mxCell id="inp" value="Token IDs [batch, seq_len]" style="shape=parallelogram;whiteSpace=wrap;html=1;fillColor=#d5e8d4;" parent="1" vertex="1"> |
| <mxGeometry x="420" y="70" width="160" height="40" as="geometry"/> |
| </mxCell> |
| <mxCell id="emb" value="Token Embedding (weight-tied with output)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;" parent="1" vertex="1"> |
| <mxGeometry x="400" y="140" width="200" height="40" as="geometry"/> |
| </mxCell> |
| <mxCell id="block" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666;dashed=1;" parent="1" vertex="1"> |
| <mxGeometry x="300" y="210" width="400" height="300" as="geometry"/> |
| </mxCell> |
| <mxCell id="blabel" value="TransformerBlock Γ 6" style="text;html=1;align=center;fontSize=13;fontStyle=1;" parent="1" vertex="1"> |
| <mxGeometry x="400" y="215" width="200" height="25" as="geometry"/> |
| </mxCell> |
| <mxCell id="rms1" value="RMSNorm" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;" parent="1" vertex="1"> |
| <mxGeometry x="430" y="250" width="140" height="30" as="geometry"/> |
| </mxCell> |
| <mxCell id="gqa" value="Grouped Query Attention 8Q / 4KV heads + RoPE Flash Attention / SDPA" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;" parent="1" vertex="1"> |
| <mxGeometry x="390" y="295" width="220" height="50" as="geometry"/> |
| </mxCell> |
| <mxCell id="res1" value="+ Residual" style="ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;" parent="1" vertex="1"> |
| <mxGeometry x="450" y="355" width="100" height="30" as="geometry"/> |
| </mxCell> |
| <mxCell id="rms2" value="RMSNorm" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;" parent="1" vertex="1"> |
| <mxGeometry x="430" y="395" width="140" height="30" as="geometry"/> |
| </mxCell> |
| <mxCell id="ffn" value="SwiGLU FFN SiLU(W1Β·x) β W3Β·x β W2" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;" parent="1" vertex="1"> |
| <mxGeometry x="400" y="435" width="200" height="40" as="geometry"/> |
| </mxCell> |
| <mxCell id="res2" value="+ Residual" style="ellipse;whiteSpace=wrap;html=1;fillColor=#d5e8d4;" parent="1" vertex="1"> |
| <mxGeometry x="450" y="485" width="100" height="25" as="geometry"/> |
| </mxCell> |
| <mxCell id="fnorm" value="RMSNorm (final)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;" parent="1" vertex="1"> |
| <mxGeometry x="430" y="540" width="140" height="30" as="geometry"/> |
| </mxCell> |
| <mxCell id="proj" value="Linear Projection β Vocab" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;" parent="1" vertex="1"> |
| <mxGeometry x="400" y="590" width="200" height="35" as="geometry"/> |
| </mxCell> |
| <mxCell id="out" value="Logits [batch, seq, 485]" style="shape=parallelogram;whiteSpace=wrap;html=1;fillColor=#d5e8d4;" parent="1" vertex="1"> |
| <mxGeometry x="420" y="650" width="160" height="40" as="geometry"/> |
| </mxCell> |
| <mxCell id="a1" parent="1" source="inp" target="emb" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a2" parent="1" source="emb" target="rms1" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a3" parent="1" source="rms1" target="gqa" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a4" parent="1" source="gqa" target="res1" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a5" parent="1" source="res1" target="rms2" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a6" parent="1" source="rms2" target="ffn" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a7" parent="1" source="ffn" target="res2" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a8" parent="1" source="res2" target="fnorm" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a9" parent="1" source="fnorm" target="proj" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="a10" parent="1" source="proj" target="out" edge="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| </root> |
| </mxGraphModel> |
| </diagram> |
| <diagram name="UML Class Diagram" id="uml-class"> |
| <mxGraphModel dx="1400" dy="900" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1400" pageHeight="900" math="0" shadow="0"> |
| <root> |
| <mxCell id="0"/> |
| <mxCell id="1" parent="0"/> |
| <!-- MusicTokenizer --> |
| <mxCell id="tok" value="MusicTokenizer βββββββββββββ - vocab_size: int - pad_id: int - bos_id: int - eos_id: int βββββββββββββ + midi_to_tokens(midi, max_len) + tokens_to_midi(tokens) + decode_token(token_id) + save(path) / load(path)" style="shape=mxgraph.uml25.class;whiteSpace=wrap;html=1;align=left;spacingLeft=8;fontSize=11;fillColor=#dae8fc;" vertex="1" parent="1"> |
| <mxGeometry x="40" y="100" width="260" height="200" as="geometry"/> |
| </mxCell> |
| <!-- MusicTransformer --> |
| <mxCell id="model" value="MusicTransformer βββββββββββββ - config: ModelConfig - token_emb: Embedding - layers: ModuleList[TransformerBlock] - norm: RMSNorm - output: Linear - freqs: Tensor (RoPE) βββββββββββββ + forward(input_ids, targets, use_cache) + reset_caches() + count_parameters() + from_config(config)" style="shape=mxgraph.uml25.class;whiteSpace=wrap;html=1;align=left;spacingLeft=8;fontSize=11;fillColor=#e1d5e7;" vertex="1" parent="1"> |
| <mxGeometry x="540" y="60" width="300" height="240" as="geometry"/> |
| </mxCell> |
| <!-- TransformerBlock --> |
| <mxCell id="tblock" value="TransformerBlock βββββββββββββ - attention: GroupedQueryAttention - feed_forward: SwiGLU - norm1, norm2: RMSNorm βββββββββββββ + forward(x, freqs, mask, use_cache)" style="shape=mxgraph.uml25.class;whiteSpace=wrap;html=1;align=left;spacingLeft=8;fontSize=11;fillColor=#f5f5f5;" vertex="1" parent="1"> |
| <mxGeometry x="560" y="370" width="260" height="140" as="geometry"/> |
| </mxCell> |
| <!-- Trainer --> |
| <mxCell id="trainer" value="Trainer βββββββββββββ - model: MusicTransformer - optimizer: AdamW - scheduler: CosineWarmup - scaler: GradScaler βββββββββββββ + train() + _train_epoch(epoch) + _validate() + _save_checkpoint(name) + load_checkpoint(path)" style="shape=mxgraph.uml25.class;whiteSpace=wrap;html=1;align=left;spacingLeft=8;fontSize=11;fillColor=#f8cecc;" vertex="1" parent="1"> |
| <mxGeometry x="960" y="60" width="240" height="220" as="geometry"/> |
| </mxCell> |
| <!-- Generator functions --> |
| <mxCell id="gen" value="Generator (functions) βββββββββββββ + generate(model, tokenizer, config) + generate_midi_file(model, tok, config, path) + top_k_top_p_filter(logits, k, p) + apply_repetition_penalty(logits, past, pen)" style="shape=mxgraph.uml25.class;whiteSpace=wrap;html=1;align=left;spacingLeft=8;fontSize=11;fillColor=#f8cecc;" vertex="1" parent="1"> |
| <mxGeometry x="960" y="340" width="320" height="120" as="geometry"/> |
| </mxCell> |
| <!-- Relationships --> |
| <mxCell id="r1" value="uses" style="endArrow=open;dashed=1;" edge="1" source="trainer" target="model" parent="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="r2" value="contains Γ6" style="endArrow=diamond;endFill=1;" edge="1" source="tblock" target="model" parent="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="r3" value="uses" style="endArrow=open;dashed=1;" edge="1" source="gen" target="model" parent="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| <mxCell id="r4" value="uses" style="endArrow=open;dashed=1;" edge="1" source="gen" target="tok" parent="1"> |
| <mxGeometry relative="1" as="geometry"/> |
| </mxCell> |
| </root> |
| </mxGraphModel> |
| </diagram> |
| </mxfile> |