Text Generation
Transformers
PyTorch
English
llama
Inference Endpoints
text-generation-inference

RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'

#29
by shubhamagarwal92 - opened

Hi, I get this runtime error when I try without flash attention, ie. if I don't use trust_remote_code=True

  File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/transformers/models/llama/modeling_llama.py", line 305, in forward
    query_states = self.q_proj(hidden_states)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/home/miniconda/envs/autoreview/lib/python3.11/site-packages/torch/nn/modules/linear.py", line 114, in forward
    return F.linear(input, self.weight, self.bias)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'
Together org

Hi @shubhamagarwal92 , this is likely because you're using float16 data type. Can you try to change it to float32 and see if the error persists?

i have used float32 the error persists

Together org

Hi @Anash , can you provide the code you use that results in this error?

Hi @Anash , can you provide the code you use that results in this error?

Hi mauriceweber, I have the same question, my code is below:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_path = r'/home/model/LLaMA-2-7B-32K'
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, torch_dtype=torch.float16)
input_context = "Your text here"
input_ids = tokenizer.encode(input_context, return_tensors="pt")
output = model.generate(input_ids, max_new_tokens=6000, temperature=0.7)
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
output_text_path=r'/qa/txt/split-cat-00/test.txt'
with open(output_text_path, 'w', encoding='utf-8') as output_file:
output_file.write(output_text)
print('success')

RuntimeError: "addmm_impl_cpu_" not implemented for 'Half'

if I change the float16 to float32, there is new error:
File "", line 21, in rotary_kernel
KeyError: ('2-.-0-.-0-1e8410f206c822547fb50e2ea86e45a6-d6252949da17ceb5f3a278a70250af1
3-1af5134066c618146d2cd009138944a0-9b9585c66493f30389231e55f159817f-3498c340fd4b6ee780
5fd54b882a04f5-e1f133f98d04093da2078dfc51c36b72-b26258bf01f839199e39d64851821f26-d7c06
e3b46e708006c15224aac7a1378-f585402118c8a136948ce0a49cfe122c', (torch.float32, torch.f
loat32, torch.float32, torch.float32, None, 'i32', 'i32', 'i32', 'i32', 'i32', 'i32',
'i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32'), (128, False, False, False, Fa
lse, 4), (True, True, True, True, (False,), (True, False), (False, False), (True, Fals
e), (True, False), (False, False), (False, False), (True, False), (True, False), (True
, False), (False, True), (True, False), (True, False), (True, False), (False, True)))

Sign up or log in to comment