getting a error when running GPTNeoXForCausalLM from Transformers Library: NameError: name 'init_empty_weights' is not defined

huangapple go评论58阅读模式
英文:

getting a error when running GPTNeoXForCausalLM from Transformers Library: NameError: name 'init_empty_weights' is not defined

问题

I'm trying to run OpenAssistant's pythia-12b model but I'm getting the following error:

NameError: name 'init_empty_weights' is not defined
I have Accelerate installed, and I'm running Transformers version 4.25.1

from transformers import AutoModelForCausalLM, GPTNeoXForCausalLM, AutoTokenizer
Model = "OpenAssistant/oasst-sft-1-pythia-12b"

tokenizer = AutoTokenizer.from_pretrained(Model, cache_dir='models_hf')
model = GPTNeoXForCausalLM.from_pretrained(Model, device_map="auto", load_in_8bit=True, cache_dir='models_hf', low_cpu_mem_usage=True)

message = "Hello, How are you?"
inp = "<|prompter|>"+message+"<|endoftext|><|assistant|>"
data = tokenizer([inp], return_tensors="pt")
data = {k: v.to(model.device) for k, v in data.items() if k in ("input_ids", "attention_mask")}
outputs = model.generate(**data)
print(tokenizer.decode(outputs[0]))
英文:

I'm trying to run OpenAssistant's pythia-12b model but I'm getting the following error:

NameError: name &#39;init_empty_weights&#39; is not defined

I have Accelerate installed, and I'm running Transformers version 4.25.1

from transformers import AutoModelForCausalLM, GPTNeoXForCausalLM, AutoTokenizer
Model = &quot;OpenAssistant/oasst-sft-1-pythia-12b&quot;
    
tokenizer = AutoTokenizer.from_pretrained(Model, cache_dir=&#39;models_hf&#39;)
model = GPTNeoXForCausalLM.from_pretrained(Model, device_map=&quot;auto&quot;, load_in_8bit=True, cache_dir=&#39;models_hf&#39;,low_cpu_mem_usage=True)
    
message = &quot;Hello, How are you?&quot;
inp = &quot;&lt;|prompter|&gt;&quot;+message+&quot;&lt;|endoftext|&gt;&lt;|assistant|&gt;&quot;
data = tokenizer([inp], return_tensors=&quot;pt&quot;)
data = {k: v.to(model.device) for k, v in data.items() if k in (&quot;input_ids&quot;, &quot;attention_mask&quot;)}
outputs = model.generate(**data)
print(tokenizer.decode(outputs[0]))

答案1

得分: 2

在我的情况下,安装加速包并重新启动运行时就足够了。相同的问题也在这里讨论过(链接:https://github.com/NielsRogge/Transformers-Tutorials/issues/131)。

英文:

In my case, installing accelerate package and re-starting the runtime was enough.
The same issue was also discussed here.

huangapple
  • 本文由 发表于 2023年4月20日 08:09:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定