Skip to content

[Tests] Add regression tests for use_kernels=True crash on Qwen3Next and Qwen3.5#46435

Closed
kpal002 wants to merge 2 commits into
huggingface:mainfrom
kpal002:fix/qwen3next-qwen35-use-kernels-regression
Closed

[Tests] Add regression tests for use_kernels=True crash on Qwen3Next and Qwen3.5#46435
kpal002 wants to merge 2 commits into
huggingface:mainfrom
kpal002:fix/qwen3next-qwen35-use-kernels-regression

Conversation

@kpal002
Copy link
Copy Markdown
Contributor

@kpal002 kpal002 commented Jun 5, 2026

What this PR does

Adds test_kernelize_does_not_crash to Qwen3NextModelTest and Qwen3_5TextModelTest.

Root cause (from issue #46399)

Setting model.use_kernels = True on either model raises:

ValueError: Attempted to register a kernel for apply_rotary_pos_emb,
but it was not a torch.nn.Module.
This means the underlying function needs to be decorated with
@use_kernel_func_from_hub.

The generated modeling files for Qwen3Next and Qwen3.5 define a local
apply_rotary_pos_emb (partial-RoPE variant) without
@use_kernel_func_from_hub, but the attention class still inherits
@use_kernelized_func(apply_rotary_pos_emb) from the parent class via the
modular converter's decorator fallback. When kernelize() tries to register
the plain function as an nn.Module, it crashes.

This PR

  • Adds two @require_kernels-gated tests, one per model.
  • Tests currently fail (they reproduce the crash). They will pass once the
    modular converter fix lands in the follow-up PR.

Follow-up PRs (tracked in #46399)

  • PR 2: Fix utils/modular_model_converter.py — strip @use_kernelized_func(fn) from generated classes when fn is defined locally without @use_kernel_func_from_hub.
  • PR 3: Regenerate modeling_qwen3_next.py and modeling_qwen3_5.py using the fixed converter.
  • Future: Wire @use_kernel_func_from_hub("rotary_pos_emb_partial") once kernels-community#919 ships.

Closes #46399 (partial — regression test step)

cc @MekkCyber @vasqu @ArthurZucker @drbh

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline?
  • Did you discuss your PR/implementation with the related model author(s) in the issue?
  • Did you update the documentation with the relevant changes?
  • Did you write any new necessary tests?

…and Qwen3.5

Adds test_kernelize_does_not_crash to Qwen3NextModelTest and Qwen3_5TextModelTest.
Setting model.use_kernels = True raises ValueError because @use_kernelized_func
references apply_rotary_pos_emb which lacks @use_kernel_func_from_hub in the
generated modeling files for these two models.

Tests are gated with @require_kernels and currently expected to fail — they will
pass once the modular converter fix in the follow-up PR lands.

Fixes huggingface#46399

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

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

run-slow: qwen3_5, qwen3_next

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen3.5: use_kernels=True crashes with ValueError on apply_rotary_pos_emb registration - missing decorator

3 participants