Skip to content

Fix vision config num_heads key in Qwen VL tiny model scripts and revert torch pin#5792

Merged
albertvillanova merged 3 commits into
huggingface:mainfrom
matdou:fix/qwen-vl-vision-config-num-heads
May 20, 2026
Merged

Fix vision config num_heads key in Qwen VL tiny model scripts and revert torch pin#5792
albertvillanova merged 3 commits into
huggingface:mainfrom
matdou:fix/qwen-vl-vision-config-num-heads

Conversation

@matdou

@matdou matdou commented May 19, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5768
Reverts #5769

The three Qwen VL tiny model generation scripts were passing num_attention_heads in vision_config, but the vision config class (Qwen2_5_VLVisionConfig, Qwen2VLVisionConfig, Qwen3VLVisionConfig) expects num_heads. The wrong key is silently ignored, num_heads stays at its default of 16, which with hidden_size=16 gives head_dim=1 and rotary_dim=0. PyTorch's SDPA then returns all-zeros for the attention output, causing zero gradients on all visual encoder parameters.

The torch pin added in #5769 is not needed.

Note: a maintainer with write access to trl-internal-testing on the Hub will need to rerun the generation scripts to upload the fixed tiny models before CI passes.

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? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

AI writing disclosure

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

Who can review?

@albertvillanova since you opened #5768 and #5769.


Note

Medium Risk
Medium risk because it changes how Qwen VL tiny test models are generated (affecting CI artifacts) and removes a previously-added torch version constraint that could re-expose version-specific failures.

Overview
Fixes the Qwen VL tiny-model generation scripts to pass the correct vision-config field (num_heads instead of num_attention_heads) for Qwen2-VL, Qwen2.5-VL, and Qwen3-VL, ensuring the intended attention head count is used during tiny model creation.

Also removes the temporary torch<2.12.0 dev-dependency pin from pyproject.toml.

Reviewed by Cursor Bugbot for commit 0365e1e. Bugbot is set up for automated code reviews on this repo. Configure here.

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

@albertvillanova

Copy link
Copy Markdown
Member

I have regenerated the tiny models and run the CI tests using the new tiny model PRs.

Once CI is green, I will merge the tiny model PRs and revert my last commit.

@albertvillanova albertvillanova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome! Thanks for your great investigation!

The CI is green with the new tiny models: https://github.com/huggingface/trl/actions/runs/26144698369?pr=5792

I have merged the tiny model PRs and reverted my last commit.

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.

CI fails: AssertionError: Param model.visual.blocks.0.norm1.weight is not updated

3 participants