Skip to content

adjustments for running tests on NAX/TF32 hardware - #649

Merged
davidkoski merged 2 commits into
mainfrom
tests-tf32
Sep 30, 2026
Merged

davidkoski merged 2 commits into
mainfrom
tests-tf32

Conversation

@davidkoski

@davidkoski davidkoski commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

adjustments for running tests on NAX/TF32 hardware.

I have been relying on CI machines for test runs -- the runners are M4 and do not have NAX/TF32. When I ran it locally (M5) I found some assertion failures in tolerance. Running with MLX_ENABLE_TF32=0 eliminated the errors, so that strongly suggests they are NAX/TF32 related.

In mlx-swift we have a dedicated integration test target that forces that to be set, but all of the tests in there are built with a python tool that ensures the results match mlx (python). The tool is able to ensure that all code passes through a handler that sets MLX_ENABLE_TF32. Not really feasible here.

The approach I took is to detect NAX and pick an appropriate threshold based on that.

Also some changes (not necessarily TF32 related) in AllowedToolOutputRouterTests.swift to handle text split across tokens.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

AI usage

  • I have read this PR description in full and approve it as my own, and it
    accurately describes the code changes.
  • AI usage disclosure: claude-opus-5 was used to implement the changes to the tests & NAX detection / threshold code.

@nwh nwh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, some minor comments

Comment thread Tests/MLXLMTests/TurboQuantTests.swift Resolved
}
return text
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention in PR description that this fix is unrelated to TF32

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

} else {
XCTAssertGreaterThan(
diff, 1e-3,
diff, MatmulPrecision.splitTolerance,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have M5, so can't verify this. Claude thinks TF32 noise might trigger a failure here:

  • When expectsIsolation == false (Qwen2VL), the test asserts diff > splitTolerance. So on TF32
    the required divergence rose from 1e-3 to 2e-2.
  • On M4 (float32), the real cross-image effect in Qwen25VLContinuationTests measures
    0.0468. That leaves only about 2.3× headroom over 2e-2, and TF32 noise can move diff either
    way.
  • Tightening is the right direction: at 1e-3, TF32 noise (~3e-3) could satisfy the check by
    itself. But the cutoff here should be "clearly above noise", not "the equality tolerance".
  • Suggestions:
    • Use a dedicated lower bound, e.g. tolerance(float32: 1e-3, reduced: 1e-2).
    • Or, better, compare against a measured noise floor, as assertWarmTextContinuation already does.
    • At minimum, add the measured value to the failure message.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the tests do pass on both M4 and M5. The value shouldn't need to be added to the message -- the assert output will already include that.

Co-authored-by: Nick Henderson <525247+nwh@users.noreply.github.com>
@davidkoski
davidkoski merged commit 3b339ad into main Sep 30, 2026
5 checks passed
@davidkoski
davidkoski deleted the tests-tf32 branch September 30, 2026 22:29
wballard added a commit to swissarmyhammer/mlx-swift-lm-old that referenced this pull request Oct 3, 2026
Apply the upstream commits ee673d6..55db721 as a 3-way patch. CLAUDE.md is
excluded.

- c043fb3 pick up mlx-swift 0.32.2 (ml-explore#646)
- 0493daf Named image attachments in MLXLMCommon and the Foundation Models adapter (ml-explore#535)
- 0dcfe2f Convert the booleans in tool parameter schemas to Swift Bool values (ml-explore#653)
- 37dab60 be able to trigger workflows on main. notes about upcoming releases. (ml-explore#647)
- 390c5fd require mlx-swift-0.32.3 for SDK issue (ml-explore#657)
- 3b339ad adjustments for running tests on NAX/TF32 hardware (ml-explore#649)
- ac6f565 update documentation and skills (ml-explore#489)
- ce3950e Drop MTP weights from converted Qwen 3.5 VLM checkpoints (ml-explore#642)
- 9112fae Synchronize cross-SIMD WHT reads before shared-memory writes (ml-explore#650)
- 7e4024e NemotronH: MoE keys are optional, so dense checkpoints load (ml-explore#635)
- 1830ae4 Declare the fused GDN projection as compile state so it frees with the model (ml-explore#631)
- 6e0a0b2 Synchronize Metal before checking cached buffer memory (ml-explore#667)
- 9afc3b5 Recommend upToNextMinor in installation instructions (ml-explore#668)
- 55db721 Reduce Qwen3 reranking memory by projecting final tokens only (ml-explore#621)

Conflict resolutions:

- MLXLanguageModel.swift: keep the drain coordinator and runRespond of
  stable, and keep historyMessages. Add the upstream attachment label
  validation before resolveConfiguration. historyMessages now throws,
  because TranscriptConverter.mlxMessages now throws.
- TranscriptConverter.swift: keep the mlxMessages(for:replayReasoning:) and
  convert(entry:) form of stable. Apply the upstream changes in
  convert(entry:): it throws, an instructions entry drops its images, and
  extractImages(from:in:) applies the orientation and rejects content that
  is not an image.
- Chat.swift: keep the doc comments of stable, and add the upstream
  MessageContentLayout and contentParts(for:layout:).
- TurboQuantKernels.swift: keep stable. Stable already fixed the same
  cross-SIMD WHT race with two barriers per stage.
- KVCacheTests.swift: take the upstream file (upstream changed it to a
  suite). Delete the upstream ArraysCache.advance test, because in this fork
  advance(_:) also moves offset. Add the fork tests for advance and the
  trim-then-continue test at file scope.
- Qwen35FusedGDNProjectionTests.swift: keep the deletion of the opt-in
  benchmark (it skips unless an environment variable is set). Add the new
  upstream memory test.
- model-container.md: take upstream (llama3_2_3B_4bit and the macros are
  the real API).
- TranscriptConverterTests.swift: the replayReasoning calls now use try.

Tests: MLXGuidedGenerationTests 70, MLXFoundationModelsTests 349,
CXGrammarTests 7, MLXHuggingFaceMacrosTests 5 pass. MLXLMTests: 1287 Swift
Testing tests pass, and 699 of 700 XCTest tests pass. The failure is the
wall-clock limit of EvalTests
testVarianceNormalizedKVCache32KIngestAndDecodePeakMetalMemorySmoke (0.29 s,
limit 0.25 s) in the full run. The test passes alone two times, and this
merge does not change EvalTests.swift.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidkoski davidkoski mentioned this pull request Oct 22, 2026
4 of 5 tasks
saurabhav88 added a commit to saurabhav88/mlx-swift-lm that referenced this pull request Nov 10, 2026
…l-explore#649)

Backport ml-explore/mlx-swift-lm commit
3b339ad "adjustments for running tests on
NAX/TF32 hardware", tests only, with one declared adaptation.

On hardware with neural accelerators MLX runs some float32 matmuls as TF32.
Tests that compute one result two ways then disagree by about 1e-3 instead
of 1e-7, so bounds sized for IEEE float32 fail for reasons unrelated to the
code under test. At this fork's base that left 26 continuation cases, the
SSM test and both GDN speculative-checkpoint tests failing on an M5, which
would hide a real regression. MatmulPrecision measures the precision and
each call site states a strict and a reduced bound. The router tests now
compare assembled response text.

Adaptation (not upstream): MatmulPrecision.relativeMatmulError is the larger
of two shapes. With the MLX core this fork pins (0.31.1) the upstream
[64, 512] x [512, 64] product is dispatched to the split-K kernel, which
stays IEEE float32 when TF32 is on, so the upstream probe read 7.8e-7 on an
M5 and kept the strict bounds. A [64, 64] x [64, 64] product takes the
regular kernel and reads about 9e-4 there, 0 with MLX_ENABLE_TF32=0.
Revalidate the probe shapes whenever the mlx-swift pin changes.

Tests: the full suite passes in default mode and with MLX_ENABLE_TF32=0
(650 XCTest tests with 2 skipped; Swift Testing bundles of 863, 154, 70 and
7 tests), including the new probe self-test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants