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

apply_rotary_pos_emb_flashatt_fp32() takes 2 positional arguments but 4 were given #45

Open
black-tea01 opened this issue Feb 17, 2025 · 3 comments

Comments

@black-tea01
Copy link

black-tea01 commented Feb 17, 2025

I follow the install pip install git+https://github.com/huggingface/transformers accelerate and the pip list:
transformers==4.49.0.dev0
tokenizers==0.21.0
accelerate== 0.34.0
flash-attn==2.5.8

apply_rotary_pos_emb_flashatt_fp32 question from training

File ""/mnt/beegfs_lfs3/training/riderapi/al_team/qian.ye/miniconda3/envs/qwen2/lib/python3.10/site-packages/torch/nn/modules/module.py"", line 1844, in _call_impl"
"1739588804.641397953","[rank7]:     return inner()"
"1739588804.641407251","[rank7]:   File ""/mnt/beegfs_lfs3/training/riderapi/al_team/qian.ye/miniconda3/envs/qwen2/lib/python3.10/site-packages/torch/nn/modules/module.py"", line 1790, in inner"
"1739588804.641416549","[rank7]:     result = forward_call(*args, **kwargs)"
"1739588804.641424894","[rank7]:   File ""/mnt/beegfs_lfs3/training/riderapi/al_team/qian.ye/miniconda3/envs/qwen2/lib/python3.10/site-packages/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py"", line 201, in forward"
"1739588804.641432762","[rank7]:     q, k = apply_rotary_pos_emb_flashatt(q.unsqueeze(0), k.unsqueeze(0), cos, sin)"
"1739588804.641441583","[rank7]: TypeError: apply_rotary_pos_emb_flashatt_fp32() takes 2 positional arguments but 4 were given"
@2U1
Copy link
Owner

2U1 commented Feb 17, 2025

It's a bit odd, I don't get it how the arguments are passed. I can't reproduce the issue.
Can you show your dataset example and the scripts you are running?

@black-tea01
Copy link
Author

I have solved the question, the lasted transformers have update the cos/sin embeding and the code
def apply_rotary_pos_emb_flashatt_fp32(tensor: torch.Tensor, freqs: torch.Tensor) -> torch.Tensor: tensor_ = tensor.float() cos = freqs.cos().float() sin = freqs.sin().float() output = apply_rotary_emb(tensor_, cos, sin).type_as(tensor) return output
need to be replace to be
def apply_rotary_pos_emb_flashatt_fp32( q: torch.Tensor, k: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor ) -> Tuple[torch.Tensor, torch.Tensor]: cos = cos.chunk(2, dim=-1)[0].contiguous() sin = sin.chunk(2, dim=-1)[0].contiguous() cos = cos.float() sin = sin.float() q_embed = apply_rotary_emb(q.float(), cos, sin).type_as(q) k_embed = apply_rotary_emb(k.float(), cos, sin).type_as(k) return q_embed, k_embed
for the lasted transformers.

@2U1
Copy link
Owner

2U1 commented Feb 17, 2025

Oh I see, it was updated again. I'll fix the README for now until it is relesead.
Thanks for letting me know!

pip install git+https://github.com/huggingface/transformers.git@9d2056f12b66e64978f78a2dcb023f65b2be2108
Maybe this version should work with the code.

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

2 participants