Coder Social home page Coder Social logo

Comments (1)

Charon-HN avatar Charon-HN commented on July 21, 2024

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()

from med-chatglm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.