Repository navigation
fix speculative decode tests - #326
Merged
Merged
Conversation
- fix #315 - run models in float16 (more typical) and avoid the float32/tf32 mismatch
Member
Author
|
@petrukha-ivan FYI -- this works as expected |
This was referenced Jun 16, 2026
dkgv
pushed a commit
to dkgv/mlx-swift-lm
that referenced
this pull request
Jul 30, 2026
* fix speculative decode tests - fix ml-explore#315 - run models in float16 (more typical) and avoid the float32/tf32 mismatch
This was referenced Jul 31, 2026
davidkoski
pushed a commit
that referenced
this pull request
Jul 31, 2026
…485) On devices with a NAX these two tests fail (#357). Both build a synthetic model from config, leaving the MLXNN weights at their random float32 defaults, then assert that chunked and single-pass prefill agree to a tolerance calibrated for exact float32. The two paths are mathematically equivalent, but TF32 can select different kernels and reduction orders by shape, so the logits drift past that tolerance. The chunking logic is correct; the oracle is not. - Cast both synthetic models to f16, as merged #326 did for SpeculativeDecodingTests. Real models never run float32. - Pin the initializer weights with withRandomState. The tests in these suites run concurrently, so MLXRandom.seed would not work here: it mutates process-global state that the other tests draw from. - In Gemma4ChunkedPrefillTests, compare max absolute difference rather than allClose, since these logits pass through zero where relative error is meaningless, and widen the bound to 5e-2. Gemma4UnifiedTests keeps its 1e-4 bound: with the model in f16 that test is bitwise equal, so only the cast was needed. unbatchedTokensAccepted moves to the same max-abs-diff form. Its old rtol 1e-4 / atol 1e-5 was finer than one f16 ulp (~2e-3 at these magnitudes) once the shared factory started returning an f16 model. Exact cache-offset assertions are unchanged throughout; those catch the chunk-boundary bugs these tests exist for and are not precision sensitive. With the weights pinned the drift is deterministic: 6.2e-3, 8.4e-3, 6.4e-3, 6.2e-3 for chunk sizes 16/8/5/3, identical across runs and unchanged with MLX_ENABLE_TF32=0. 5e-2 leaves ~6x margin, while an injected cache/mask defect moves these logits by 1.0-2.4.
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
…l-explore#326) * style(gptoss): format GPTOSS+Experts.swift for the Lint gate Format-only: line breaks and indentation, no token changes. The Lint workflow formats every Swift file that a pull request changes with .swift-format and fails on any resulting diff. This file is not formatted on main, and the next commit edits it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(gptoss): keep bf16 activations through the expert SwiGLU clamp `swiglu` clamped with `MLXArray(limit)` bounds. They are float32 0-d arrays, so `clip` promoted bf16 expert activations to float32, and the residual add carried float32 into every later layer: layers 1-23 of a bf16 gpt-oss-20b checkpoint ran their projections and stored K/V in float32. Swift scalar bounds take the input dtype through `ScalarOrArray`, as the Python float bounds of mlx-lm's `swiglu_oai` do. bf16 checkpoints now stay bf16 and float32 models stay float32. The bounds came from the upstream port. The opt-in compiled single-token expert graph wraps the same function, so both expert routes change. gpt-oss-20b native full-attention K/V falls from 49,152 to 24,576 bytes per token; consumers that size from the observed native types (`CBv2NativeKVTypeProbe`) follow. `GPTOSSActivationDTypeTests` (kernel) builds bf16 and float32 tiny models with MXFP4 experts and checks the eager (sorted and unsorted) and compiled expert outputs, every layer's output, the logits, and the probe's per-layer K/V dtypes. Three comments that described GPT-OSS K/V as float32 now match, and fork.yaml describes the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(gptoss): price catalog window checkpoints with bf16 K/V `HistoricalWindowCheckpointTests.catalogWindowReservation` still sized gpt-oss-20b windows with float32 K/V ("float32 for 23 of its 24 layers") and expected ~7 MB per checkpoint. With scalar clamp bounds every layer of the bf16 checkpoint stores bf16 K/V, so the catalog row uses 2-byte elements: 262,144 logical bytes per window layer and 4,462,452 bytes reserved per checkpoint (~4.5 MB; three retained checkpoints are ~13 MB). The staged byte budget comment in `CompleteCheckpointCapture.swift` quotes reserved bytes, as its gemma-4-26b figure does, so gpt-oss-20b is ~4.5 MB there rather than the 3.15 MB logical window size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
Brings ml-explore#322 (Flint), ml-explore#324, ml-explore#326-ml-explore#330 (CBv2 paged/MTP/SDPA, GPT-OSS), ml-explore#325 and the Nemotron Super fused MTP verify window: SDK main up to the commit d-inference master pins (889fe3c). Main's later ml-explore#331/ml-explore#332 are left out until the provider adopts ml-explore#332's streamed tool-call type. Package.swift pins the cluster mlx-swift 9fe34405 instead of main's 67dc7528; that was the only conflict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes