Repository navigation
Fix attention mask for float16 - #496
Merged
Merged
Conversation
davidkoski
approved these changes
Oct 4, 2026
davidkoski
left a comment
Member
There was a problem hiding this comment.
Nice! Just waiting on CI, thanks!
Merged
2 of 4 tasks
eejd
pushed a commit
to eejd/mlx-swift
that referenced
this pull request
Oct 18, 2026
…lx-swift Real merge of upstream/main (b4f7684, "Fix attention mask for float16 (ml-explore#496)") instead of a snapshot copy, so upstream history is preserved and future syncs only have to deal with new commits. - Re-vendor mlx v0.32.2 (1f8e74e) and mlx-c ebc88f1 as plain directories and re-apply the SharpAI patch series on top (SSD expert streaming, TurboKV, fast loaders, mlx-c fast.* wrappers, quieter Metal compile logging). - Drop the old lazy per-thread Metal command encoder patch: upstream's Swift StreamPool creates streams with mlx_stream_new_thread_unsafe, so they already work across threads, and a second encoder for the same stream index would silently break ordering. - mlx-c: forward the Swift stream in mlx_fast_streamed_gather_mm (it used only the device, which crashes when the graph is evaluated on another thread) and make the prefetch cache's try_take check the stored size before copying. - Regenerate Source/Cmlx/mlx-generated with tools/update-mlx.sh; keep moe_stream.metal. - Swift: keep the fork's MLXFast bindings next to upstream's crossEntropy and the compile scoped-default-device fix. - Package.swift stays on swift-tools-version 5.12 (upstream's 6.3;(experimentalCGen) is only needed for the Linux CUDA plugin, which this fork does not ship). - Restore upstream fixes that an earlier sync (877d992) had silently reverted: Module.update dictionary keys (ml-explore#356), ellipsis indexing copy (ml-explore#358/ml-explore#363), init order (ml-explore#367), WiredMemory cancellation guard (ml-explore#369), release.yml (ml-explore#471). - Add SSDStreamingTests (streamedGatherMM, preadInto, preadIntoOffset, and evaluation on a different thread). - Document the layout and the merge procedure in UPSTREAM_MERGE_PLAN.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
8 of 9 tasks
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
This PR fixes a bug in
MultiHeadAttention.createAdditiveCausalMaskwhich occurs withfloat16which will yield invalid values in
float16due to the fact that
-1e9is not representable in float16, yielding infinities at the masked location and nan (0 * inf) in unmasked locations.This doesn't occur in python
which correctly uses the min representable value for all types
.
The fix is simply to use
dtype.finfo.minwhere available in the function.This PR adds a unit tests that fails before the fix and succeeds after.
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes