Repository navigation
Add DeepSeek-V4 (deepseek_v4) text model - #796
Augustas11 wants to merge 47 commits into
Conversation
|
Thanks @Augustas11, nice work, and the kernel is fine with me: it's JIT, it has a fallback, and the gain makes sense.
Could the 4.3 log-probability gap be HISA? Running both sides with Minor: the fallback P.S.: mlx-vlm's generator wires memory by default ( |
- index_block / index_keep default to 0: exact top-k over the visible pooled entries, as DeepSeek's reference. HISA stays an opt-in mlx-vlm approximation; its trailing partial block is documented. - The exact indexer path scores queries in tiles to bound the [B, H, L, P] scores; selections equal the untiled computation. - compress_ratios is required; a configuration without it fails to decode instead of falling back to a guessed layout. - The compressed pool grows in steps of 256 entries like KVCacheSimple and readers use its logical length. - RoPE frequency tables are built in init for the known head widths; the lock is gone.
Ratio-4 compressors pool each window together with the first half of the window before it (the reference's overlap_transform and its decode kv_state[:, :ratio]). The port gave the first window of every call no previous window, so chunked prefill and every decode-time ratio-4 entry lost the overlap. The pool cache now keeps the raw kv/gate rows of the last completed window and hands them to the next call; they are part of the cache state and its copies. Only the first window of the sequence has no previous window, so the pool no longer depends on how the tokens are split into calls. Also fix the window buffer for a multi-token call that completes no window while rows are already buffered: it now appends every row of the call instead of slicing from a negative start. The tiny fixture's mlx-vlm oracle has the old behaviour, so its teacher-forced and token-iterator parity tests now differ on cases with chunked prefill or decode-time ratio-4 entries.
The oracle now comes from DeepSeek's inference/model.py, imported unmodified on a float32 CPU shim of its kernel.py (activation quantization identity), instead of mlx-vlm. The generator takes --reference-dir, writes the weights with a NumPy MXFP4/MXFP8 quantizer that matches MLX bit for bit (check_mxfp.py), and gives every hash-routing row distinct experts. Seed 26 passes the margin rule; tolerance 9.5e-05.
Match where DeepSeek's reference model.py computes in float32 and where it stays in the activation dtype: - RMSNorm in float32 with a float32 weight, rounded once - compressor projections, buffered rows, softmax and pooling in float32, entries cast back before the norm - router matmul in float32 - expert SwiGLU in float32; routed and shared outputs summed in float32 - sparse pooled attention scores, softmax and sink in float32 - logits as a float32 projection - query head normalization and exact indexer scores in the activation dtype Float32 runs are unchanged. A bfloat16 test checks overlap pooling and router weights against the same computations done in float32.
The logits head, the compressor projections and the router weight are float32 parameters in the reference. sanitize now casts them to float32 when the checkpoint holds them dense (no scales), so the forward pass does not cast them each step. Quantized modules are left as they are and keep the cast at use, which is also the path if a caller later casts these weights to another dtype. A test loads the bfloat16 tiny checkpoint, checks which parameters are float32, and compares prefill and decode logits with the cast-at-use path exactly.
|
Thanks @aleroot. You are right on both points, and both came from the same mistake: I ported from mlx-vlm and tested against mlx-vlm, so its differences from DeepSeek's 1. Overlap compression. 2. HISA. Minor points. 3. Float32 placement, which you did not raise. Checking the port against This one costs speed and memory, see the table below. If you prefer the faster placement for some of these steps, tell me which and I will change them back. The fixture now comes from DeepSeek's code.
With deliberate errors put into the port, the tests fail: overlap carry reverted, one expert index changed, and the overlap gate dropped are each more than 10,000 times the tolerance; 19 Sinkhorn iterations instead of 20 is 3.8 times. I ran those four at 89b68d3, before the float32 commits. Full size (M3 Ultra, same setup as in the description, one run per cell; three runs on the same day):
Points 1 and 2 moved decode by -0.9%, +3.7% and -0.2% and added 9.7% to TTFT at 32K, most likely the exact top-k in prefill; I have not separated it from the overlap change. The float32 placement costs 6.0 to 6.8% of decode, 3.8% more TTFT at 32K and 5.7 GB of peak memory at 8K and 32K (2.2 GB at 1K). I have not measured which of its steps carries the cost. The 4.3 gap. I do not think it is HISA alone. As opened, the gap against mlx-vlm was 2.06 at 1K, 4.31 at 8K and 4.13 at 32K. At 1K the ratio-4 pool has 256 to 259 entries in the compared steps. That is below One more thing I have to correct. The full-size greedy tokens are still 256 of 256 equal to mlx-vlm after all of this, and equal to what the port produced as opened. So that comparison cannot see any of these changes: my prompt is a repeated block of text and the continuation is repetitive (51 distinct tokens in 256). It was a weak check and I should not have leaned on it. I have no full-size reference that follows DeepSeek's code: Wired memory. In my comparison I ran mlx-vlm without its wired limit: my oracle script (not in this PR; I can share it) calls Two things I found in
Full suite on the M5 at the new head: 995 XCTest run, 9 skipped, and the same failing tests as on main. I will rewrite the description to match, since its mlx-vlm comparison no longer describes what the code does. Augustas from Malibu |
|
@Augustas11 I see you have been doing nice work, however, I think there is still room for improvement and we should be careful not to trade correctness for performance before understanding where the actual cost comes from. On activation quantization, I would keep it for a follow-up, but it's worth investigating with real checkpoints(unfortunately I do not have a Mac Studio so I cannot really help you more). The Hadamard rotation and FP4 rounding should be considered together, since the rotation preserves dot products before quantization. I would also keep the current duplicate-expert accumulation rather than reproduce PyTorch's indexed update semantics. Performance-wise, I think the biggest opportunity is in the sparse attention and indexer paths. We are materializing fairly large intermediate tensors and promoting them to FP32. A fused Metal implementation could reduce memory traffic significantly while preserving FP32 accumulation where it matters. I would profile those paths before reverting any precision changes. Also, storing BF16 checkpoint weights as FP32 doesn't recover precision, so that's another area worth measuring. If this is going to speed up even further, you're making me tempted to buy a Mac Studio as well, because these are starting to look like interesting numbers... I just need to find the budget first! 😅 |
|
Another thing: this work would potentially pair with my #708, which keeps lookup tables on disk and reads only the rows a token uses. For V4-Flash that's only the 1 GB embedding, but it matters for V4.1-Flash, whose Engram n-gram tables are about 203 GB in Big-MoE's EXL3 conversion. The next step would be doing the same for experts. Of the 158 GB, routed experts are about 147 GB, and a token reads only about 3.45 GB of them (6 per layer). With an expert cache in memory and the rest read from SSD, as Big-MoE-Small-Box does, it could run on a 96–128 GB Mac Studio, at a speed that depends on how often experts are reused. Your 0.57 tok/s run without a wired limit shows that OS paging alone won't do it. @Augustas11 if you could log how often consecutive tokens reuse the same experts on your Mac Studio, that would tell us whether this is worth building. It would also tell me whether a Mac Studio Ultra with 96 GB would be enough, or whether I need more memory. Thank you. |
The reference's RMSNorm weights are float32. Like the head, compressor and router weights, they are now kept in float32 at load, so the norm's cast of its weight is a no-op on every call instead of one dispatch per norm. The norm still casts at use, so a weight set to another dtype works as before. bfloat16 to float32 is exact: the values are the same.
Same ops in the activation dtype as before, each rounded as when run one by one: on the GPU they run as one compiled graph, so the steps after the reduction fuse into one kernel. The mean is written as its sum times 1 / head_dim so the traced graph holds a constant. The CPU keeps the plain ops, since its compiled float32 kernel rounds differently.
The two compressors of a ratio-4 layer project the same float32 copy of the layer input instead of casting it twice. When a window completes, the pooled entries' round trip through the input dtype runs as one kernel and the norm takes the float32 result directly, through a norm entry point for float32 inputs. The values are the same as before.
MLX looks up a compiled graph by function id, input shapes and dtypes and the C++ default stream. Device.withDefaultDevice changes only the Swift task-local default, so a function traced under the CPU replays its CPU kernels when called under the GPU, and the other way round. Each compiled function is now built once per device type and picked by the current default device.
A norm weight set with update(parameters:) after a forward pass gives exactly the logits of a fresh model with that weight. float32 logits on each device are bit for bit the same whether or not the other device ran first. Each run starts on a new thread, whose MLX compile cache is empty, so the check does not depend on what ran earlier in the process. Skipped without a GPU.
|
@aleroot thanks, both comments were useful. I profiled before touching any precision, as you said, and logged the expert routing you asked for. Everything below is on the M3 Ultra (256 GB) with the MXFP4 conversion unless it says otherwise. 1. Where the cost of the float32-placement commit comes from One model load, greedy, 256 decode steps, two rounds per cell. Each row turns one step of that commit back to what it was before and leaves the rest as in the PR. For most rows that means the activation dtype instead of float32. For the query norm it means the fused
Three things I take from it:
2. What I changed, with no precision change Four commits, pushed now (53b39aa, fb74094, 7fda001, ca80ba9), with two tests in b11433c:
Checked on the M3 Ultra against logits captured there from the code before these commits, tiny model, bfloat16 and float32, in a process that runs the CPU cases and then the GPU cases, 30 iterations: the first three commits change no bit (360 of 360 comparisons). I have no GPU-only capture of the code before the commits, so in float32 the GPU side of that check is subject to what section 3 describes. At full size, same window, same method as the table:
Greedy tokens are equal in both, with the caveat from my last comment that this prompt is a weak check. The four commits recover about half of the float32-placement commit's cost at 1K and less than a third at 8K. Peak at 1K went from 159.96 to 160.14 GB, which I have not explained. These full-size numbers and the bit checks were run on my local profiling branch, which carries the same four commits plus profiling switches that are off by default; the commits as pushed have so far only run the tiny tests on the M5 (20 tests, 1 skipped, 0 failures). What is left in the norms is the cast of the input and output around 3. A device-order problem I found on the way The PR's compiled functions (hyper-connection expand and Sinkhorn, the expert SwiGLU, the two compressor functions) are traced once and replayed. MLX looks a compiled function up by the C++ default stream, and Swift's Two things from my base M5, neither caused by the device-order problem:
4. Expert reuse I recorded the selected experts for every layer and token on five workloads (an English explanation, a second unrelated turn in the same chat, a coding task, a Chinese question, and a question after about 8K tokens of mixed documents), greedy, 512 decode tokens each. Limits first: the conversion has no chat template, so the prompts use a hand-written DeepSeek V3 style non-thinking format (the outputs read as normal answers); 512 tokens is short; and the cache numbers are a simulation, I did not build anything. Sizes, from the loaded arrays: 157.9 GB total, 147.2 GB routed experts, 10.8 GB shared. One expert is 12.75 MiB, and a token selects 258 of the 11,008 (6 in each of 43 layers), 3.45 GB. Your figures were right.
LRU over single experts, decode only, with the shared weights resident and 8 GiB left free (budgets read as GiB):
How I read it for your question. The reuse between neighbouring tokens is real but partial, and the set of experts in use keeps growing: after 512 tokens it is already larger than a 96 GB machine's cache, and it was still growing when the runs stopped, so the 96 GB misses do not die out: in the last quarter of each run a 96 GB cache still reads 5 to 11 experts per token (63 to 148 MB), and that rate had stopped falling between the third and the last quarter in four of the five runs, while at 128 it was still falling. At 128 the cache is larger than what any of these 512-token generations touched, so most of its misses are first touches, except after the 8K prompt, where they are re-reads of experts the prefill pushed out. On whether 96 GB is enough: over 512 tokens 96 and 128 differ little (95-97% against 97-98% warm), and at 96 each token waits for roughly 60 to 150 MB of expert reads once the cache has filled, more at the start. Whether that is fast enough depends on the read speed, which I did not measure, so I will not turn it into tok/s. Two cautions. Long prompts are the harder case: an 8K prefill touches nearly every expert, so prefill would read almost the whole 147 GB at least once whatever the cache size. And the 8 GiB I left free is tight at long context: at 8K the measured peak is 8.1 GB above the weights. The three hash-routed layers have no locality between neighbouring tokens (their experts follow the token id); they are 9.6 GiB together. I can run longer generations, or other prompts if you have a set you care about, and I can share the per-token traces (a few MB) and the script that produced these tables. On your other two points: agreed on both. Activation quantization stays out of this PR as a follow-up, with the Hadamard rotation and the FP4 rounding taken together, and the duplicate-expert accumulation stays as it is. Next from my side, if you agree: a fused kernel for the norms (decode) and for the sparse-attention path (TTFT and memory at long context) as separate steps, each compared against the current float32 results with the differences reported. Augustas from Malibu |
MLX's sorted gathered quantized matmul reads past the last weight column on some GPUs when the reduction width is not a multiple of 64. The fixture's expert down projection has width 32, so a GPU forward over 16 or more tokens can turn the last output column NaN, depending on the memory after the weights. Feeding the 300-token prompt in chunks of 7 keeps every expert call at 14 routes, below the 16 at which SwitchGLU sorts them; the ratio-4 and ratio-128 windows still complete.
|
A correction to my last comment, on the NaN from the M5. I have the cause now, and part of what I wrote does not hold. What does not hold. I reported the NaN in 3 of 16 GPU iterations when the fused hyper-connection kernel was replaced by the plain-op path, and in 0 of 26 on the default path. That split did not hold up. In longer GPU loops of the same tiny-model check (TF32 off, so only the bfloat16 cases take the kernel described below), the default path gave NaN in 25 of 150 iterations and the plain-op path (three variants of it) in 18 of 120. The hyper-connection code has nothing to do with it. The cause is in MLX. On an M5-class GPU the sorted gathered quantized matmul (what a quantized Evidence:
It is in the same K tail as ml-explore/mlx#3887; the fix for that (ml-explore/mlx#4009) bounded the activation tile by the K remainder, and the weight tile still is not. I have not run mlx main; the two kernel bodies and their loaders are the same there as at 36969c0. I found no existing report of it, so I will file one on mlx with the model-free reproduction. What it means for this PR.
One more data point on the bfloat16 gap between the two GPUs that I mentioned: with the M5's kernel family switched off, the M5's bfloat16 GPU logits on the tiny model are bit-identical to the M3 Ultra's. So that gap comes from that kernel family and not from the port. In the model-free runs the sorted kernel agrees with the unsorted one within bfloat16 rounding whenever no NaN appears, so I do not think it is this bug, but I have not found which kernel it is or whether it is only rounding. Augustas from Malibu |
|
Four results from a second session on the M3 Ultra, 15 November. They cover three things I had left open (longer expert traces, the PR branch's tests on the M3 Ultra, the norm kernel) and re-measure against mlx-vlm. Still open from my earlier comments: the mlx issue for the gathered-matmul read, the bfloat16 difference between the two GPUs, the 1K peak, and the sparse-attention kernel I proposed, which I have not started. 1. Longer expert traces. The 512-token runs were too short to show what a 96 GiB machine's cache settles to. I reran the five workloads with a 4,096-token cap (the second turn now follows the complete first answer, so it is not the same generation as before). Four answers ended on their own (2,328, 743, 1,871 and 1,432 decode tokens); the coding task ran to the cap.
The 96 GiB reading holds with more data; the 128 GiB one changes. At 96 GiB the reads level off at about 5 to 12 experts per token in four runs; in the long English answer they rose again in the last quarter (6.0, 6.7, 9.5 over the last three quarters). With a warm cache, 66 to 100% of the last-quarter reads are re-reads of experts the cache had dropped, not first touches. At 128 GiB they drop to 0.4 to 2.5 experts per token. Two runs were still falling at the end; in the other three the last quarter was level or higher than the third. Four of the five generations now touch more than the 110 GiB cache, and in those three runs 39 to 100% of the last-quarter reads are re-reads. The decode tokens of the five generations together touched 99.3% of all experts, so across a varied session nearly every expert is needed sooner or later. Same limits as before: the cache is simulated, the prompts use my hand-written chat format, and I did not measure read speed. 2. The PR branch on the M3 Ultra. At b516e59, Release: 20 tests, 1 skipped, 0 failures, and 0 failures in 10 further iterations of the class. That covers the two tests I had only run on the M5. 3. A fused norm kernel, measured. I wrote the kernel I mentioned for the cast around
The norm row of the split was 2.7% at 1K and 1.9% at 8K, measured before 53b39aa. 53b39aa then removed the weight cast; the kernel recovers a further 0.56% and 1.3%: little at 1K, about two thirds of the row at 8K. It is not in the PR. I can add it if you think a second custom kernel is worth that much; my own view is that it is not, on these numbers. 4. Full size against mlx-vlm in the same window. Same setup as the table in the description, one run per cell; mlx-vlm ran as a separate process about 15 to 30 minutes after the Swift cells. The Swift numbers are from my local branch, which carries the PR's library changes plus the norm kernel from point 3 and the profiling and tracing hooks (off):
With the kernel switched off on the same branch (the mean of the two rounds in point 3; not the PR branch itself) decode was 28.45 tok/s at 1K and 26.09 at 8K; 32K was not measured that way. That is 10.4% below mlx-vlm at 1K and 7.8% at 8K, against 12.9% and 8.2% at 7324f75. The same library code without the kernel measured 28.71 and 26.32 in the first session, about ten hours earlier, so sessions differ by about 1%, which is more than the kernel gains at 1K. mlx-vlm ran without its wired limit, as before. I am now looking at where the remaining decode time goes relative to mlx-vlm, one decode step side by side, before changing anything else. Augustas from Malibu |
|
Thanks @Augustas11, the longer runs are very useful... If you still have the traces, two things would settle it:
On the norm kernel I agree, on these numbers it's not worth a second custom kernel. |
|
Both done, on the same five 4,096-cap workloads as the longer runs above. I reran them for the prediction; the expert ids of the rerun are byte-identical to the earlier traces, so the two parts describe the same generations. 1. Misses per token from 40 to 130 GiB. One pass of LRU stack distances over the decode tokens. Every (layer, expert) unit is the same size here (13,369,344 bytes), so the stack distance is exact, and it matched a direct LRU simulation in all 110 cases I compared (5 workloads, cold, warm and the second turn after its first, 10 sizes). I took 40 to 130 GiB as machine sizes, as before: the cache is what is left of the machine after 8 GiB headroom and the 10.04 GiB of shared weights, so the cache column runs from 22 to 112 GiB. Pooled over the five workloads, cache warm after the prompt (for the second turn that is its own prompt only, not the first turn):
A token routes to 258 experts (43 layers, 6 each), so 73.7 reads at 40 GiB is 29% of them. Last-quarter reads fall below 12 per token from an 85 GiB machine, below 5 from 104, below 2 from 120 and below 1 from 129. Above the table little changes: a 120 GiB cache reads 2.1 experts per token (0.6 in the last quarter) and a 130 GiB cache 2.0 (0.5). With no cache limit the reads are 1.9 per token over all decode and 0.5 in the last quarter, all first touches. All routed experts together are 137.1 GiB. Per workload the last-quarter figure spans 21.6 to 40.1 at 64 GiB, 4.9 to 11.5 at 96 and 0.4 to 2.5 at 128. I have the table in 1 GiB steps if you want it. 2. Layer l+1's router on layer l's FFN input. "Layer l's FFN input" can be read three ways in this model, because each layer first collapses the 4 residual streams with its own mixer and then applies its own norm before the gate. I recorded all three:
Layers 0 to 2 route by token id, so layer 3 is the first predicted target: 40 predicted layers per token. Decode tokens, pooled (418,800 token-layer pairs):
Chance is 0.14 of 6. The norm makes almost no difference (A and B agree within 0.02 at every layer); the mixer does. From target layer 19 up C is ahead at 21 of 24 layers, most at 19, 35 and 36 (5.05 against 2.62, 5.11 against 3.70, 5.11 against 3.51). Below layer 19 C is not better: the two are within 0.04 at 11 of the 16 layers, C is ahead at layer 3 (3.81 against 3.69) and behind at layers 4, 5, 9 and 14 (most at 5 and 14: 2.90 against 3.39, 3.92 against 4.37). By target layer A spans 2.62 to 4.81 and C 2.90 to 5.11. What matters for hiding misses is whether the experts that miss the cache are among the predicted ones. With the same simulated LRU cache, warm after the prompt, decode tokens, pooled:
Per workload A covers 38 to 51% and C 44 to 57%. So a prefetch issued one layer early from the next router's top 6 would have about half of the missing experts in flight, and the other half would still be read on demand. The misses are harder to predict than the average expert (about 73% of all experts are predicted by C, 51% of the missing ones), which fits: a miss is an expert not used recently, and the previous token predicts none of them by construction. Limits: I only stored each predictor's top 6, so I cannot say what a wider prefetch (top 12, say) would cover. The cache is simulated and never inserts predicted experts, so wrong prefetches cost nothing here. And I did not measure read speed. One layer of lead is about 0.8 ms at the 1K decode rate of my last comment (28.7 tok/s, 35 ms per token over 43 layers, everything in memory). Reading one 13.4 MB expert inside that would need about 16 GB/s, so one layer of lead shortens a miss but does not hide it. The predictions are computed inside the forward on my local branch behind a trace hook; logits are bit-identical with it on and off (tiny model, CPU and GPU, bfloat16 and float32, on the M3 Ultra), and nothing of it is in the PR. Agreed on the norm kernel; I leave it out. Augustas from Malibu |
The integration test imported Jinja, which the IntegrationTesting project does not link. It now downloads the pinned DeepSeek-V4-Flash tokenizer and renders each fixture case with applyChatTemplate(messages:chatTemplate:tools:additionalContext:), the path LLMModelFactory uses, and compares the tokens and their decoded text with the jinja2 output.
ThinkingBudgetProcessor threw unsupportedReasoningProtocol for ReasoningConfig.deepseekV4 unless the caller passed a transitionOverride. Declare .immediate, closing the span with </think> (token 128822) alone, as Qwen3.5 does: DeepSeek's encoder writes every reply straight after a bare </think>. The ThinkingBudget tests now run without an override.
|
@aleroot, the review items are now implemented on this branch (updated with
Tests (release test build with compiled Metal library on M3 Ultra, at
(AI-assisted note; I checked the code and the test results.) Augustas from Malibu |
|
Thanks @Augustas11, nice job. A few things before the next CI run:
|
…ekV4ChatTemplateTests
|
@aleroot, both pushed and ready for the next CI run:
(AI-assisted commits and note; I reviewed the diff.) Augustas from Malibu |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@aleroot, I merged current main into this branch ( The last run failed only in two The (AI-assisted merge and note.) Augustas from Malibu |
Proposed changes
Adds the
deepseek_v4text model (DeepSeek-V4-Flash). With the MXFP4 MLX conversion (158.0 GB resident, wired limit set to that; 0.57 tok/s without one, not re-measured at this head), an M3 Ultra (256 GB), macOS 27.0.1, decoding a 1K prompt withTokenIterator(local harness) gives 28.7 tok/s, 2.5 s to first token and 160.1 GB peak at this head, against 27.5 tok/s, 2.5 s and 160.0 GB at 7324f75; 256 of 256 greedy tokens equal the 7324f75 run's. At 8K / 32K: 25.9 / 24.8 tok/s, peak 166.0 / 166.2 GB (7324f75, not re-measured at this head).Ported from mlx-vlm 0.7.10, corrected in review to DeepSeek's
inference/model.py. I removed the opt-in HISA indexer selection taken from mlx-vlm: none of the 45 readable MLX conversion configs I surveyed sets its keys, nor does the official config. A config that carries the keys gets exact top-k; the keys are ignored (not tested). Every compared value comes from DeepSeek's code.Architecture
Outside the model file
One
SwitchGLUinitializer; registry and model-list lines.Tests
tools/deepseek-v4-reference.pyruns the pinned, sha256-checkedmodel.pyon a tiny hashed-weight model and writesDeepseekV4ReferenceValues.swift.tools/deepseek-v4-reference/kernel.pyreplaces DeepSeek's CUDA kernels with float32 CPU versions;act_quant,fp4_act_quantandrotate_activationare identity.DeepseekV4Testsrebuilds the weights; on the CPU it checks exact greedy tokens, top-4 log-probabilities within 4.3e-6 and 5.2e-6 (45 and 250 prompt tokens), tolerance 2e-5.At this head on an M5 (32 GB, macOS 27.0.1): 19 tests, 2 skipped, 0 failures. The call-split and bfloat16-load checks are skipped unless
MLX_DEEPSEEK_V4_LONG=1is set (TEST_RUNNER_MLX_DEEPSEEK_V4_LONG=1forxcodebuild); with it, 0 skipped, 0 failures.Deliberate bugs: dropping
apefrom the overlap gate fails 4 tests (up to 99,000x tolerance); shifting hash routing by one, 4 (up to 230,000x). A 19-iteration Sinkhorn is caught only by the fused-kernel-versus-ops GPU test (1.5e-4 against 3.6e-6, 42x), not by the reference comparison.IntegrationTesting/.../DeepseekV4CheckpointTestschecks the module tree and finite logits over a 512-token prefill and 8 decode steps. With the real checkpoint on the M3 Ultra (Xcode 26.6, mlx-swift 0.33.0) both pass at this head.Limits
maxKVSizeand KV quantization are ignored.MLX_ENABLE_TF32=0, and MLX's gathered quantized matmul can return NaN for K not a multiple of 64; parity runs on the CPU.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.
Augustas from Malibu