[Modular Converter] Strip @use_kernelized_func(fn) when fn lacks @use_kernel_func_from_hub#46437
Open
kpal002 wants to merge 2 commits into
Open
Conversation
…_kernel_func_from_hub replace_class_node() falls back to the parent class decorators when a modular subclass declares none. For Qwen3Next and Qwen3.5 this causes @use_kernelized_func( apply_rotary_pos_emb) to be inherited from Qwen3MoeAttention even though the generated file defines apply_rotary_pos_emb as a partial-RoPE variant without @use_kernel_func_from_hub. When kernelize() runs, attach_hidden_kernels() tries to register that plain function as an nn.Module and raises ValueError. Fix: add strip_orphaned_kernelized_func_decorators(), called in create_modules() before get_needed_imports(). It drops @use_kernelized_func(fn) from any class in the generated body when fn is defined locally without @use_kernel_func_from_hub. Placing it before get_needed_imports lets the existing scope analysis also remove the now-unused use_kernelized_func import automatically. Regression tests: huggingface#46435 Regen of affected model files: follow-up PR Fixes huggingface#46399
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Fixes the root cause of the
use_kernels=Truecrash onQwen3NextandQwen3.5(issue #46399).Root cause
replace_class_node()falls back to the parent class decorators when a modular subclass declares none. ForQwen3NextAttention(Qwen3MoeAttention)andQwen3_5Attention, this means@use_kernelized_func(apply_rotary_pos_emb)is inherited fromQwen3MoeAttention— but the generated file definesapply_rotary_pos_embas a partial-RoPE variant without@use_kernel_func_from_hub. Whenkernelize()runs,attach_hidden_kernels()tries to register that plain function as annn.Moduleand raises:Fix
Add
strip_orphaned_kernelized_func_decorators(), called increate_modules()beforeget_needed_imports().For each generated file's
bodydict it:@use_kernel_func_from_hub@use_kernelized_func(fn)wherefnis defined locally without@use_kernel_func_from_hub, drops that decoratorCalling it before
get_needed_importsmeans the existing LibCST scope analysis also removes the now-unuseduse_kernelized_funcimport automatically — no separate cleanup needed.What is NOT changed
modeling_qwen3_next.pyandmodeling_qwen3_5.py(using this fixed converter) is in a follow-up PR to keep the diff reviewable.PR series for #46399
modeling_qwen3_next.pyandmodeling_qwen3_5.pycc @vasqu @ArthurZucker @MekkCyber @drbh
Before submitting