Views
No views yet
| Metric | Value |
|---|---|
| Decode speed | 77.9 tok/s peak (77.6 avg) on M5 Max 128GB |
| Quality | 0.9555 Pearson logit correlation vs BF16 reference (≥0.95 gate) |
| Baseline | 65.2 tok/s stock mlx-lm, → +19% with our optimizations |
| Custom baseline | 7.5 tok/s (naive Python MoE loop) → +937% |
bench_speed.py — the optimized decode benchmark (one-big-function @mx.compile + zmlx sigmoid gating fix)test_quality.py — quality verification (Pearson logit correlation vs BF16 reference)test_generation.py — end-to-end generation smoke testkernels/fused_sdpa_decode.py — custom Metal SDPA kernel (correctness-verified, see kernels/test_fused_sdpa.py)laguna_pipenetwork.py — model registration script (copies laguna.py into mlx-lm's models directory)serve.py — OpenAI-compatible API serverEXHAUSTION.md — full documentation of every optimization lever tried and why the remaining ones can't helpprobes/ — scratch/profiling scripts from the optimization process1git clone https://github.com/jacklarmer/laguna-apple.git
2cd laguna-apple
3python -m venv .venv
4source .venv/bin/activate
5pip install -r requirements.txtpython laguna_pipenetwork.pypython bench_speed.pyFused SDPA kernel verified on decode path (kernels/test_fused_sdpa.py: 4/4 PASS)
Decode: 77.6 tok/s for 20 tokens1# First time: generate the BF16 reference (needs poolside/Laguna-S-2.1-NVFP4-mlx)
2python make_reference.py
3
4# Then: run quality test (threshold 0.95)
5LAGUNA_QUALITY_THRESHOLD=0.95 python test_quality.pypython run.py1python serve.py
2# POST to http://127.0.0.1:8090/v1/chat/completions@mx.compile — all 48 layers compiled into a single MLX
function. Model parameters are closure constants; KV cache arrays are explicit
arguments. This eliminates ~96 Python→Metal boundary crossings per decode step.moe_mlp patch — applies optimized MoE combine logic from
ZMLX. Gives ~3% speed on the 47 MoE layers.e_score_correction_bias.
We monkey-patch ZMLX's _gating function to use mx.sigmoid() instead of
softmax. Without this fix, zmlx drops quality from 0.955 to 0.810.logaddexp(g_proj(x), 0))
is computed in bfloat16 instead of upcasting to float32, saving 2 dispatches
per layer.kernels/fused_sdpa_decode.py) was also written and
correctness-verified (4/4 layer types pass), but stock MLX's scaled_dot_product_attention
is faster because it uses optimized matrix-multiply units. The custom kernel uses
scalar float loops and can't compete. See EXHAUSTION.md for the full analysis.trust_remote_code — they only load model architectures already
built into their bundled mlx-lm/llama.cpp. Laguna is a custom
architecture — the laguna.py model file is not in upstream mlx-lm
(we install it manually via laguna_pipenetwork.py). LM Studio's mlx-engine
does not execute custom repo code,
so it cannot load Laguna.run.py / mlx-lm path in this repo (3-command setup, see Quick Start above)serve.py for an OpenAI-compatible API server on localhost:8090
(any client that speaks OpenAI API can connect to it)mlx-lm main merging the Laguna architecture codemlx-lm release that includes itmlx-lmmlx-lm maintainers
accepting the PR. We can't control that timeline.EXHAUSTION.md for the full bottleneck analysis and why ~78 tok/s is the
ceiling on this hardware holding the 0.95 quality gate.laguna.py registered via laguna_pipenetwork.py) is Copyright PipeNetwork,
Apache 2.0.