Negative result: dual-ANE shared-expert offload for DeepSeek V4 misses correctness and whole-prefill gates #2807
DiscoStew6082
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I tested a dual-ANE fused shared-expert path for
deepseek-ai/DeepSeek-V4-Flash-0731on a Mac Studio M3 Ultra. I am sharing the negative result because the design looked promising on paper, but a gated one-layer prototype showed that it was not worth compiling and integrating across all 43 layers.This is not a claim that ANE acceleration cannot help DeepSeek V4. It is a scoped result for this checkpoint, this shared-expert seam, this INT8 ANE conversion path, and a fixed 2,048-token prefill shape.
Short version
6.60 msversus39.36 msmean.0.999119and relative L2 error4.091%.38.41 msto34.98 ms, an8.9%MoE improvement, but missed my predeclared10%gate.4.11%.6.46%, leaving too little margin for a repeatable gain above5%after integration overhead.Environment
0.6.1, source commit6307e396acfdfff7b75d3ceb9b4756272fb03b6b0.32.00.31.30.6.3deepseek-ai/DeepSeek-V4-Flash-07311 x 2048 x 4096, BF16The installed checkpoint is mixed quantization: the always-on shared experts use MXFP8, while the routed experts use packed MXFP4 and select six of 256 experts per token. This made it possible to test the real shared-expert weights without constructing an all-MXFP8 checkpoint.
Why this seam looked promising
The routed and shared branches are independent after receiving the normalized MoE input:
The fused graph used DeepSeek's exact limited SwiGLU:
The Python/reference shard algebra, clamp behavior beyond both limits, output shape/dtype, unsupported-shape fallback, repeated use, procedure selection, and finite-output checks all passed. The native extension rebuilt successfully, and 220 relevant tests passed.
Predeclared one-layer gates
I set the continuation gates before compiling the full bank:
>= 0.9999<= 1%<= 1.05<= 0.90>= 7%< about 2.5 GBThe 7% projection gate was intended to leave enough margin to retain a repeatable improvement above 5% after integration overhead.
Correctness result
0.999118984.091%0.999752101.972%The ANE constants were produced by dequantizing the checkpoint's MXFP8 weights and converting them to per-row INT8. The exact source of the remaining error could be in that conversion or the compiled execution path; I did not continue isolating it after the independent projected-value gate also failed. FP16 constants might improve fidelity, but they would increase the 43-layer memory cost and cannot improve the perfect-hide upper bound.
Timing result
Complete wall time over six warmed alternating repetitions:
5.395 ms5.545 ms4.948-5.680 ms6.599 ms6.588 ms5.716-7.120 ms39.362 ms33.737 ms33.077-53.766 ms38.411 ms38.424 ms38.301-38.485 ms34.980 ms34.990 ms34.479-35.566 msThe host intervals placed the ANE call inside the routed GPU interval on every repetition. That establishes concurrent host-side work, but it does not prove physical GPU/ANE execution overlap. I did not find a supported device-level timeline source that could provide independent GPU and ANE start/end timestamps.
The full warmed 2,048-token model forward averaged
3,593.38 ms.Measured projection:
Generous perfect-hide upper bound:
Because stream or event tuning cannot exceed the perfect-hide bound, I treated this as a decisive no-go for full integration.
Memory result
I changed the ANE procedure-bank design to use one reusable input/output workspace per ANE bank under a strict one-in-flight invariant, instead of allocating mutable IOSurfaces per procedure.
0.168 s49,152 B0.463 s48,644,168 B0.845 s80,035,936 BThese measurements deliberately reused the same layer-21 weights. The private compiler may deduplicate identical constants, so this is only a lower bound and not a defensible projection for 43 unique layers. The 43 shared experts contain about
1.08 GBof INT8 weight data before compiler expansion. I did not compile unique 43-layer banks merely to refine a memory estimate after the correctness and value gates had already failed.Related attention-projection result
This shared-expert experiment followed a reconstructed DeepSeek attention-projection ANE path. That path produced repeatable long-context prompt-throughput gains of
1.57%at 4K,3.50%at 16K, and3.06%at 32K, while adding about 8 GB of physical footprint. Its isolated hybrid projection was slower than GPU-only at every tested split. That result is why I moved the seam to the whole MoE shared branch rather than continuing to tune attention fractions.What I think this establishes
It does not establish that every DeepSeek V4 ANE strategy is unhelpful, nor that a different ANE format or a larger primitive could not work.
Questions for maintainers and other experimenters
6.46%perfect-hide bound match how you would evaluate this seam, or is there an important whole-model scheduling effect that this one-layer projection misses?I am mainly posting this so others considering the same seemingly straightforward shared-expert offload can start from measured constraints rather than rebuilding the entire 43-layer bank first.
All reactions