Skip to content

[Bug] The size of tensor a (828) must match the size of tensor b (824) at non-singleton dimension 1 #4081

Closed

Description

@dipta007
  1. Did you update? pip install --upgrade unsloth unsloth_zoo - yes
  2. Colab or Kaggle or local / cloud - local
  3. Number GPUs used, use nvidia-smi - 1 L40s
  4. Which notebook? Please link!
  5. Which Unsloth version, TRL version, transformers version, PyTorch version?
Name: unsloth                                                                                                                                                                                                                               
Version: 2026.2.1

Name: trl                                                                                                                                                                                                                                   
Version: 0.24.0 

Name: transformers
Version: 4.57.6

Name: torch
Version: 2.9.
  1. Which trainer? SFTTrainer, GRPOTrainer etc
    GRPOTrainer

🦥 You can also ask via our Reddit page: https://reddit.com/r/unsloth/

Unsloth: Will smartly offload gradients to save VRAM!
Traceback (most recent call last):
  File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/decomposer/unsloth/grpo_lora.py", line 202, in <module>
    main(args)
  File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/decomposer/unsloth/grpo_lora.py", line 170, in main
    trainer.train(resume_from_checkpoint=resume_from_checkpoint)
  File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 66, in wrapper
    output = f(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/.venv/lib/python3.12/site-packages/transformers/trainer.py", line 2325, in train
    return inner_training_loop(
           ^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 330, in _fast_inner_training_loop
  File "<string>", line 40, in _unsloth_training_step
  File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 3698, in compute_loss
    low_clip = masked_batch_mean(is_low_clipped.float())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 3687, in masked_batch_mean
    return (x * completion_mask).sum() / completion_token_count
            ~~^~~~~~~~~~~~~~~~~
RuntimeError: The size of tensor a (828) must match the size of tensor b (824) at non-singleton dimension 1
[rank0]: Traceback (most recent call last):
[rank0]:   File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/decomposer/unsloth/grpo_lora.py", line 202, in <module>
[rank0]:     main(args)
[rank0]:   File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/decomposer/unsloth/grpo_lora.py", line 170, in main
[rank0]:     trainer.train(resume_from_checkpoint=resume_from_checkpoint)
[rank0]:   File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 66, in wrapper
[rank0]:     output = f(self, *args, **kwargs)
[rank0]:              ^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/.venv/lib/python3.12/site-packages/transformers/trainer.py", line 2325, in train
[rank0]:     return inner_training_loop(
[rank0]:            ^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "<string>", line 330, in _fast_inner_training_loop
[rank0]:   File "<string>", line 40, in _unsloth_training_step
[rank0]:   File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 3698, in compute_loss
[rank0]:     low_clip = masked_batch_mean(is_low_clipped.float())
[rank0]:                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/umbc/ada/ferraro/users/sroydip1/DecomposeRL/unsloth_compiled_cache/UnslothGRPOTrainer.py", line 3687, in masked_batch_mean
[rank0]:     return (x * completion_mask).sum() / completion_token_count
[rank0]:             ~~^~~~~~~~~~~~~~~~~
[rank0]: RuntimeError: The size of tensor a (828) must match the size of tensor b (824) at non-singleton dimension 1

Activity

  1. changed the title [-][Bug] Please fill in your issue title here.[/-] [+][Bug] The size of tensor a (828) must match the size of tensor b (824) at non-singleton dimension 1[/+] on Feb 20, 2026
  2. GhostWalkers commented on Feb 22, 2026

    @GhostWalkers

    I have the same problem

  3. GhostWalkers commented on Feb 22, 2026

    @GhostWalkers

    I can confirm that the issue only occurs in the current version; everything is fine in version 2026.1.4.

    Regarding @darshjme-codes comment, I think this is a solution to the symptom, not the problem.

  4. Datta0 commented on Feb 23, 2026

    @Datta0
    Contributor

    @pluesclues something with masking. Can you please check

  5. ingambe commented on Mar 2, 2026

    @ingambe

    Same issue from my side

  6. cmunley1 commented on Mar 4, 2026

    @cmunley1

    same here

  7. Datta0 commented on Mar 4, 2026

    @Datta0
    Contributor

    Hey guys, the PR linked above #4140 should fix it. Please wait till the changes are merged :)

  8. danielhanchen commented on Mar 8, 2026

    @danielhanchen
    Member

    Fixed by unslothai/unsloth-zoo#528 and #4140

    We're going to do a Pypi release, so to update Unsloth, please do pip install --upgrade --force-reinstall --no-deps --no-cache-dir unsloth unsloth_zoo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions