2023-01-25 08:21:21,659 - ERROR - Traceback (most recent call last):
File "/home/xyzUser/project/queue_handler/document_queue_listner.py", line 148, in __process_and_acknowledge
pipeline_result = self.__process_document_type(message, pipeline_input)
File "/home/xyzUser/project/queue_handler/document_queue_listner.py", line 194, in __process_document_type
pipeline_result = bill_parser_pipeline.process(pipeline_input)
File "/home/xyzUser/project/main/billparser/__init__.py", line 18, in process
bill_extractor_model = MachineGeneratedBillExtractorModel()
File "/home/xyzUser/project/main/billparser/models/qa_model.py", line 25, in __new__
cls.__model = TransformersReader(model_name_or_path=cls.__model_path, use_gpu=False)
File "/home/xyzUser/project/.env/lib/python3.8/site-packages/haystack/nodes/base.py", line 48, in wrapper_exportable_to_yaml
init_func(self, *args, **kwargs)
File "/home/xyzUser/project/.env/lib/python3.8/site-packages/haystack/nodes/reader/transformers.py", line 93, in __init__
self.model = pipeline(
File "/home/xyzUser/project/.env/lib/python3.8/site-packages/transformers/pipelines/__init__.py", line 542, in pipeline
return task_class(model=model, framework=framework, task=task, **kwargs)
File "/home/xyzUser/project/.env/lib/python3.8/site-packages/transformers/pipelines/question_answering.py", line 125, in __init__
super().__init__(
File "/home/xyzUser/project/.env/lib/python3.8/site-packages/transformers/pipelines/base.py", line 691, in __init__
self.device = device if framework == "tf" else torch.device("cpu" if device < 0 else f"cuda:{device}")
TypeError: '<' not supported between instances of 'torch.device' and 'int'
这是我从项目安装requirement.txt 文件后收到的错误消息。我认为这与 torch 有关,但也不知道如何修复它。我是抱脸变形金刚新手,不知道是否是版本问题。
最佳答案
这是 transformers
的错误v4.22.0
之前的许多版本的软件包,因为特定的代码行无法区分 device
参数的类型可能是 torch。 device
,然后将其与 int
进行比较。通过gitblame
追踪,我们可以发现this specific change在变更集中制作 9d4a45509ab
在结果文件中包含第 764 行提供的急需的 if isinstance(device, torch.device):
,这将确保不会发生此错误。检查上面的标签将显示 v4.22.0
及更高版本的版本应包含此特定修复。作为回顾,要更新特定包,激活环境,并发出以下命令:
pip install -U transformers
或者使用特定版本,例如:
pip install -U transformers==4.22.0
关于python - 类型错误 : '<' not supported between instances of 'torch.device' and 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75229395/