# MoE8 Full Fine-Tune Runtime MVP Report ## Outcome The expert-only int8 mixed checkpoint and inference path were built successfully, but the full fine-tune runtime cannot proceed with stock MLX quantized expert kernels because `mx.gather_qmm` has no gradient with respect to quantized weights. This stops the MVP before the 10K full-training pilot. The retained artifacts are still useful: they prove the expected weight-memory reduction and isolate the exact missing runtime primitive. ## Completed Gates - Gate 1, expert-only quantization: passed. - Output checkpoint: `runtime_moe8_artifacts/checkpoints/lfm25_experts_int8_mlx` - Size on disk: 9.0 GB - Converted modules: 66 expert `SwitchLinear` projections - Converted expert params: 7,751,073,792 - Gate 2, generation load/shape smoke: passed. - Report: `runtime_moe8_artifacts/reports/generation_smoke.json` - Quality note: the short generations were repetitive and weak, so the mixed checkpoint is loadable but not parity-accepted for real training yet. - 10K dataset artifact: created. - Train: 582 examples - Valid: 29 examples - Test: 26 examples - Streaming update primitive: passed. - One real checkpoint expert projection update changed 197,683 packed int8 codes with 0.323 GB peak memory. - One real SwitchGLU expert update changed gate/up/down codes with 0.654 GB peak memory. - A 20-step routed micro trainer updated selected experts only, changed 35,189,712 packed codes, and stayed below 0.686 GB peak in the isolated block probe. - Layerwise next-token-loss path: passed. - One 9,999-token batch updated one full MoE block plus router with peak memory 21.733 GB. - One 9,999-token batch updated all 22 MoE blocks plus routers with peak memory 34.484 GB. - The all-layer pilot reduced batch loss from 2.13539 to 2.13013 and saved `runtime_moe8_artifacts/checkpoints/lfm25_experts_int8_lm_pilot_10k`. - Resumable trainer smoke: passed. - `runtime_moe8/layerwise_lm_train.py` wrote progress JSONL and reloadable checkpoints. - 2-layer/2K smoke completed with peak memory 13.445 GB. - Grouped semi-full gradient trainer: passed. - `runtime_moe8/grouped_lm_train.py` trains multiple MoE layers in one joint gradient group. - `runtime_moe8/group_sweep.py` finds the largest group size under a memory target. - On a 9,999-token example, group-size sweep results were: - 1 layer/group: 34.484 GB, 213.0 s - 2 layers/group: 35.188 GB, 123.2 s - 4 layers/group: 39.091 GB, 73.6 s - 8 layers/group: 49.468 GB, 45.2 s - 11 layers/group: 59.955 GB, 37.1 s - Recommended 64 GB unified-memory baseline group size: 8. ## Blocked Gates Gate 3, direct quantized expert backward: blocked. Probe: ```text runtime_moe8/probes.py stock-quant-grad \ --model runtime_moe8_artifacts/checkpoints/lfm25_experts_int8_mlx ``` Result: ```text RuntimeError: [GatherQMM::vjp] no gradient wrt the quantized weights. ``` This is the key runtime blocker. The stock `QuantizedSwitchLinear` forward path uses `mx.gather_qmm`, which is inference-only for quantized weights in the required sense. Generation parity is also not yet accepted. The mixed checkpoint and the one-batch pilot checkpoint run without shape/routing errors, but short raw generations are repetitive. That needs either a better quantization recipe, calibration, or real training/eval before treating the checkpoint as useful. ## What Was Built - `runtime_moe8/quantize_experts.py` - Loads `LiquidAI/LFM2.5-8B-A1B-MLX-bf16`. - Quantizes only: - `feed_forward.switch_mlp.gate_proj` - `feed_forward.switch_mlp.up_proj` - `feed_forward.switch_mlp.down_proj` - Keeps router, conv, attention, embeddings, norms, and dense FFN in BF16. - Saves a loadable mixed MLX checkpoint. - `runtime_moe8/probes.py` - `generate-smoke`: validates mixed checkpoint inference. - `stock-quant-grad`: proves stock quantized expert weights are not trainable. - `ste-toy`: proves MLX custom VJP can return surrogate float gradients for int8 arrays on a toy op. - `memory-estimate`: records expected gradient pressure for full expert training. ## Memory Findings Stored weight target was achieved: - Experts int8: ~7.75 GB - Non-experts BF16: ~1.43 GB - Checkpoint on disk: 9.0 GB Training remains the hard part: - Naive STE expert gradients as FP32 would be ~31.0 GB. - BF16 expert gradients would be ~15.5 GB. - A custom int8/sign/blockwise optimizer gradient path would need custom kernels or layerwise update logic to avoid full dense gradient materialization. ## Required Next Runtime Primitive The new layerwise primitive avoids the stock `gather_qmm` VJP and is now connected to true next-token loss. It is a coordinate-descent style trainer: each MoE layer is temporarily dequantized, updated against LM loss, and requantized before moving to the next layer. To improve it further, the runtime needs one of: 1. A custom differentiable gathered quantized MoE matmul: - forward equivalent to `gather_qmm` - VJP returns compressed/blockwise updates for int8 expert codes and scales - avoids materializing full BF16 expert weights or FP32 expert gradients 2. A layerwise/manual expert update loop: - recompute one MoE projection/layer at a time - accumulate compressed code/scale updates immediately - never retain all expert gradients globally - already connected to next-token loss in `layerwise_lm_pilot.py` and `layerwise_lm_train.py` 3. A CUDA/torchao-style FP8/MXFP8 training runtime on another machine. The Mac-local MLX route is now mechanically viable through option 2. It is not a mathematically identical full simultaneous gradient update, but it does directly change expert weights through true LM-loss layerwise updates while keeping experts stored as int8. The preferred current trainer is grouped block-coordinate training with group size 8 for 10K examples on this 64 GB Mac. This is the best measured balance between gradient coordination and memory headroom. ## Status MVP is no longer blocked at full language-model loss integration. The remaining risks are quality, runtime, and stability over many steps. Do not run a full epoch unattended until the repetitive-generation issue is understood and a short validation loop is added.