CI fails: AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
CI fails: https://github.com/huggingface/trl/actions/runs/25825653691/job/75877994889
AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
FAILED tests/test_sft_trainer.py::TestSFTTrainer::test_train_chunked_nll_loss_vlm[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
FAILED tests/test_sft_trainer.py::TestSFTTrainer::test_train_chunked_nll_loss_vlm[trl-internal-testing/tiny-Qwen3VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
FAILED tests/test_dpo_trainer.py::TestDPOTrainer::test_train_vlm[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f0b6a8f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f0b6a8f6b20> = torch.equal
FAILED tests/test_dpo_trainer.py::TestDPOTrainer::test_train_vlm[trl-internal-testing/tiny-Qwen3VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f0b6a8f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f0b6a8f6b20> = torch.equal
FAILED tests/test_rloo_trainer.py::TestRLOOTrainer::test_train_vlm_multi_image[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Parameter model.visual.blocks.0.norm1.weight has not changed.
assert not True
+ where True = <built-in method equal of type object at 0x7f2cda4f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2cda4f6b20> = torch.equal
FAILED tests/test_dpo_trainer.py::TestDPOTrainer::test_train_vlm_multi_image[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f0b6a8f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f0b6a8f6b20> = torch.equal
FAILED tests/test_sft_trainer.py::TestSFTTrainer::test_train_vlm[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
FAILED tests/test_grpo_trainer.py::TestGRPOTrainer::test_train_vlm_multi_image[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Parameter model.visual.blocks.0.norm1.weight has not changed.
assert not True
+ where True = <built-in method equal of type object at 0x7fb7186f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7fb7186f6b20> = torch.equal
FAILED tests/test_sft_trainer.py::TestSFTTrainer::test_train_vlm[trl-internal-testing/tiny-Qwen3VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
FAILED tests/test_sft_trainer.py::TestSFTTrainer::test_train_vlm_multi_image[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
FAILED tests/test_sft_trainer.py::TestSFTTrainer::test_train_vlm_prompt_completion[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] - AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
assert not True
+ where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
+ where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
= 11 failed
Stacktrace:
_ TestSFTTrainer.test_train_vlm_prompt_completion[trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration] _
[gw3] linux -- Python 3.10.20 /__w/trl/trl/.venv/bin/python3
self = <tests.test_sft_trainer.TestSFTTrainer object at 0x7f2c8ae53610>
model_id = 'trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration'
@pytest.mark.parametrize(
"model_id",
[
"trl-internal-testing/tiny-Qwen2_5_VLForConditionalGeneration",
# Special case for Gemma, as it uses token_type_ids, and we need to ensure they are properly in the collator:
"trl-internal-testing/tiny-Gemma3ForConditionalGeneration",
pytest.param(
"trl-internal-testing/tiny-Gemma4ForConditionalGeneration",
marks=pytest.mark.skipif(
Version(transformers.__version__) < Version("5.5.0"),
reason="Gemma4 models were introduced in transformers-5.5.0",
),
),
],
)
@require_vision
def test_train_vlm_prompt_completion(self, model_id):
dataset = load_dataset("trl-internal-testing/zen-image", "conversational_prompt_completion", split="train")
training_args = SFTConfig(
output_dir=self.tmp_dir,
per_device_train_batch_size=1, # VLM training is memory intensive, reduce batch size to avoid OOM
learning_rate=0.1, # use higher lr because gradients are tiny and default lr can stall updates
max_length=None, # for VLMs, truncating can remove image tokens, leading to errors
report_to="none",
)
trainer = SFTTrainer(
model=model_id,
args=training_args,
train_dataset=dataset,
)
previous_trainable_params = {n: param.clone() for n, param in trainer.model.named_parameters()}
trainer.train()
assert trainer.state.log_history[-1]["train_loss"] is not None
# Check that the params have changed
for n, param in previous_trainable_params.items():
new_param = trainer.model.get_parameter(n)
> assert not torch.equal(param, new_param), f"Param {n} is not updated"
E AssertionError: Param model.visual.blocks.0.norm1.weight is not updated
E assert not True
E + where True = <built-in method equal of type object at 0x7f2d5d2f6b20>(tensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', grad_fn=<CloneBackward0>), Parameter containing:\ntensor([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n device='cuda:0', requires_grad=True))
E + where <built-in method equal of type object at 0x7f2d5d2f6b20> = torch.equal
tests/test_sft_trainer.py:1755: AssertionError
After investigation, it seems the issue appeared after the release of torch-2.12.0 on May 13, 2026:
- https://pypi.org/project/torch/2.12.0/
- https://github.com/pytorch/pytorch/releases/tag/v2.12.0
I am proposing a temporary hotfix to pin torch < 2.12.0 until we find the root cause.
Hey, did some digging on this, it's not a torch 2.12.0 regression, the pin isn't needed.
The actual cause is in scripts/generate_tiny_models/for_conditional_generation/qwen2_5_vl_for_conditional_generation.py. The vision_config dict uses num_attention_heads as the key:
vision_config = {
"hidden_size": 16,
"num_attention_heads": 4, # wrong key
...
}
But Qwen2_5_VLVisionConfig expects num_heads, not num_attention_heads. The key gets silently absorbed, and num_heads stays at its default of 16. With hidden_size=16 that gives:
head_dim = hidden_size // num_heads = 16 // 16 = 1
rotary_dim = head_dim // 2 = 1 // 2 = 0
With rotary_dim=0, Qwen2_5_VisionRotaryEmbedding produces embeddings of shape (seq, 0). The query tensor ends up with head_dim=0 so q.numel() == 0. PyTorch's SDPA has an early-exit for empty tensors that returns all-zeros, and zero attention output means zero gradients on everything upstream of self.proj, including norm1.weight.
That also explains why proj.bias still gets a gradient (bias grad = sum(grad_output), independent of input) while proj.weight and norm1.weight don't (weight grad = grad_output^T x input, input is zero).
I checked the attention.cpp commit history and torch 2.12.0 only touched MPS, cuDNN and XPU backends for SDPA. The SDPA early-exit predates 2.12.0, so the timing is just a coincidence.
Fix is in qwen2_5_vl_for_conditional_generation.py:
vision_config = {
"hidden_size": 16,
- "num_attention_heads": 4,
+ "num_heads": 4, # correct key for Qwen2_5_VLVisionConfig
...
}
head_dim=4, rotary_dim=2, gradients flow. The torch pin in #5769 can be reverted once the tiny model is regenerated.
Same bug is in qwen2_vl_for_conditional_generation.py and
qwen3_vl_for_conditional_generation.py, both also use num_attention_heads
in vision_config when the correct key is num_heads.
I'll open a PR to fix all three scripts and revert the torch pin.
Thanks a lot for your investigation: it was in my TODO list.
Indeed, the torch pin was only intended as a temporary hotfix to quickly restore CI stability while the actual underlying issue was investigated and fixed properly. That is also why I intentionally left this issue open after merging the hotfix PR.
I'm now reviewing and testing the PR you opened to address the real cause in the tiny model generation scripts and revert the pin.