Skip to content

fix: include input dtypes in compiled kernel names - #19

Merged
solderzzc merged 1 commit into
mainfrom
fix/compiled-kernel-input-dtypes
Sep 25, 2026
Merged

solderzzc merged 1 commit into
mainfrom
fix/compiled-kernel-input-dtypes

Conversation

@solderzzc

Copy link
Copy Markdown
Member

Proposed changes

Applies the upstream fix ml-explore/mlx@c594e6ec38 (ml-explore/mlx#3427) to the vendored MLX in Source/Cmlx/mlx, ahead of the planned upstream sync. The change is identical to the upstream commit.

Compiled::Compiled moves inputs and constant_ids into its members, then builds the kernel name from the moved-from parameters, so the input dtypes are missing from the name. Two graphs that differ only in input dtype (for example bf16 and f16 inputs that are upcast to float32) get the same name and share one Metal library, so the second graph runs the first one's kernel. The fix builds the name from the members.

In mlx-swift-lm this makes Qwen3NextCompiledDecodeTests (f16) fail whenever Qwen35QLoRATests (bf16) runs first in the same process.

Testing

  • New testCompiledKernelsDifferByInputDtype: compiles one function and calls it with bf16, then f16 input. It fails without this change and passes with it.
  • swift test on an M5 Pro: 508 tests pass with --skip WiredMemoryTests. WiredMemoryTests passes on its own, but in a full run it crashes in resident.cpp (-[_MTLFunctionInternal allocatedSize]: unrecognized selector). The crash also happens on main (384de38) and is not related to this change.
  • mlx-swift-lm built against this branch: Qwen35QLoRATests + Qwen3NextCompiledDecodeTests together pass (7 tests, 0 failures); on main they give 4 failures.

Checklist

  • 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-format 6.2.3 with .swift-format: the changed test file is clean.

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 Code (Opus 5.5) traced the failure to this upstream fix, applied it, wrote the test, ran the tests, and wrote this description.

🤖 Generated with Claude Code

Apply ml-explore/mlx@c594e6ec38 (ml-explore/mlx#3427) to the vendored
MLX. Compiled::Compiled built the kernel name from the moved-from
inputs, so graphs that differ only in input dtype got the same name and
shared one Metal library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@solderzzc
solderzzc merged commit 1a2b3af into main Sep 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant