Skip to content

Qwen 3.5 MoE: Add Metal source transformations#18879

Merged
manuelcandales merged 40 commits intomainfrom
gh/manuelcandales/174/head
Apr 21, 2026
Merged

Qwen 3.5 MoE: Add Metal source transformations#18879
manuelcandales merged 40 commits intomainfrom
gh/manuelcandales/174/head

Conversation

@manuelcandales
Copy link
Copy Markdown
Contributor

Adds metal_source_transformations.py with module replacements for Metal:

  • FusedMoEExperts -> MetalMoEExperts (two metal::gather_qmv calls with
    SiLU gating, replacing torch.ops.triton.fused_moe)
  • GatedDeltaNet -> metal::gated_delta_rule custom op (replaces both the
    T=1 native path and T>1 Triton kernel)
  • FullAttention -> removes turboquant codepath, keeps standard SDPA
  • SparseMoE -> removes .float() cast on expert_weights

Also includes quantize_experts_metal() which quantizes expert weights to
MLX affine INT4 format (unsigned uint4 with scale + bias per group),
compatible with the Metal gather_qmv kernel.

Authored with Claude.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@manuelcandales manuelcandales requested a review from lucylq as a code owner April 14, 2026 16:25
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 14, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18879

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 166 Pending

As of commit 187e4f5 with merge base d408a10 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
# Metal custom op: handles both T=1 and T>1
import executorch.backends.apple.metal.ops.gated_delta_rule as _ # noqa: F401

output = torch.ops.metal.gated_delta_rule(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For future work, maybe we should fuse the q/k expansion into the kernel

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Base automatically changed from gh/manuelcandales/173/head to main April 21, 2026 18:00
[ghstack-poisoned]
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@manuelcandales manuelcandales merged commit 9600f63 into main Apr 21, 2026
166 of 190 checks passed
@manuelcandales manuelcandales deleted the gh/manuelcandales/174/head branch April 21, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants