Commit eca0265
feat(inf-002): Transformer Forward Pass — native LLM inference, 18 tests
transformer_forward.zig (977 lines):
- LLaMA-style transformer: RMSNorm, RoPE, GQA attention, SwiGLU FFN
- SIMD-friendly matVec with 8-wide unrolling and scalar tail
- KV cache with per-layer/position/kv-head storage
- RoPE with precomputed cos/sin cache, correct rotation formula
- Numerically stable softmax (subtract max before exp)
- Full generation loop: forward -> sample -> next token
- Top-p nucleus sampling + greedy argmax
- InferenceStats with FLOP counting and memory estimation
- LCG PRNG with Xavier-like weight init for deterministic tests
- 18 tests: norms, matmul, activations, attention, forward, generation
- build.zig wired: test-transformer-forward step
- Tech tree 49/56 (88%)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent cc8c92f commit eca0265
3 files changed
Lines changed: 994 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1882 | 1882 | | |
1883 | 1883 | | |
1884 | 1884 | | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
1885 | 1898 | | |
0 commit comments