今天在测试阿里通义千问Qwen-1_8B-Chat-Int8的模型的时候发生报错,部分错误信息如下:
Traceback (most recent call last):
File “.\request_llms\local_llm_class.py”, line 160, in run
for response_full in self.llm_stream_generator(*kwargs): File “.\request_llms\bridge_qwen_local.py”, line 46, in llm_stream_generator for response in self._model.chat_stream(self._tokenizer, query, history=history): File “.\huggingface\modules\transformers_modules\Qwen\Qwen-1_8B-Chat-Int8\2fb5c225fe592d8d891cbf6c1ed5924cabe48a18\modeling_qwen.py”, line 1214, in stream_generator for token in self.generate_stream( File “.\python3\lib\site-packages\torch\utils_contextlib.py”, line 116, in decorate_context return func(args, **kwargs)
File “.\python3\lib\site-packages\transformers_stream_generator\main.py”, line 208, in generate
] = self._prepare_attention_mask_for_generation(
File “.\python3\lib\site-packages\transformers\generation\utils.py”, line 473, in _prepare_attention_mask_for_generation
torch.isin(elements=inputs, test_elements=pad_token_id).any()
TypeError: isin() received an invalid combination of arguments – got (elements=Tensor, test_elements=int, ), but expected one of:
- (Tensor elements, Tensor test_elements, *, bool assume_unique = False, bool invert = False, Tensor out = None)
- (Number element, Tensor test_elements, *, bool assume_unique = False, bool invert = False, Tensor out = None)
- (Tensor elements, Number test_element, *, bool assume_unique = False, bool invert = False, Tensor out = None)
意思就是在 torch.isin() 函数中传入的参数类型不匹配导致的。torch.isin 期望的是两个张量(Tensor)参数或者一个数字和一个张量的组合,而传入的是一个张量(elements)和一个整数(test_elements)。
需要修改torch部分功能代码解决,还有另一种方法就是重新安装transformers,将版本降到4.41.0以下,可解决此报错问题