OpenBMB / MiniCPM

MiniCPM3-4B: An edge-side LLM that surpasses GPT-3.5-Turbo.
Apache License 2.0
7.01k stars 441 forks source link

[Bug]: TypeError: PreTrainedTokenizerFast._batch_encode_plus() got an unexpected keyword argument 'tools' #244

Open sankexin opened 2 weeks ago

sankexin commented 2 weeks ago

Is there an existing issue ? / 是否已有相关的 issue ?

Describe the bug / 描述这个 bug

File /opt/conda/lib/python3.10/site-packages/transformers/tokenization_utils_fast.py:576, in PreTrainedTokenizerFast._encode_plus(self, text, text_pair, add_special_tokens, padding_strategy, truncation_strategy, max_length, stride, is_split_into_words, pad_to_multiple_of, return_tensors, return_token_type_ids, return_attention_mask, return_overflowing_tokens, return_special_tokens_mask, return_offsets_mapping, return_length, verbose, kwargs) 554 def _encode_plus( 555 self, 556 text: Union[TextInput, PreTokenizedInput], (...) 573 kwargs, 574 ) -> BatchEncoding: 575 batched_input = [(text, text_pair)] if text_pair else [text] --> 576 batched_output = self._batch_encode_plus( 577 batched_input, 578 is_split_into_words=is_split_into_words, 579 add_special_tokens=add_special_tokens, 580 padding_strategy=padding_strategy, 581 truncation_strategy=truncation_strategy, 582 max_length=max_length, 583 stride=stride, 584 pad_to_multiple_of=pad_to_multiple_of, 585 return_tensors=return_tensors, 586 return_token_type_ids=return_token_type_ids, 587 return_attention_mask=return_attention_mask, 588 return_overflowing_tokens=return_overflowing_tokens, 589 return_special_tokens_mask=return_special_tokens_mask, 590 return_offsets_mapping=return_offsets_mapping, 591 return_length=return_length, 592 verbose=verbose, 593 **kwargs, 594 ) 596 # Return tensor is None, then we can remove the leading batch axis 597 # Overflowing tokens are returned as a batch of output so we keep them in this case 598 if return_tensors is None and not return_overflowing_tokens:

TypeError: PreTrainedTokenizerFast._batch_encode_plus() got an unexpected keyword argument 'tools'

To Reproduce / 如何复现

from transformers import AutoModelForCausalLM, AutoTokenizer import torch

path = "openbmb/MiniCPM3-4B" device = "cuda"

tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)

messages = [ {"role": "user", "content": "推荐5个北京的景点。"}, ] model_inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(device)

model_outputs = model.generate( model_inputs, max_new_tokens=1024, top_p=0.7, temperature=0.7 )

output_token_ids = [ model_outputs[i][len(model_inputs[i]):] for i in range(len(model_inputs)) ]

responses = tokenizer.batch_decode(output_token_ids, skip_special_tokens=True)[0] print(responses)

Expected behavior / 期望的结果

No response

Screenshots / 截图

No response

Environment / 环境

- OS: [e.g. Ubuntu 20.04]
- Pytorch: [e.g. torch 2.0.0]
- CUDA: [e.g. CUDA 11.8]
- Device: [e.g. A10, RTX3090]

Additional context / 其他信息

No response

LDLINGLINGLING commented 2 weeks ago

Hello, I used your code here without the above bugs. Please try to update the transformers library.

sankexin commented 2 weeks ago

Hello, I used your code here without the above bugs. Please try to update the transformers library.

I have tested many transformers, which transformers do you used?can you share your detail env?

LDLINGLINGLING commented 2 weeks ago

hello, my transformers version is 4.44.2

sankexin commented 2 weeks ago

hello, my transformers version is 4.44.2

done