Skip to content

Fix/isolated mlx test streams (fixes unit tests on main)#291

Closed
christophsturm wants to merge 2 commits into
ml-explore:mainfrom
christophsturm:fix/isolated-mlx-test-streams
Closed

Fix/isolated mlx test streams (fixes unit tests on main)#291
christophsturm wants to merge 2 commits into
ml-explore:mainfrom
christophsturm:fix/isolated-mlx-test-streams

Conversation

@christophsturm
Copy link
Copy Markdown

Proposed changes

Swift Testing can run suites concurrently. The previous .serialized trait only serialized tests within RoPEApplicationTests, so it did not prevent gemma3nAttentionTest from running alongside KV cache and speculative decoding tests.

Those tests all enqueue and evaluate MLX work through StreamOrDevice.default. Without a task-local override, that resolves to the shared default GPU stream, so separate tests can interact through the same underlying command-buffer lifecycle and trip Metal's 'Completed handler provided after commit call' assertion.

Run the RoPE test under Stream.withNewDefaultStream and synchronize that scoped stream before returning. This isolates the MLX stream state for the test while preserving Swift Testing parallelism instead of serializing unrelated tests.
Please include a description of the problem or feature this PR is addressing. If there is a corresponding issue, include the issue #.

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)

Swift Testing can run suites concurrently. The previous .serialized trait only serialized tests within RoPEApplicationTests, so it did not prevent gemma3nAttentionTest from running alongside KV cache and speculative decoding tests.

Those tests all enqueue and evaluate MLX work through StreamOrDevice.default. Without a task-local override, that resolves to the shared default GPU stream, so separate tests can interact through the same underlying command-buffer lifecycle and trip Metal's 'Completed handler provided after commit call' assertion.

Run the RoPE test under Stream.withNewDefaultStream and synchronize that scoped stream before returning. This isolates the MLX stream state for the test while preserving Swift Testing parallelism instead of serializing unrelated tests.
@christophsturm christophsturm changed the title Fix/isolated mlx test streams Fix/isolated mlx test streams (fixes unit tests on main) May 17, 2026
@davidkoski
Copy link
Copy Markdown
Collaborator

Can you give more info on the failure? Separate streams should not be required, even if tests are running concurrently.

I was able to trigger a failure, but this is in mlx-swift: ml-explore/mlx-swift#410

@davidkoski davidkoski added the question Further information is requested label May 18, 2026
@christophsturm
Copy link
Copy Markdown
Author

you are right! it seems the prints in the test are the problem so the real fix is your ml-explore/mlx-swift#410 (and in the meantime removing the prints would also fix it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants