Skip to content

[Modular] Add no_inherit_decorators and fixup wrong RoPE related inheritances #46440

Merged
vasqu merged 8 commits into
huggingface:mainfrom
Bissmella:fix/no-inherit-decorators-kernel-crash-v2
Jun 5, 2026
Merged

[Modular] Add no_inherit_decorators and fixup wrong RoPE related inheritances #46440
vasqu merged 8 commits into
huggingface:mainfrom
Bissmella:fix/no-inherit-decorators-kernel-crash-v2

Conversation

@Bissmella

Copy link
Copy Markdown
Contributor

Fixes #46399

What does this PR do?

Several attention classes inherit @use_kernelized_func(apply_rotary_pos_emb) from their parent
but override apply_rotary_pos_emb with a version that has no @use_kernel_func_from_hub decoration.
When use_kernels=True is set, kernelize() tries to register the raw function in _hidden_kernels
as an nn.Module and crashes with a ValueError.

The root cause is in replace_class_node() in modular_model_converter.py, when a modular class
defines no decorators of its own, the converter falls back to the parent class decorators, blindly
propagating @use_kernelized_func even when the underlying function has no kernel backing.

Affected models: qwen3_next, qwen3_5, glm4_moe, glm4v_moe, moonshine, laguna

This PR introduces a general-purpose @no_inherit_decorators sentinel in utils/generic.py.
When placed on a class in a modular file, it signals the converter to drop all parent class
decorators for that class. The dummy decorator itself is stripped from the generated output and doesn't
appears in the final modeling_*.py files.

The fix is intentionally general, this decorator propagation problem is not limited to kernels
and could affect other decorators in the future.

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read CONTRIBUTING.md.

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

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,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@vasqu, @drbh, @Cyrilvallez

@vasqu vasqu changed the title [Modular] Add no_inherit_decorators sentinel to prevent incorrect kernel decorator inheritance [Modular] Add no_inherit_decorators and fixup wrong RoPE related inheritances Jun 5, 2026
@vasqu vasqu requested a review from ArthurZucker June 5, 2026 12:36
@vasqu

vasqu commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Thanks @Bissmella, this is a bit more important so I went ahead and took a bit over to also allow the same for functions

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

Make sur the tests is a mixin test its a good catch! 🤗

Comment thread tests/models/qwen3_5/test_modeling_qwen3_5.py Outdated
2. Take the decorators attached in the modular file.
3. Inherit all existing decorators of the parent/original node, if any.
"""
decorator_names = [mapper.python_module.code_for_node(dec.decorator) for dec in modular_node.decorators]

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.

there's probably a faster way to do this but no worries!

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

CI Dashboard: View test results in Grafana

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: bamba, cohere, cohere2, cohere2_moe, ernie4_5, ernie4_5_moe, ernie4_5_vl_moe, flex_olmo, gemma4, glm, glm4, glm4_moe, glm4v_moe, glm_image, glmasr, helium

@vasqu vasqu enabled auto-merge June 5, 2026 14:09
@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.

@vasqu vasqu added this pull request to the merge queue Jun 5, 2026
@vasqu vasqu removed this pull request from the merge queue due to a manual request Jun 5, 2026
@vasqu vasqu added this pull request to the merge queue Jun 5, 2026
Merged via the queue into huggingface:main with commit bcd12e3 Jun 5, 2026
29 checks passed
khushali9 pushed a commit to khushali9/transformers that referenced this pull request Jun 8, 2026
…heritances (huggingface#46440)

* feat: add no_inherit_decorator sentinel to fix kernel decorator propagation in modular converter

* formatting

* fixup the decorator

* better typing and proper propogation to use more explicit cases

* fix

* refactor to fn and allow for class and fn

* add regression test

* fix all models

---------

Co-authored-by: vasqu <antonprogamer@gmail.com>
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.

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

4 participants