PaddlePaddle / PaddleNLP

👑 Easy-to-use and powerful NLP and LLM library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, ❓ Question Answering, ℹ️ Information Extraction, 📄 Document Intelligence, 💌 Sentiment Analysis etc.
https://paddlenlp.readthedocs.io
Apache License 2.0
11.96k stars 2.91k forks source link

[Bug]: ValueError: The feeded_var_names[0]: 'input_ids' doesn't exist in pruned inference program. #6625

Closed BrightXiaoHan closed 4 months ago

BrightXiaoHan commented 1 year ago

软件环境

paddle-custom-npu   0.0.0
paddle2onnx         1.0.5
paddlefsl           1.1.0
paddlenlp           2.6.0rc0.post0
paddlepaddle        0.0.0

重复问题

错误描述

在昇腾910上使用Taskflow api

(.venv) [ma-user npu]$ipython
Python 3.9.17 (main, Jul 31 2023, 14:08:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from paddlenlp import Taskflow
I0806 22:35:07.311784 19043 init.cc:239] ENV [CUSTOM_DEVICE_ROOT]=/home/ma-user/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle_custom_device
I0806 22:35:07.311841 19043 init.cc:145] Try loading custom device libs from: [/home/ma-user/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle_custom_device]
I0806 22:35:07.861747 19043 custom_device.cc:1112] Successed in loading custom runtime in lib: /home/ma-user/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle_custom_device/libpaddle-custom-npu.so
I0806 22:35:07.867177 19043 custom_kernel.cc:76] Successed in loading 325 custom kernel(s) from loaded lib(s), will be used like native ones.
I0806 22:35:07.867350 19043 init.cc:157] Finished in LoadCustomDevice with libs_path: [/home/ma-user/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle_custom_device]
I0806 22:35:07.867383 19043 init.cc:245] CustomDevice: npu, visible devices count: 1

In [2]: obj = Taskflow("zero_shot_text_classification")
[2023-08-06 22:35:25,087] [    INFO] - We are using <class 'paddlenlp.transformers.ernie.tokenizer.ErnieTokenizer'> to load '/home/ma-user/.paddlenlp/taskflow/zero_shot_text_classification/utc-base'.
[2023-08-06 22:35:25,138] [    INFO] - Assigning ['[O-MASK]'] to the additional_special_tokens key of the tokenizer
[2023-08-06 22:35:25,141] [    INFO] - Loading configuration file /home/ma-user/.paddlenlp/taskflow/zero_shot_text_classification/utc-base/config.json
[2023-08-06 22:35:25,142] [    INFO] - Loading weights file /home/ma-user/.paddlenlp/taskflow/zero_shot_text_classification/utc-base/model_state.pdparams
[2023-08-06 22:35:26,051] [    INFO] - Loaded weights file from disk, setting weights to model.
[2023-08-06 22:35:51,091] [    INFO] - All model checkpoint weights were used when initializing UTC.

[2023-08-06 22:35:51,092] [    INFO] - All the weights of UTC were initialized from the model checkpoint at /home/ma-user/.paddlenlp/taskflow/zero_shot_text_classification/utc-base.
If your task is similar to the task the model of the checkpoint was trained on, you can already use UTC for predictions without further training.
[2023-08-06 22:35:51,113] [    INFO] - Converting to the inference model cost a little time.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 1
----> 1 obj = Taskflow("zero_shot_text_classification")

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddlenlp/taskflow/taskflow.py:804, in Taskflow.__init__(self, task, model, mode, device_id, from_hf_hub, **kwargs)
    802 self.kwargs = kwargs
    803 task_class = TASKS[self.task][tag][self.model]["task_class"]
--> 804 self.task_instance = task_class(
    805     model=self.model, task=self.task, priority_path=self.priority_path, from_hf_hub=from_hf_hub, **self.kwargs
    806 )
    807 task_list = TASKS.keys()
    808 Taskflow.task_list = task_list

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddlenlp/taskflow/zero_shot_text_classification.py:272, in ZeroShotTextClassificationTask.__init__(self, task, model, schema, **kwargs)
    270 self._construct_tokenizer()
    271 self._check_predictor_type()
--> 272 self._get_inference_model()

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddlenlp/taskflow/task.py:343, in Task._get_inference_model(self)
    341             self._construct_model(self.model)
    342             self._construct_input_spec()
--> 343             self._convert_dygraph_to_static()
    345 self._static_model_file = self.inference_model_path + ".pdmodel"
    346 self._static_params_file = self.inference_model_path + ".pdiparams"

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddlenlp/taskflow/task.py:389, in Task._convert_dygraph_to_static(self)
    386 logger.info("Converting to the inference model cost a little time.")
    387 static_model = paddle.jit.to_static(self._model, input_spec=self._input_spec)
--> 389 paddle.jit.save(static_model, self.inference_model_path)
    390 logger.info("The inference model save in the path:{}".format(self.inference_model_path))

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
    230 if not kwsyntax:
    231     args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/wrapped_decorator.py:25, in wrap_decorator.<locals>.__impl__(func, *args, **kwargs)
     22 @decorator.decorator
     23 def __impl__(func, *args, **kwargs):
     24     wrapped_func = decorator_func(func)
---> 25     return wrapped_func(*args, **kwargs)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/jit/api.py:757, in _run_save_pre_hooks.<locals>.wrapper(layer, path, input_spec, **configs)
    755 for hook in _save_pre_hooks:
    756     hook(layer, input_spec, configs)
--> 757 func(layer, path, input_spec, **configs)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
    230 if not kwsyntax:
    231     args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/wrapped_decorator.py:25, in wrap_decorator.<locals>.__impl__(func, *args, **kwargs)
     22 @decorator.decorator
     23 def __impl__(func, *args, **kwargs):
     24     wrapped_func = decorator_func(func)
---> 25     return wrapped_func(*args, **kwargs)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/dygraph/base.py:75, in _switch_to_static_graph_.<locals>.__impl__(*args, **kwargs)
     73 def __impl__(*args, **kwargs):
     74     with framework._dygraph_guard(None):
---> 75         return func(*args, **kwargs)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/jit/api.py:1205, in save(layer, path, input_spec, **configs)
   1200     params_filename = (
   1201         file_prefix + '.' + attr_func + INFER_PARAMS_SUFFIX
   1202     )
   1204 with scope_guard(scope):
-> 1205     save_inference_model(
   1206         dirname=model_path,
   1207         feeded_var_names=input_var_names,
   1208         target_vars=output_vars,
   1209         executor=Executor(_current_expected_place()),
   1210         main_program=concrete_program.main_program.clone(),
   1211         model_filename=model_filename,
   1212         params_filename=params_filename,
   1213         export_for_deployment=configs._export_for_deployment,
   1214         program_only=configs._program_only,
   1215         clip_extra=configs.clip_extra,
   1216     )
   1218 if combine_params:
   1219     clone_main_program = concrete_program.main_program.clone()

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
    230 if not kwsyntax:
    231     args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/wrapped_decorator.py:25, in wrap_decorator.<locals>.__impl__(func, *args, **kwargs)
     22 @decorator.decorator
     23 def __impl__(func, *args, **kwargs):
     24     wrapped_func = decorator_func(func)
---> 25     return wrapped_func(*args, **kwargs)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/framework.py:474, in _static_only_.<locals>.__impl__(*args, **kwargs)
    469 def __impl__(*args, **kwargs):
    470     assert not in_dygraph_mode(), (
    471         "In PaddlePaddle 2.x, we turn on dynamic graph mode by default, and '%s()' is only supported in static graph mode. So if you want to use this api, please call 'paddle.enable_static()' before this api to enter static graph mode."
    472         % func.__name__
    473     )
--> 474     return func(*args, **kwargs)

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/io.py:315, in save_inference_model(dirname, feeded_var_names, target_vars, executor, main_program, model_filename, params_filename, export_for_deployment, program_only, clip_extra, legacy_format)
    307     if not main_program.global_block().has_var(target_v.name):
    308         main_program.global_block().create_var(
    309             name=target_v.name,
    310             shape=target_v.shape,
    311             dtype=target_v.dtype,
    312             persistable=target_v.persistable,
    313         )
--> 315 prepend_feed_ops(main_program, feeded_var_names)
    316 append_fetch_ops(main_program, fetch_var_names)
    318 with open(model_basename, "wb") as f:

File ~/work/PaddleCustomDevice/backends/npu/.venv/lib/python3.9/site-packages/paddle/fluid/io.py:88, in prepend_feed_ops(inference_program, feed_target_names, feed_holder_name)
     86 for i, name in enumerate(feed_target_names):
     87     if not global_block.has_var(name):
---> 88         raise ValueError(
     89             "The feeded_var_names[{i}]: '{name}' doesn't exist in pruned inference program. "
     90             "Please check whether '{name}' is a valid feed_var name, or remove it from feeded_var_names "
     91             "if '{name}' is not involved in the target_vars calculation.".format(
     92                 i=i, name=name
     93             )
     94         )
     95     out = global_block.var(name)
     96     global_block._prepend_op(
     97         type='feed',
     98         inputs={'X': [feed_var]},
     99         outputs={'Out': [out]},
    100         attrs={'col': i},
    101     )

ValueError: The feeded_var_names[0]: 'input_ids' doesn't exist in pruned inference program. Please check whether 'input_ids' is a valid feed_var name, or remove it from feeded_var_names if 'input_ids' is not involved in the target_vars calculation.

稳定复现步骤 & 代码

from paddlenlp import Taskflow
obj = Taskflow("zero_shot_text_classification")
w5688414 commented 4 months ago

我测了一下没什么问题:

image

以下是我的环境:

absl-py==2.1.0
aiofiles==23.2.1
aiohttp==3.9.3
aiosignal==1.3.1
aistudio-sdk==0.1.7
altair==5.2.0
annotated-types==0.6.0
antlr4-python3-runtime==4.9.3
anyio==4.3.0
astor==0.8.1
asttokens==2.4.1
async-timeout==4.0.3
attrs==23.2.0
audioread==3.0.1
Babel==2.14.0
backcall==0.2.0
bce-python-sdk==0.9.4
blinker==1.7.0
bokeh==3.1.1
boltons==23.1.1
Bottleneck==1.3.8
braceexpand==0.1.7
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
coloredlogs==15.0.1
colorlog==6.8.2
contourpy==1.1.1
cycler==0.12.1
Cython==3.0.8
datasets==2.17.1
decorator==5.1.1
dill==0.3.4
Distance==0.1.3
easydict==1.12
editdistance==0.8.1
einops==0.7.0
exceptiongroup==1.2.0
executing==2.0.1
fastapi==0.110.0
ffmpy==0.3.2
filelock==3.13.1
Flask==3.0.2
Flask-Babel==2.0.0
flatbuffers==23.5.26
fonttools==4.49.0
frozenlist==1.4.1
fsspec==2023.10.0
ftfy==6.1.3
future==1.0.0
g2p-en==2.1.0
g2pM==0.1.2.5
gradio==4.19.2
gradio_client==0.10.1
gunicorn==21.2.0
h11==0.14.0
h5py==3.10.0
httpcore==1.0.4
httpx==0.27.0
huggingface-hub==0.21.1
humanfriendly==10.0
HyperPyYAML==1.2.2
idna==3.6
importlib-metadata==7.0.1
importlib_resources==6.1.2
inflect==7.0.0
intervaltree==3.1.0
ipython==8.12.3
itsdangerous==2.1.2
jedi==0.19.1
jieba==0.42.1
Jinja2==3.1.3
joblib==1.3.2
jsonlines==4.0.0
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
kaldiio==2.18.0
kiwisolver==1.4.5
librosa==0.9.2
llvmlite==0.41.1
loguru==0.7.2
lxml==5.1.0
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib==3.7.5
matplotlib-inline==0.1.6
mdurl==0.1.2
mido==1.3.2
mock==5.1.0
mpmath==1.3.0
multidict==6.0.5
multiprocess==0.70.12.2
nara-wpe==0.0.9
nltk==3.8.1
note-seq==0.0.5
numba==0.58.1
numpy==1.22.0
omegaconf==2.3.0
onnx==1.15.0
onnxruntime==1.17.1
OpenCC==1.1.7
opencc-python-reimplemented==0.1.7
opencv-python==4.6.0.66
opt-einsum==3.3.0
orjson==3.9.15
packaging==23.2
paddle-bfloat==0.1.7
paddle2onnx==1.1.0
paddleaudio==1.1.0
paddlefsl==1.1.0
paddlehub==2.4.0
paddlenlp==2.5.2
paddlepaddle-gpu==2.4.1.post117
paddlesde==0.2.5
paddleslim==2.6.0
paddlespeech==1.4.1
paddlespeech-ctcdecoders==0.2.1
paddlespeech-feat==0.1.0
pandas==2.0.3
parameterized==0.9.0
parso==0.8.3
pathos==0.2.8
pattern_singleton==1.2.0
pexpect==4.9.0
pickleshare==0.7.5
pillow==10.2.0
pkgutil_resolve_name==1.3.10
platformdirs==4.2.0
pooch==1.8.1
portalocker==2.8.2
pox==0.3.4
ppdiffusers==0.19.4
ppft==1.7.6.8
praatio==5.1.1
pretty_midi==0.2.10
prettytable==3.10.0
prompt-toolkit==3.0.43
protobuf==3.20.0
psutil==5.9.8
ptyprocess==0.7.0
pure-eval==0.2.2
pyarrow==15.0.0
pyarrow-hotfix==0.6
pybind11==2.11.1
pycparser==2.21
pycryptodome==3.20.0
pydantic==2.6.3
pydantic_core==2.16.3
pydub==0.25.1
Pygments==2.17.2
pygtrie==2.5.0
pyparsing==3.1.1
pypinyin==0.44.0
pypinyin-dict==0.7.0
python-dateutil==2.8.2
python-multipart==0.0.9
pytz==2024.1
pyworld==0.3.4
PyYAML==6.0.1
pyzmq==25.1.2
rarfile==4.1
referencing==0.33.0
regex==2023.12.25
requests==2.31.0
requests-mock==1.11.0
resampy==0.4.2
rich==13.7.0
rpds-py==0.18.0
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.8
ruff==0.2.2
sacrebleu==2.4.0
safetensors==0.4.2
scikit-learn==1.3.2
scipy==1.10.1
semantic-version==2.10.0
sentencepiece==0.2.0
seqeval==1.2.2
shellingham==1.5.4
six==1.16.0
sniffio==1.3.1
sortedcontainers==2.4.0
soundfile==0.12.1
stack-data==0.6.3
starlette==0.36.3
swig==4.2.1
sympy==1.12
tabulate==0.9.0
TextGrid==1.5
threadpoolctl==3.3.0
timer==0.2.2
ToJyutping==0.2.3
tomlkit==0.12.0
tool-helpers==0.1.1
toolz==0.12.1
tornado==6.4
tqdm==4.66.2
traitlets==5.14.1
trampoline==0.1.2
typeguard==2.13.3
typer==0.9.0
typing_extensions==4.10.0
tzdata==2024.1
urllib3==1.26.18
uvicorn==0.27.1
visualdl==2.4.2
wcwidth==0.2.13
webrtcvad==2.0.10
websockets==11.0.3
Werkzeug==3.0.1
xxhash==3.4.1
xyzservices==2023.10.1
yacs==0.1.8
yarl==1.9.4
zhon==2.0.2
zipp==3.17.0