A straightforward method for training your LLM, from downloading data to generating text.
docs(diagrams): speculative decoding, BPE training and typed configs
FareedKhan-dev4ac8b20c1a33
diff --git a/docs/diagrams/23_speculative.png b/docs/diagrams/23_speculative.pngnew file mode 100644index 0000000..5962d01Binary files /dev/null and b/docs/diagrams/23_speculative.png differdiff --git a/docs/diagrams/24_bpe.png b/docs/diagrams/24_bpe.pngnew file mode 100644index 0000000..2193eecBinary files /dev/null and b/docs/diagrams/24_bpe.png differdiff --git a/docs/diagrams/25_typed_config.png b/docs/diagrams/25_typed_config.pngnew file mode 100644index 0000000..c1ddbddBinary files /dev/null and b/docs/diagrams/25_typed_config.png differdiff --git a/docs/diagrams/src/23_speculative.mmd b/docs/diagrams/src/23_speculative.mmdnew file mode 100644index 0000000..c631567--- /dev/null+++ b/docs/diagrams/src/23_speculative.mmd@@ -0,0 +1,16 @@+%%{init: {'look':'handDrawn','theme':'base','themeVariables':{'fontFamily':'Comic Sans MS, cursive'}}}%%+flowchart LR+ P([text so far]):::data --> D{{small draft model<br/>guesses k tokens, one by one}}:::model+ D --> T{{big target model<br/>scores all k in ONE pass}}:::model+ T --> CHK{keep guess i with<br/>probability min 1, p/q}:::rl+ CHK -->|kept| NEXT[check the next guess]:::proc+ NEXT --> CHK+ CHK -->|rejected| FIX[resample from max 0, p - q<br/>and stop]:::proc+ CHK -->|all k kept| BONUS[one bonus token<br/>from the target]:::proc+ FIX --> OUT([append and repeat]):::eval+ BONUS --> OUT+ classDef data fill:#d6ffd9,stroke:#27ae60,stroke-width:2px,color:#143d1a;+ classDef proc fill:#d6e8ff,stroke:#2c6fbb,stroke-width:2px,color:#0d2c52;+ classDef model fill:#ffe8a3,stroke:#d48806,stroke-width:2px,color:#5a3d00;+ classDef rl fill:#ffd9b3,stroke:#e67e22,stroke-width:2px,color:#6b3500;+ classDef eval fill:#e8d6ff,stroke:#8e44ad,stroke-width:2px,color:#3d1a5a;diff --git a/docs/diagrams/src/24_bpe.mmd b/docs/diagrams/src/24_bpe.mmdnew file mode 100644index 0000000..6a21b96--- /dev/null+++ b/docs/diagrams/src/24_bpe.mmd@@ -0,0 +1,15 @@+%%{init: {'look':'handDrawn','theme':'base','themeVariables':{'fontFamily':'Comic Sans MS, cursive'}}}%%+flowchart LR+ T([raw text]):::data --> S[regex split<br/>words, numbers, spaces]:::proc+ S --> B[(each chunk as UTF-8 bytes<br/>ids 0 to 255)]:::store+ B --> C[count every adjacent<br/>pair of ids]:::proc+ C --> M{{merge the most frequent pair<br/>into a new id}}:::model+ M -->|update only the chunks<br/>that had the pair| C+ M -->|after vocab_size - 256 merges| V[(merges list<br/>= the tokenizer)]:::ckpt+ V --> E([encode: replay merges in order<br/>decode: join the bytes]):::eval+ classDef data fill:#d6ffd9,stroke:#27ae60,stroke-width:2px,color:#143d1a;+ classDef proc fill:#d6e8ff,stroke:#2c6fbb,stroke-width:2px,color:#0d2c52;+ classDef store fill:#cdece8,stroke:#16a085,stroke-width:2px,color:#0a3d33;+ classDef model fill:#ffe8a3,stroke:#d48806,stroke-width:2px,color:#5a3d00;+ classDef ckpt fill:#eeeeee,stroke:#555,stroke-width:2px,color:#222;+ classDef eval fill:#e8d6ff,stroke:#8e44ad,stroke-width:2px,color:#3d1a5a;diff --git a/docs/diagrams/src/25_typed_config.mmd b/docs/diagrams/src/25_typed_config.mmdnew file mode 100644index 0000000..c031927--- /dev/null+++ b/docs/diagrams/src/25_typed_config.mmd@@ -0,0 +1,15 @@+%%{init: {'look':'handDrawn','theme':'base','themeVariables':{'fontFamily':'Comic Sans MS, cursive'}}}%%+flowchart LR+ J1[(configs/base.json)]:::store --> L{{typed loader<br/>config/loader.py}}:::model+ J2[(configs/dpo.json)]:::store --> L+ CLI([--beta 0.2]):::data --> L+ L -->|unknown key| E1[error + did you mean]:::loss+ L -->|wrong type or choice| E2[error naming the file]:::loss+ L -->|ok| DC[dataclass<br/>__post_init__ checks]:::proc+ DC -->|n_embed % n_head != 0| E3[error at startup]:::loss+ DC -->|ok| M{{model and trainer<br/>tensor shapes checked in tests}}:::model+ classDef data fill:#d6ffd9,stroke:#27ae60,stroke-width:2px,color:#143d1a;+ classDef proc fill:#d6e8ff,stroke:#2c6fbb,stroke-width:2px,color:#0d2c52;+ classDef store fill:#cdece8,stroke:#16a085,stroke-width:2px,color:#0a3d33;+ classDef model fill:#ffe8a3,stroke:#d48806,stroke-width:2px,color:#5a3d00;+ classDef loss fill:#ffd6d6,stroke:#c0392b,stroke-width:2px,color:#5c1212;