Skip to content

Add GB10/SM121 Hub-kernel path for Qwen3.6 Gated DeltaNet - #46423

Merged
vasqu merged 6 commits into
huggingface:mainfrom
AzeezIsh:gdn-sm121-kernelize-qwen3_6
Jun 19, 2026
Merged

vasqu merged 6 commits into
huggingface:mainfrom
AzeezIsh:gdn-sm121-kernelize-qwen3_6

Conversation

@AzeezIsh

@AzeezIsh AzeezIsh commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

On a DGX Spark (GB10, compute capability 12.1) the fla and causal_conv1d fast paths have no SM121 build, so Qwen3.6 falls back to the slow pure-torch Gated DeltaNet (is_fast_path_available=False). Register a compute-capability- gated Hub kernel (Atlas-Inference/gdn) for the Qwen3.6 GDN layers so GB10 users get a fast path automatically; every other GPU keeps the existing path.

  • Decorate Qwen3_5GatedDeltaNet (Qwen3.6-27B dense) and Qwen3_5MoeGatedDeltaNet (Qwen3.6-35B-A3B) with @use_kernel_forward_from_hub(...) in the modular files; regenerate modeling via the modular converter.
  • Add two CUDAProperties(min=121, max=121)-gated entries in integrations/hub_kernels.py.

The kernel is a stateless kernels layer: it reuses the host module's projections, gated RMSNorm, and out_proj and replaces only the conv1d and gated-delta-rule cores. Output parity vs the torch fallback is cosine >= 0.9999 on GB10; a full-model greedy generate() produces identical token IDs.

What does this PR do?

The two decorators in the modular_*.py files (with modeling_*.py regenerated by the converter) plus the two gated entries in integrations/hub_kernels.py.

Verified on GB10 (SM121), bf16:

  • Layer parity vs the torch fallback through a real DynamicCache (prefill + 8 decode), using the published Hub kernel Atlas-Inference/gdn@v0: 27B 0.999970, 35B-A3B 0.999967 reproduced on a second, clean box via an unauthenticated Hub pull.
  • Decorator path (this PR's mechanism): kernel_layer_name set, kernelize() swaps the forward, parity unchanged.
  • Full-model greedy generate() (Qwen3_5MoeForCausalLM): identical token IDs vs the torch fallback, GDN layers confirmed swapped to the Atlas kernel.

Context: follow-up to huggingface/kernels-community#866 (@sayakpaul asked to show how the Atlas SM121 kernels can be used in transformers). No overlapping PR exists. One non-blocking follow-up for reviewers: the mapped kernel currently needs trust_remote_code=True until Atlas-Inference is added to the kernels trusted-publisher allowlist (or the layer is hosted under kernels-community)

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

Before submitting

Who can review?

@drbh (kernels integration) and @Cyrilvallez (text models / Qwen3.6).

@vasqu vasqu 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.

Just have 2 smaller questions but that is exciting!

pass


@use_kernel_forward_from_hub("Qwen3_5MoeGatedDeltaNet")

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.

Any reason we make the distinction here? It should be the same as the non-moe as we only handle the GDN x conv1d path here, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The GDN core is identical for dense and MoE (the MoE-ness only lives in the MLP, not the attention), so we'll collapse it to one shared name and dropped the redundant entry. Thanks for pointing this out!

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.

Ah ig the qwen 3 next variation is not included because of the different memory layout of the projections (fused vs split)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's right, Qwen3-Next uses fused projection weights (in_proj_qkvz, in_proj_ba) while Qwen3.5 deletes those and uses split ones (in_proj_qkv/z/b/a). Our kernel reuses the host module's projections, so it's written against the split layout

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.

Thanks, yes that makes sense!

@AzeezIsh

AzeezIsh commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

I believe I've addressed your comments @vasqu just wanted to bring up some blockers for the use_kernels=True path for qwen3_5, both independent of this kernel. Firstly the Atlas-Inference/gdn entry needs trust_remote_code=True for now, can drop it once Atlas-Inference is an allow-listed kernel publisher. use_kernels=True also currently crashes on qwen3_5 rotary, the attention is decorated @use_kernelized_func(apply_rotary_pos_emb) but the function lacks @use_kernel_func_from_hub, and the only rotary Hub kernel (kernels-community/rotary) is uncompatible with qwen3_5's partial rotary (shape mismatch 128 vs 64). I feel this needs a maintainer decision, happy to help look into this

@vasqu

vasqu commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Hey @AzeezIsh 👋

Yes that's true, I think we also need to slightly rewrite the logic in transformers (as we limited this quite a bit before trusted kernels was a thing), see

# all `kernels-community` repos are trusted by default!
if repo_parent != "kernels-community" and not allow_all_kernels:
raise ValueError(
"You need to specify `allow_all_kernels=True` to use kernels outside of the `kernels-community` repository"
)

I'm working on upgrading the minimum kernels version so we can use the proper in-built feature (see #46039 for syncing to latest kernels)

Yes the issue is known (#46399). The underlying issue is that modular always inherited that decorator so we need something that disallows it. I will try working on it to unblock this.

layer_name="Qwen3_5GatedDeltaNet",
revision="v0",
# TODO: drop once Atlas-Inference is an allow-listed publisher
trust_remote_code=True,

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.

Inherently agree with this, would it be ok to wait until we figure this out

  1. Get you to be a trusted publisher
  2. I fix to latest kernels and the associated issues

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @vasqu, that works for me on both counts!

On the trusted-publisher and kernels-version path yes, happy to wait until that lands. No rush on my end. Once Atlas-Inference is allow-listed (or the layer moves under kernels-community) and the min-kernels bump in #46039 goes in, I can drop the trust_remote_code=True from the mapping entry.

Also confirmed #46440 fixes it! I rebased onto main (so the no_inherit_decorator change is in) and re-ran the full e2e on a second, clean GB10 (SM121) box, fresh env, pulling Atlas-Inference/gdn@v0 from the Hub:

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.

Awesome that's good to hear! I will work on the versioning with kernels and we should get a first pass this week in then.

Let me nudge internally re trusted publishers 🫡 this is some awesome work!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @vasqu just bumping this!

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.

Yup, sorry there were a lot of delays and unexpected issues I encountered but I finally merged my PR!

Can you sync with main? I would plan to let this live as trust remote code but pin a revision along with it for now 🤗 We can also add a small todo

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.

Let's also add some small docs about benchmark numbers. I think that would be very nice 🫡

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @vasqu, both done. Synced with main, conflict-free (the kernels bump and #46440 are both in, so it uses the in-built CUDAProperties gate). Kept it as trust_remote_code with a pinned revision (Atlas-Inference/gdn@v0) plus a TODO to drop trust_remote_code once Atlas-Inference is allow-listed :)

Also added before/after numbers to the dense and MoE usage docs. GB10/SM121, bf16, 1024-token prompt, greedy:
Qwen3.6-27B TTFT 1.66s -> 1.11s (1.49x), decode 4.11 -> 4.14 tok/s
Qwen3.6-35B-A3B TTFT 0.73s -> 0.53s (1.38x), decode 16.3 -> 16.7 tok/s

Greedy token IDs are identical between the two paths for exact parity, and the kernel only engages on SM121.

Ready for another look when you get a chance!

@vasqu

vasqu commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

For the second issue: #46440 - this should fix the problem allowing non inheritance where needed

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

CI Dashboard: View test results in Grafana

…rk docs

Rebase the Qwen3.6 GB10/SM121 Gated DeltaNet kernel path onto current main:
use the in-built CUDAProperties capability gate, share one Atlas-Inference/gdn
mapping entry across the dense and MoE Gated DeltaNet, and pin the kernel
revision (trust_remote_code with a TODO to drop once Atlas-Inference is an
allow-listed publisher). Add GB10/SM121 benchmark numbers to the Qwen3.5/3.6
usage docs.
@AzeezIsh
AzeezIsh force-pushed the gdn-sm121-kernelize-qwen3_6 branch from bdce881 to 90bc799 Compare June 18, 2026 06:31

@vasqu vasqu 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.

Just one small nit, then we can merge. Very nice!

Comment thread docs/source/en/model_doc/qwen3_5.md Outdated
## Usage tips and notes

- Layers are hybrid: [`Qwen3_5TextConfig`]'s `layer_types` is a per-layer list of `"linear_attention"` or `"full_attention"` that encodes the 3:1 Gated DeltaNet / Gated Attention stack. The DeltaNet path (`Qwen3NextGatedDeltaNet`) needs the optional `causal_conv1d` (from [Dao-AILab](https://github.com/Dao-AILab/causal-conv1d)) and `fla` packages for its fast kernels — without them, the model silently falls back to slower and more memory hungry PyTorch ops.
- On NVIDIA GB10 (compute capability 12.1 / SM121) neither `causal_conv1d` nor `fla` ship an SM121 build, so the DeltaNet path always falls back to the slow PyTorch reference. Passing `use_kernels=True` to [`~PreTrainedModel.from_pretrained`] swaps the Gated DeltaNet conv1d and delta-rule cores for a compute-capability-gated Hub kernel ([`Atlas-Inference/gdn`](https://huggingface.co/Atlas-Inference/gdn)); every other GPU keeps the existing path. The kernel is numerically faithful to the fallback (identical greedy output) and speeds up prefill. Measured on `Qwen/Qwen3.6-27B` (bf16, GB10/SM121, 1024-token prompt, greedy decode of 256 tokens):

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 would just add a small note that you also need kernels to be installed pip install kernels==0.15.2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call @vasqu, added a note in both the dense and MoE docs that loading the mapped kernel needs the kernels package (pip install kernels==0.15.2). Also merged latest main to bring the branch up to date, thanks!

AzeezIsh and others added 3 commits June 19, 2026 00:36
Document that use_kernels=True needs the kernels package (pip install kernels==0.15.2) in the Qwen3.5 and Qwen3.5-MoE usage docs.

@vasqu vasqu 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.

We are good to merge I just fixed some small nits on my side; mainly pinning to an explicit commit to be on the safe side (93b6eda)

Lmk if that's ok, then I merge 🤗

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

We are good to merge I just fixed some small nits on my side; mainly pinning to an explicit commit to be on the safe side (93b6eda)

Lmk if that's ok, then I merge 🤗

Looks great to me @vasqu, please feel free to merge!

@vasqu
vasqu enabled auto-merge June 19, 2026 16:50
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: qwen3_5, qwen3_5_moe

@vasqu
vasqu added this pull request to the merge queue Jun 19, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Merged via the queue into huggingface:main with commit 95ed1b8 Jun 19, 2026
103 checks passed
@vasqu

vasqu commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Let's go 🥳 thanks a lot for sticking through

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Thanks so much @vasqu, plan to push more work up for DGX along with the Strix Halo too. Likely need to enable that arch (gfx1151) to run transformers as well! Will link an issue/PR for this to follow up :)

@vasqu

vasqu commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Yep, dont hesitate to cc me. If idk, I can at least forward internally as well 🤗

@vasqu

vasqu commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Btw @AzeezIsh https://github.com/huggingface/kernels/releases/tag/v0.16.0 might be interesting for you as well, we will also adopt kernels signing bit by bit 🤗

stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
…e#46423)

* Sync GB10/SM121 Gated DeltaNet Hub-kernel path with main; add benchmark docs

Rebase the Qwen3.6 GB10/SM121 Gated DeltaNet kernel path onto current main:
use the in-built CUDAProperties capability gate, share one Atlas-Inference/gdn
mapping entry across the dense and MoE Gated DeltaNet, and pin the kernel
revision (trust_remote_code with a TODO to drop once Atlas-Inference is an
allow-listed publisher). Add GB10/SM121 benchmark numbers to the Qwen3.5/3.6
usage docs.

* Note kernels package install for GB10/SM121 Gated DeltaNet Hub kernel

Document that use_kernels=True needs the kernels package (pip install kernels==0.15.2) in the Qwen3.5 and Qwen3.5-MoE usage docs.

* small nits

---------

Co-authored-by: vasqu <[email protected]>
@AzeezIsh

AzeezIsh commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Hey @vasqu! Wanted to quickly revisit this conversation, I heard slack is the place to be... Also congrats :)

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.

3 participants