ValueError: too many values to unpack (expected 2)怎么解决?
ValueError Traceback (most recent call last)
Cell In[9], line 25
23 gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
24 with torch.no_grad():
---> 25 outputs = model.generate(**inputs, **gen_kwargs)
26 outputs = outputs[:, inputs['input_ids'].shape[1]:]
27 print(tokenizer.decode(outputs[0], skip_special_tokens=True))
ValueError: too many values to unpack (expected 2)
ps:用的是官方demo
加载模型
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained(model_dir,trust_remote_code=True)
query = "你好"
inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
add_generation_prompt=True,
tokenize=True,
return_tensors="pt",
return_dict=True
)
inputs = inputs.to(device)
model = AutoModelForCausalLM.from_pretrained(
model_dir,
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True
).to(device).eval()
gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
with torch.no_grad():
outputs = model.generate(**inputs, **gen_kwargs)
outputs = outputs[:, inputs['input_ids'].shape[1]:]
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
pip install transformers==4.40.2
pip install transformers==4.42.4
using with latest code
你可以看我的pull request,把model文件改一下就行,新的transformers多了一个参数
https://huggingface.co/THUDM/glm-4-9b-chat/discussions/58
现在又少了一个参数,还得再改,我下周统一改成4.44以上
pip install transformers==4.40.2
点赞,用这个版本的可以正常运行