从transformers 自动下载模型,response, history = model.chat(tokenizer, "你好", history=[])报错too many values to unpack (expected 2) #1301
Unanswered
LiuXingEmail
asked this question in
Q&A
Replies: 1 comment
-
pip install transformers==4.41.2,试一下requirements.txt中最低的transformers版本 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
kaggle上使用官方提供的代码从 transformers下载模型,调用 ChatGLM 生成对话,在response, history = model.chat(tokenizer, "你好", history=[])对话阶段出现以下错误
ValueError Traceback (most recent call last)
Cell In[6], line 5
3 model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True, device='cuda')
4 model = model.eval()
----> 5 response, history = model.chat(tokenizer, "你好", history=[])
6 print(response)
File /opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator..decorate_context(*args, **kwargs)
112 @functools.wraps(func)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)
File ~/.cache/huggingface/modules/transformers_modules/THUDM/chatglm3-6b/06c7c873c843814171c51330b69c2e2a68e05178/modeling_chatglm.py:1042, in ChatGLMForConditionalGeneration.chat(self, tokenizer, query, history, role, max_length, num_beams, do_sample, top_p, temperature, logits_processor, **kwargs)
1039 inputs = inputs.to(self.device)
1040 eos_token_id = [tokenizer.eos_token_id, tokenizer.get_command("<|user|>"),
1041 tokenizer.get_command("<|observation|>")]
-> 1042 outputs = self.generate(**inputs, **gen_kwargs, eos_token_id=eos_token_id)
1043 outputs = outputs.tolist()[0][len(inputs["input_ids"][0]):-1]
1044 response = tokenizer.decode(outputs)
File /opt/conda/lib/python3.10/site-packages/torch/utils/_contextlib.py:115, in context_decorator..decorate_context(*args, **kwargs)
112 @functools.wraps(func)
113 def decorate_context(*args, **kwargs):
114 with ctx_factory():
--> 115 return func(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/transformers/generation/utils.py:1914, in GenerationMixin.generate(self, inputs, generation_config, logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, assistant_model, streamer, negative_prompt_ids, negative_prompt_attention_mask, **kwargs)
1906 input_ids, model_kwargs = self._expand_inputs_for_generation(
1907 input_ids=input_ids,
1908 expand_size=generation_config.num_return_sequences,
1909 is_encoder_decoder=self.config.is_encoder_decoder,
1910 **model_kwargs,
1911 )
1913 # 13. run sample (it degenerates to greedy search when
generation_config.do_sample=False
)-> 1914 result = self._sample(
1915 input_ids,
1916 logits_processor=prepared_logits_processor,
1917 logits_warper=prepared_logits_warper,
1918 stopping_criteria=prepared_stopping_criteria,
1919 generation_config=generation_config,
1920 synced_gpus=synced_gpus,
1921 streamer=streamer,
1922 **model_kwargs,
1923 )
1925 elif generation_mode in (GenerationMode.BEAM_SAMPLE, GenerationMode.BEAM_SEARCH):
1926 # 11. prepare logits warper
1927 prepared_logits_warper = (
1928 self._get_logits_warper(generation_config, device=input_ids.device)
1929 if generation_config.do_sample
1930 else None
1931 )
File /opt/conda/lib/python3.10/site-packages/transformers/generation/utils.py:2651, in GenerationMixin._sample(self, input_ids, logits_processor, stopping_criteria, generation_config, synced_gpus, streamer, logits_warper, **model_kwargs)
2648 model_inputs = self.prepare_inputs_for_generation(input_ids, **model_kwargs)
2650 # forward pass to get next token
-> 2651 outputs = self(
2652 **model_inputs,
2653 return_dict=True,
2654 output_attentions=output_attentions,
2655 output_hidden_states=output_hidden_states,
2656 )
2658 if synced_gpus and this_peer_finished:
2659 continue # don't waste resources running the code we don't need
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File ~/.cache/huggingface/modules/transformers_modules/THUDM/chatglm3-6b/06c7c873c843814171c51330b69c2e2a68e05178/modeling_chatglm.py:941, in ChatGLMForConditionalGeneration.forward(self, input_ids, position_ids, attention_mask, past_key_values, inputs_embeds, labels, use_cache, output_attentions, output_hidden_states, return_dict, return_last_logit)
938 use_cache = use_cache if use_cache is not None else self.config.use_cache
939 return_dict = return_dict if return_dict is not None else self.config.use_return_dict
--> 941 transformer_outputs = self.transformer(
942 input_ids=input_ids,
943 position_ids=position_ids,
944 attention_mask=attention_mask,
945 past_key_values=past_key_values,
946 inputs_embeds=inputs_embeds,
947 use_cache=use_cache,
948 output_hidden_states=output_hidden_states,
949 return_dict=return_dict,
950 )
952 hidden_states = transformer_outputs[0]
953 if return_last_logit:
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File ~/.cache/huggingface/modules/transformers_modules/THUDM/chatglm3-6b/06c7c873c843814171c51330b69c2e2a68e05178/modeling_chatglm.py:834, in ChatGLMModel.forward(self, input_ids, position_ids, attention_mask, full_attention_mask, past_key_values, inputs_embeds, use_cache, output_hidden_states, return_dict)
831 rotary_pos_emb = rotary_pos_emb.transpose(0, 1).contiguous()
833 # Run encoder.
--> 834 hidden_states, presents, all_hidden_states, all_self_attentions = self.encoder(
835 inputs_embeds, full_attention_mask, rotary_pos_emb=rotary_pos_emb,
836 kv_caches=past_key_values, use_cache=use_cache, output_hidden_states=output_hidden_states
837 )
839 if not return_dict:
840 return tuple(v for v in [hidden_states, presents, all_hidden_states, all_self_attentions] if v is not None)
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File ~/.cache/huggingface/modules/transformers_modules/THUDM/chatglm3-6b/06c7c873c843814171c51330b69c2e2a68e05178/modeling_chatglm.py:641, in GLMTransformer.forward(self, hidden_states, attention_mask, rotary_pos_emb, kv_caches, use_cache, output_hidden_states)
631 layer_ret = torch.utils.checkpoint.checkpoint(
632 layer,
633 hidden_states,
(...)
638 use_reentrant=False
639 )
640 else:
--> 641 layer_ret = layer(
642 hidden_states,
643 attention_mask,
644 rotary_pos_emb,
645 kv_cache=kv_caches[index],
646 use_cache=use_cache
647 )
648 hidden_states, kv_cache = layer_ret
649 if use_cache:
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File ~/.cache/huggingface/modules/transformers_modules/THUDM/chatglm3-6b/06c7c873c843814171c51330b69c2e2a68e05178/modeling_chatglm.py:544, in GLMBlock.forward(self, hidden_states, attention_mask, rotary_pos_emb, kv_cache, use_cache)
542 layernorm_output = self.input_layernorm(hidden_states)
543 # Self attention.
--> 544 attention_output, kv_cache = self.self_attention(
545 layernorm_output,
546 attention_mask,
547 rotary_pos_emb,
548 kv_cache=kv_cache,
549 use_cache=use_cache
550 )
552 # Residual connection.
553 if self.apply_residual_connection_post_layernorm:
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)
1516 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1517 else:
-> 1518 return self._call_impl(*args, **kwargs)
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)
1522 # If we don't have any hooks, we want to skip the rest of the logic in
1523 # this function, and just call forward.
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1525 or _global_backward_pre_hooks or _global_backward_hooks
1526 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1527 return forward_call(*args, **kwargs)
1529 try:
1530 result = None
File ~/.cache/huggingface/modules/transformers_modules/THUDM/chatglm3-6b/06c7c873c843814171c51330b69c2e2a68e05178/modeling_chatglm.py:413, in SelfAttention.forward(self, hidden_states, attention_mask, rotary_pos_emb, kv_cache, use_cache)
411 # adjust key and value for inference
412 if kv_cache is not None:
--> 413 cache_k, cache_v = kv_cache
414 key_layer = torch.cat((cache_k, key_layer), dim=0)
415 value_layer = torch.cat((cache_v, value_layer), dim=0)
ValueError: too many values to unpack (expected 2)
Beta Was this translation helpful? Give feedback.
All reactions