Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: The size of tensor a (2048) must match the size of tensor b (4241) at non-singleton dimension 1 #1717

Open
azzedineA opened this issue Feb 15, 2025 · 11 comments

Comments

@azzedineA
Copy link

azzedineA commented Feb 15, 2025

I am getting this error even though the same code was running successfully. Any help, please?


RuntimeError Traceback (most recent call last)
in <cell line: 0>()

12 frames
/usr/local/lib/python3.11/dist-packages/unsloth/models/llama.py in LlamaModel_fast_forward(self, input_ids, causal_mask, attention_mask, position_ids, past_key_values, inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict, *args, **kwargs)
701 inputs_embeds.requires_grad_(False)
702 pass
--> 703 inputs_embeds *= attention_mask.unsqueeze(0).transpose(0, 1).transpose(1, 2)
704 if inputs_requires_grad: inputs_embeds.requires_grad_(True)
705 pass

RuntimeError: The size of tensor a (2048) must match the size of tensor b (4241) at non-singleton dimension 1

@SomeoneKong
Copy link

SomeoneKong commented Feb 16, 2025

+1

trl==0.15.0
unsloth==2025.2.12
unsloth_zoo==2025.2.5
triton==3.2.0

@YannickRuppenthal
Copy link

YannickRuppenthal commented Feb 16, 2025

Had a similar problem, but it turns out I had to increase max_seq_length in FastLanguageModel.from_pretrained(...)

@fyj3266098
Copy link

+1

@danielhanchen
Copy link
Contributor

Apologies is this for normal finetuning or DPO?

@danielhanchen
Copy link
Contributor

I'm assuming it's something to do with the max sequence length?

@SomeoneKong
Copy link

Apologies is this for normal finetuning or DPO?

GRPO

@janglichao
Copy link

I'm assuming it's something to do with the max sequence length?

+1, I also got same error,pls help
Name Version Build Channel
unsloth 2025.2.12 pypi_0 pypi
unsloth-zoo 2025.2.5 pypi_0 pypi

@delbyte
Copy link

delbyte commented Feb 17, 2025

I'm assuming it's something to do with the max sequence length?

Check if your input_ids and attention_mask align:

print("Input IDs shape:", input_ids.shape)
print("Attention Mask shape:", attention_mask.shape)

They should have the same first dimension, e.g., (batch_size, sequence_length).

@ZhangYuHao1
Copy link

+1, pls help

2 similar comments
@Damonzhl
Copy link

+1, pls help

@linyang-ant
Copy link

+1, pls help

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

No branches or pull requests

10 participants