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: "LayerNormKernelImpl" not implemented for 'Half' #56

Open
888yyh opened this issue Oct 30, 2023 · 1 comment
Open

RuntimeError: "LayerNormKernelImpl" not implemented for 'Half' #56

888yyh opened this issue Oct 30, 2023 · 1 comment

Comments

@888yyh
Copy link

888yyh commented Oct 30, 2023

i can only use gpu,and ran the code below

import torch
from transformers import AutoTokenizer, AutoModel
from modeling_chatglm import ChatGLMForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained(
"./model", trust_remote_code=True)

model = ChatGLMForConditionalGeneration.from_pretrained(
"./model").half()

while True:
a = input("请输入您的问题:(输入q以退出)")
if a.strip() == 'q':

    exit()
response, history = model.chat(tokenizer, "问题:" + a.strip() + '\n答案:', max_length=256, history=[])
print("回答:", response)

errors:RuntimeError: "LayerNormKernelImpl" not implemented for 'Half',however i use model = ChatGLMForConditionalGeneration.from_pretrained(
"./model",torch_type=torch.float32),error "RuntimeError: mixed dtype (CPU): expect parameter to have scalar type of bFloat "
if i use ChatGLMForConditionalGeneration.from_pretrained(
"./model",torch_type=torch.Bfloat) errors"RuntimeError: mixed dtype (CPU): expect parameter to have scalar type of Float"
how can i run the code correctly?

@Charon-HN
Copy link

Charon-HN commented Dec 24, 2023

i can only use gpu,and ran the code below

import torch from transformers import AutoTokenizer, AutoModel from modeling_chatglm import ChatGLMForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained( "./model", trust_remote_code=True)

model = ChatGLMForConditionalGeneration.from_pretrained( "./model").half()

while True: a = input("请输入您的问题:(输入q以退出)") if a.strip() == 'q':

    exit()
response, history = model.chat(tokenizer, "问题:" + a.strip() + '\n答案:', max_length=256, history=[])
print("回答:", response)

errors:RuntimeError: "LayerNormKernelImpl" not implemented for 'Half',however i use model = ChatGLMForConditionalGeneration.from_pretrained( "./model",torch_type=torch.float32),error "RuntimeError: mixed dtype (CPU): expect parameter to have scalar type of bFloat " if i use ChatGLMForConditionalGeneration.from_pretrained( "./model",torch_type=torch.Bfloat) errors"RuntimeError: mixed dtype (CPU): expect parameter to have scalar type of Float" how can i run the code correctly?

What a coincidence! I encoutered the same problem as you. I found a Blog that might be useful to you.

To summary, the reason for this problem should be that the model is not placed on the GPU. Because the model needs to be half() and CPU can't do it, only GPU can.

So you can try to add .cuda(), as shown below

model = ChatGLMForConditionalGeneration.from_pretrained(
"./model").half().cuda()

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