MojoLlama
Archived Mojo/MAX quantizer and serving research repository (read-only history)
Brought by drakestapleton
MojoLlama / .coding-memory
| 1 | # MojoLlama — Coding Memory |
| 2 | |
| 3 | ## Current State |
| 4 | - MAX 26.3 + Mojo 1.0.0b1 installed via `pip install modular` |
| 5 | - Mojo SIMD Q4_0 matmul kernel verified (kernels/q4_matmul.mojo, all tests pass) |
| 6 | - Mojo SIMD attention kernel written (kernels/attention.mojo) |
| 7 | - Mojo SIMD norms kernel written (kernels/norms.mojo) |
| 8 | - bridge.py loads GGUF weights and runs forward pass (Python numpy + C kernel, ~1.6 tok/s) |
| 9 | - llama.cpp server achieves 85 tok/s on this machine |
| 10 | - MAX pipeline runs at 14.8 tok/s (GGUF fixed via monkey-patch) |
| 11 | |
| 12 | ## Mojo 1.0.0b1 API Notes |
| 13 | - Heap: `alloc[Type](count)`, `ptr.free()`, `ptr.load(offset)`, `ptr.store(offset, value)` |
| 14 | - `pointer_to_int(ptr)` works |
| 15 | - `UnsafePointer(unsafe_from_address=Int)` NOT in compiled build |
| 16 | - Function params: `UnsafePointer[True, UInt8, _]` (mut, type, any-origin) |
| 17 | - Python interop: `from python import Python`, `Python.import_module("numpy")` |
| 18 | - `defer` keyword NOT available |
| 19 | - `fn` keyword deprecated, use `def` |
| 20 | - `alias` deprecated, use `comptime` |
| 21 | |
| 22 | ## Key Blockers |
| 23 | 1. No way to construct UnsafePointer from raw Int address in compiled Mojo 1.0.0b1 |
| 24 | 2. Python interop works but element-by-element Float32/PythonObject conversion is slow |
| 25 | 3. File-based IPC (read/write binary files) is the most reliable bridge method |
| 26 | |
| 27 | ## Integration Approaches Tested |
| 28 | A. Python interop from Mojo ✓ works but element-wise type conversion is verbose |
| 29 | B. @export shared library ✗ pointer types not passable |
| 30 | C. File-based binary IPC ✓ works, suitable for weight passthrough at load time |
| 31 | D. MAX pipeline ✓ works but 5.7x slower than llama.cpp on CPU |
| 32 | |
| 33 | ## What Needs Building |
| 34 | Complete the Mojo SIMD forward pass: |
| 35 | 1. Accept weight data from Python via file or stdin |
| 36 | 2. Run embed, layer loop (attention + FFN), output projection |
| 37 | 3. Return logits to Python |
| 38 | 4. Benchmark against existing C kernel (1.6 tok/s) and llama.cpp (85 tok/s) |