Skip to content

paddlenlp运行paddlenlp/PP-UIE-0.5B模型时,出现报错:AttributeError: 'builtins.PySafeSlice' object has no attribute 'shape'的解决方案 #10881

@steinsWorld

Description

@steinsWorld

问题描述

paddlenlp版本:3.0.0b4.post20250704
运行代码:
`from pprint import pprint
from paddlenlp import Taskflow

schema = ['时间', '选手', '赛事名称']
ie = Taskflow('information_extraction',
schema= ['时间', '选手', '赛事名称'],
schema_lang="zh",
batch_size=1,
model='paddlenlp/PP-UIE-0.5B',
precision='float16')
pprint(ie("2月8日上午北京冬奥会自由式滑雪女子大跳台决赛中中国选手谷爱凌以188.25分获得金牌!")) `

报错信息:
Traceback (most recent call last): File "C:\Users\604115\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 198, in _run_module_as_main return _run_code(code, main_globals, None, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\604115\AppData\Local\Programs\Python\Python312\Lib\runpy.py", line 88, in _run_code exec(code, run_globals) File "c:\Users\604115\.vscode\extensions\ms-python.debugpy-2025.10.0-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy\__main__.py", line 71, in <module> cli.main() File "c:\Users\604115\.vscode\extensions\ms-python.debugpy-2025.10.0-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 501, in main run() File "c:\Users\604115\.vscode\extensions\ms-python.debugpy-2025.10.0-win32-x64\bundled\libs\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 351, in run_file runpy.run_path(target, run_name="__main__") File "c:\Users\604115\.vscode\extensions\ms-python.debugpy-2025.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 310, in run_path return _run_module_code(code, init_globals, run_name, pkg_name=pkg_name, script_name=fname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "c:\Users\604115\.vscode\extensions\ms-python.debugpy-2025.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 127, in _run_module_code _run_code(code, mod_globals, init_globals, mod_name, mod_spec, pkg_name, script_name) File "c:\Users\604115\.vscode\extensions\ms-python.debugpy-2025.10.0-win32-x64\bundled\libs\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 118, in _run_code exec(code, run_globals) File "E:\personal_dev\paddle_uie\entity_extraction.py", line 5, in <module> ie = Taskflow('information_extraction', ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\taskflow\taskflow.py", line 869, in __init__ self.task_instance = task_class( ^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\taskflow\information_extraction.py", line 152, in __init__ self._construct_model(model) File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\taskflow\information_extraction.py", line 170, in _construct_model model_instance = AutoModelForCausalLM.from_pretrained(model, dtype=self._infer_precision) File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\transformers\auto\modeling.py", line 799, in from_pretrained ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\transformers\auto\modeling.py", line 347, in _from_pretrained return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\transformers\model_utils.py", line 2695, in from_pretrained model, missing_keys, unexpected_keys, mismatched_keys = cls._load_pretrained_model( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\transformers\model_utils.py", line 2331, in _load_pretrained_model state_dict = load_state_dict( ^^^^^^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\transformers\model_utils.py", line 501, in load_state_dict state_dict, scale_dict = _load_part_state_dict( ^^^^^^^^^^^^^^^^^^^^^^ File "e:\personal_dev\paddle_uie\uie_test\Lib\site-packages\paddlenlp\transformers\model_utils.py", line 437, in _load_part_state_dict if len(py_safe_slice_.get_shape()) == 0: ^^^^^^^^^^^^^^^^^^^^ AttributeError: 'builtins.PySafeSlice' object has no attribute 'shape'

解决方案:

Image

Metadata

Metadata

Assignees

Labels

othersunknown issue type

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions