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

加载8bit量化/离线量化模型报错:RuntimeError: probability tensor contains either inf, nan or element < 0 #48

Closed
ywancit opened this issue Sep 7, 2023 · 8 comments

Comments

@ywancit
Copy link

ywancit commented Sep 7, 2023

背景:可以正常使用无量化模型。保存8bit量化模型过程无报错。按照官方文档中加载8bit量化/离线量化模型报错:RuntimeError: probability tensor contains either inf, nan or element < 0

代码如下:
model = AutoModelForCausalLM.from_pretrained(r".\Baichuan2-13B-Chat",
load_in_8bit=True, device_map="auto", trust_remote_code=True)
model.save_pretrained(r'.\8bit')
model = AutoModelForCausalLM.from_pretrained(r'.\8bit', device_map="auto", trust_remote_code=True)
model.generation_config = GenerationConfig.from_pretrained(r".\Baichuan2-13B-Chat")
tokenizer = AutoTokenizer.from_pretrained(r".\Baichuan2-13B-Chat",
use_fast=False, trust_remote_code=True)

messages = []
messages.append({"role": "user", "content": "解释一下“温故而知新”"})
response = model.chat(tokenizer, messages)
print(response)

报错如下:
in GenerationMixin.sample(self, input_ids, logits_processor, stopping_criteria, logits_warper, max_length, pad_token_id, eos_token_id, output_attentions, output_hidden_states, output_scores, return_dict_in_generate, synced_gpus, streamer, **model_kwargs)
2676 # sample
2677 probs = nn.functional.softmax(next_token_scores, dim=-1)
-> 2678 next_tokens = torch.multinomial(probs, num_samples=1).squeeze(1)
2680 # finished sentences should have their next token be a padding token
2681 if eos_token_id is not None:

RuntimeError: probability tensor contains either inf, nan or element < 0

@bihui9968
Copy link

我也遇到了

@jameswu2014
Copy link
Contributor

是最新的代码吗?

@ywancit
Copy link
Author

ywancit commented Sep 7, 2023

是最新的代码吗?

是的,4小时之前刚clone的模型文件和repo。

@jameswu2014
Copy link
Contributor

我这边用你发的代码跑了一下,是正常的。

@jameswu2014
Copy link
Contributor

你检查一下是不是哪些改了?

@ldisgod
Copy link

ldisgod commented Oct 7, 2023

解决了么?

@Dori-Nilou
Copy link

请问解决了吗

@ldisgod
Copy link

ldisgod commented Oct 11, 2023 via email

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

6 participants