You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LoRA adapters turn off fused decode paths on DeepSeek V4.1 and GLM-5.3-Flash: an opt-in merge, or a fused-path fix?
#5704
Setup: oMLX 0.8.3 on a Mac Studio (M5 Ultra, 512 GB), MTP on, adapters set in Model Settings or a profile. The checks quoted below are unchanged on current main.
What I measured: decode speed with each adapter applied the way oMLX does today (wrapped) and folded into the weights at load (merged, described below). "ms/cycle" is the main model's time per MTP cycle, from oMLX's MTP[...] timing[backbone=...] log lines.
For merged DeepSeek, tok/s moved with how well MTP predicted each essay, so ms/cycle is the like-for-like number there. Both DeepSeek adapter runs had the output_dims fix from #5703; without it, oMLX refuses this adapter.
Why, from the code:
DeepSeek V4.1: decode_fused._fused_projection() requires a QuantizedProjection, and the MTP verify step runs through the fused kernels only when all(decode_fused.supported(layer, c) ...) holds (patches/deepseek_v41/language.py). A LoRALinear on wo_b in 38 layers sends all 40 layers to the unfused path. The adapter's own matmuls account for about 0.28 ms of the 13.4 ms per cycle (timed with its shapes in a dependent chain).
GLM-5.3-Flash: in the 34 KDA layers, _fused_in_proj() fuses q|k|v|f_a|g_a|b only when all six have scales, and _build_decode_groups() requires nn.QuantizedLinear. With q/k/v wrapped, _decode_step() returns None and those layers run the reference body. I haven't measured how the 4.0 ms splits between this and the adapter's own matmuls.
What I tried: a per-model setting lora_merge (off by default, kept in profiles, with a switch under the LoRA picker) that adds B·A to each target's own weights at load, re-encoded on the module's existing scales and biases (affine 2/4/8-bit, MXFP8, float). The module keeps its type, so every fused path stays on. Formats without an encoder (oQh, MXFP4 and others) stay wrapped, and the log says why.
DeepSeek: 8,433 values clipped. Mean KL to the heretic model (pqhaz's 38 changed wo_b weights put into the same oQ4e model): 0.0101 merged, 0.0102 wrapped.
GLM: 23,977,410 values (about 0.4% of the adapted weights) clipped at group edges. Top-1 agreement with the base model over 249 positions: 87.1% merged, 88.0% wrapped; mean KL 0.111 merged, 0.119 wrapped.
The rounding concern in lora_adapters.py is real for small updates. For a rank-32 fine-tune LoRA on Qwen3.8-Flash-Next-oQ8e-mtp (300 projections), merging would change only 5.6% of the stored codes, so most of that update would be lost. That is why it is off by default, and the switch's hint says so.
Open point: a merged DeepSeek takes about 1 GB more after loading (289.1–289.4 GB vs 288.1–288.4 GB). I haven't found why.
Question: would you take this opt-in merge setting as a PR (about 330 changed lines with tests; web UI so far, not the macOS app)? Or would you rather have the fused paths accept a wrapped projection, which keeps the result exact but still runs the adapter's own matmuls? Or neither? #5490 takes the second route for Qwen4 attention: the grouped projection launch runs on the base layers and then adds each adapter's own update. It also asks whether other fast paths that check a layer's type should get the same treatment; DeepSeek V4.1's fused decode and GLM-5.3's KDA input projection are two more.
Separately: on stock oMLX, a LoRA on DeepSeek V4.1's quantized dense projections does not load at all ("layers.8.attn.wo_b is 8192 -> 2048; the adapter expects 8192 -> 5120"), because QuantizedProjection reports the packed input width as output_dims. #5703 fixes that.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Setup: oMLX 0.8.3 on a Mac Studio (M5 Ultra, 512 GB), MTP on, adapters set in Model Settings or a profile. The checks quoted below are unchanged on current main.
Adapters: both remove refusals.
attn.wo_bin 38 layers. Its Hub entry names pqhaz/DeepSeek-V4.1-Flash-1017-heretic, a full checkpoint with those 38 weights changed, as its base model.What I measured: decode speed with each adapter applied the way oMLX does today (wrapped) and folded into the weights at load (merged, described below). "ms/cycle" is the main model's time per MTP cycle, from oMLX's
MTP[...] timing[backbone=...]log lines.For merged DeepSeek, tok/s moved with how well MTP predicted each essay, so ms/cycle is the like-for-like number there. Both DeepSeek adapter runs had the
output_dimsfix from #5703; without it, oMLX refuses this adapter.Why, from the code:
decode_fused._fused_projection()requires aQuantizedProjection, and the MTP verify step runs through the fused kernels only whenall(decode_fused.supported(layer, c) ...)holds (patches/deepseek_v41/language.py). ALoRALinearonwo_bin 38 layers sends all 40 layers to the unfused path. The adapter's own matmuls account for about 0.28 ms of the 13.4 ms per cycle (timed with its shapes in a dependent chain)._fused_in_proj()fuses q|k|v|f_a|g_a|b only when all six havescales, and_build_decode_groups()requiresnn.QuantizedLinear. With q/k/v wrapped,_decode_step()returns None and those layers run the reference body. I haven't measured how the 4.0 ms splits between this and the adapter's own matmuls.What I tried: a per-model setting
lora_merge(off by default, kept in profiles, with a switch under the LoRA picker) that adds B·A to each target's own weights at load, re-encoded on the module's existing scales and biases (affine 2/4/8-bit, MXFP8, float). The module keeps its type, so every fused path stays on. Formats without an encoder (oQh, MXFP4 and others) stay wrapped, and the log says why.wo_bweights put into the same oQ4e model): 0.0101 merged, 0.0102 wrapped.lora_adapters.pyis real for small updates. For a rank-32 fine-tune LoRA on Qwen3.8-Flash-Next-oQ8e-mtp (300 projections), merging would change only 5.6% of the stored codes, so most of that update would be lost. That is why it is off by default, and the switch's hint says so.Question: would you take this opt-in merge setting as a PR (about 330 changed lines with tests; web UI so far, not the macOS app)? Or would you rather have the fused paths accept a wrapped projection, which keeps the result exact but still runs the adapter's own matmuls? Or neither? #5490 takes the second route for Qwen4 attention: the grouped projection launch runs on the base layers and then adds each adapter's own update. It also asks whether other fast paths that check a layer's type should get the same treatment; DeepSeek V4.1's fused decode and GLM-5.3's KDA input projection are two more.
Separately: on stock oMLX, a LoRA on DeepSeek V4.1's quantized dense projections does not load at all ("layers.8.attn.wo_b is 8192 -> 2048; the adapter expects 8192 -> 5120"), because
QuantizedProjectionreports the packed input width asoutput_dims. #5703 fixes that.All reactions