[GH-ISSUE #35] Finetune with deepspeed: type mismatch #33

Open
opened 2026-10-26 21:01:54 +00:00 by bsakaguchi · 3 comments
Owner

Originally created by @YeZiyi1998 on GitHub (Jun 7, 2024).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-MoE/issues/35

I encountered an issue while finetune with the officially released code using the DeepSpeed. Here is the detailed error message:

File "/lib/python3.11/site-packages/deepspeed/runtime/zero/linear.py", line 57, in forward
output = input.matmul(weight.t())
RuntimeError: expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16

It appears that the matmul operation expects the two input tensors to have the same dtype. However, in my case, one of the tensors is of dtype float and the other is of dtype BFloat16.

I am not sure if this is a bug in the DeepSpeed library or an issue with my usage. I would appreciate any assistance in resolving this issue.

Originally created by @YeZiyi1998 on GitHub (Jun 7, 2024). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-MoE/issues/35 I encountered an issue while finetune with the officially released code using the DeepSpeed. Here is the detailed error message: ``` File "/lib/python3.11/site-packages/deepspeed/runtime/zero/linear.py", line 57, in forward output = input.matmul(weight.t()) RuntimeError: expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16 ``` It appears that the matmul operation expects the two input tensors to have the same dtype. However, in my case, one of the tensors is of dtype float and the other is of dtype BFloat16. I am not sure if this is a bug in the DeepSpeed library or an issue with my usage. I would appreciate any assistance in resolving this issue.
Author
Owner

@lihaoling commented on GitHub (Jun 18, 2024):

same question

<!-- gh-comment-id:2175469825 --> @lihaoling commented on GitHub (Jun 18, 2024): same question
Author
Owner

@JensenDong commented on GitHub (Jun 25, 2024):

same + 1

<!-- gh-comment-id:2187829464 --> @JensenDong commented on GitHub (Jun 25, 2024): same + 1
Author
Owner

@xidongyuandong commented on GitHub (Jul 23, 2024):

I encountered the same problem, and here's how I solved it. modify lines 425 and 428 in the modelling_deepseek.py file and remove torch.float32, such as the following code

        logits = F.linear(
            hidden_states, self.weight, None
        )
      if self.scoring_func == "softmax":
            scores = logits.softmax(dim=-1)

I encountered an issue while finetune with the officially released code using the DeepSpeed. Here is the detailed error message:

File "/lib/python3.11/site-packages/deepspeed/runtime/zero/linear.py", line 57, in forward
output = input.matmul(weight.t())
RuntimeError: expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16

It appears that the matmul operation expects the two input tensors to have the same dtype. However, in my case, one of the tensors is of dtype float and the other is of dtype BFloat16.

I am not sure if this is a bug in the DeepSpeed library or an issue with my usage. I would appreciate any assistance in resolving this issue.

<!-- gh-comment-id:2244115100 --> @xidongyuandong commented on GitHub (Jul 23, 2024): I encountered the same problem, and here's how I solved it. modify lines 425 and 428 in the modelling_deepseek.py file and remove torch.float32, such as the following code ``` logits = F.linear( hidden_states, self.weight, None ) if self.scoring_func == "softmax": scores = logits.softmax(dim=-1) ``` > I encountered an issue while finetune with the officially released code using the DeepSpeed. Here is the detailed error message: > > ``` > File "/lib/python3.11/site-packages/deepspeed/runtime/zero/linear.py", line 57, in forward > output = input.matmul(weight.t()) > RuntimeError: expected mat1 and mat2 to have the same dtype, but got: float != c10::BFloat16 > ``` > > It appears that the matmul operation expects the two input tensors to have the same dtype. However, in my case, one of the tensors is of dtype float and the other is of dtype BFloat16. > > I am not sure if this is a bug in the DeepSpeed library or an issue with my usage. I would appreciate any assistance in resolving this issue.
Sign in to join this conversation.
No labels
pull-request
WIP
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-MoE#33
No description provided.