Skip to content

fix(qwen3_moe): correct return type annotation on Qwen3MoeSparseMoeBlock.forward#45352

Merged
Rocketknight1 merged 5 commits intohuggingface:mainfrom
RudrenduPaul:fix/qwen3moe-return-type-annotation
Apr 13, 2026
Merged

fix(qwen3_moe): correct return type annotation on Qwen3MoeSparseMoeBlock.forward#45352
Rocketknight1 merged 5 commits intohuggingface:mainfrom
RudrenduPaul:fix/qwen3moe-return-type-annotation

Conversation

@RudrenduPaul
Copy link
Copy Markdown
Contributor

What does this PR do?

Corrects an incorrect return type annotation on Qwen3MoeSparseMoeBlock.forward.

The method is annotated as returning tuple[torch.Tensor, torch.Tensor] but actually returns a single reshaped torch.Tensor (see the return final_hidden_states.reshape(...) statement). This type mismatch was identified in issue #45208 and confirmed by maintainer @Rocketknight1.

Fixes #45208

Changes

  • src/transformers/models/qwen3_moe/modular_qwen3_moe.py: Fix return type annotation from tuple[torch.Tensor, torch.Tensor] to torch.Tensor
  • src/transformers/models/qwen3_moe/modeling_qwen3_moe.py: Same fix in the generated file (kept in sync with the modular file)

Tests

No functional change — annotation-only fix. Existing tests continue to pass.

This is not a duplicate of PR #45211 (which was opened and closed without review before the maintainer commented on the issue).

Note: This PR was developed with AI assistance (Claude Code). I have reviewed every line and understand the change.

@Rocketknight1
Copy link
Copy Markdown
Member

@RudrenduPaul can you run make fix-repo to clean up any modular/modeling issues and propagate the fix, then ping me for final review? Thank you!

@RudrenduPaul
Copy link
Copy Markdown
Contributor Author

Hi @Rocketknight1 — ran make fix-repo (using python3 utils/checkers.py directly since the python alias wasn't available). All the key consistency checks passed with no changes needed:

auto_mappings — OK
doc_toc — OK
copies — no # Copied from drift detected
modular_conversion — no generated-file divergence
dummies — OK
pipeline_typing — OK

(3 checks failed due to missing local packages — ruff, gitpython, setuptools — these are env setup issues on my machine, not repo inconsistencies.)

The branch is also up to date with main (the upstream sync from the 'Update branch' button is already included). Ready for your final review whenever you're free — thanks!

…rated vl_moe and omni_moe files

Built by Rudrendu Paul, developed with Claude Code
@RudrenduPaul
Copy link
Copy Markdown
Contributor Author

@Rocketknight1 — follow-up on the check_repository_consistency failure.

The CI diff showed the modular conversion of Qwen3VLMoeTextSparseMoeBlock and Qwen3OmniMoeThinkerTextSparseMoeBlock (both inherit from Qwen3MoeSparseMoeBlock via pass) would generate -> torch.Tensor, while the actual generated modeling files still had -> tuple[torch.Tensor, torch.Tensor].

Just pushed a second commit propagating the fix to:

  • modeling_qwen3_vl_moe.pyQwen3VLMoeTextSparseMoeBlock.forward
  • modeling_qwen3_omni_moe.pyQwen3OmniMoeThinkerTextSparseMoeBlock.forward

(Left Qwen3OmniMoeTalkerTextSparseMoeBlock untouched — it inherits from Qwen2MoeSparseMoeBlock, not Qwen3.)

Should be ready for final review now!

@github-actions
Copy link
Copy Markdown
Contributor

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

run-slow: qwen3_moe, qwen3_omni_moe, qwen3_vl_moe

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yep, LGTM now!

@Rocketknight1 Rocketknight1 enabled auto-merge April 13, 2026 13:50
@Rocketknight1 Rocketknight1 added this pull request to the merge queue Apr 13, 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 357f414 Apr 13, 2026
21 checks passed
sirzechs66 pushed a commit to sirzechs66/transformers that referenced this pull request Apr 18, 2026
…ock.forward (huggingface#45352)

* fix(qwen3_moe): correct return type annotation on Qwen3MoeSparseMoeBlock.forward

* fix: propagate Qwen3MoeSparseMoeBlock forward return type fix to generated vl_moe and omni_moe files

Built by Rudrendu Paul, developed with Claude Code

---------

Co-authored-by: Rudrendu <RudrenduPaul@users.noreply.github.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.

[Qwen3MoE] Potentially a bug on Qwen3MoeSparseMoeBlock

3 participants