PaddleNLP icon indicating copy to clipboard operation
PaddleNLP copied to clipboard

[Question]: 使用Taskflow进行情感分析任务的一键预测的时候报错

Open tigerbaby1515 opened this issue 2 years ago • 6 comments

请提出你的问题

在执行senta = Taskflow("sentiment_analysis", model="skep_ernie_1.0_large_ch")的时候

senta = Taskflow("sentiment_analysis", model="skep_ernie_1.0_large_ch") [2022-11-02 23:29:39,840] [ INFO] - Downloading model_state.pdparams from https://bj.bcebos.com/paddlenlp/taskflow/sentiment_analysis/skep_ernie_1.0_large_ch/model_state.pdparams 100%|██████████████████████████████████████████████████████████████████| 1.77G/1.77G [22:51<00:00, 1.38MB/s] [2022-11-02 23:52:38,870] [ INFO] - Downloading model_config.json from https://bj.bcebos.com/paddlenlp/taskflow/sentiment_analysis/skep_ernie_1.0_large_ch/model_config.json 100%|███████████████████████████████████████████████████████████████████████| 399/399 [00:00<00:00, 109kB/s] [2022-11-02 23:52:42,712] [ INFO] - Downloading https://bj.bcebos.com/paddlenlp/models/transformers/skep/skep_ernie_1.0_large_ch.vocab.txt and saved to /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch [2022-11-02 23:52:42,712] [ INFO] - Downloading skep_ernie_1.0_large_ch.vocab.txt from https://bj.bcebos.com/paddlenlp/models/transformers/skep/skep_ernie_1.0_large_ch.vocab.txt 100%|███████████████████████████████████████████████████████████████████| 54.4k/54.4k [00:00<00:00, 291kB/s] [2022-11-02 23:52:46,127] [ INFO] - tokenizer config file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/tokenizer_config.json [2022-11-02 23:52:46,127] [ INFO] - Special tokens file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/special_tokens_map.json [2022-11-02 23:52:54,362] [ INFO] - Converting to the inference model cost a little time. Traceback (most recent call last): File "", line 1, in File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/taskflow.py", line 569, in init self.task_instance = task_class(model=self.model, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/sentiment_analysis.py", line 255, in init self._get_inference_model() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/task.py", line 247, in _get_inference_model self._convert_dygraph_to_static() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/task.py", line 268, in _convert_dygraph_to_static paddle.jit.save(static_model, save_path) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/jit.py", line 631, in wrapper func(layer, path, input_spec, **configs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in impl return wrapped_func(*args, **kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/base.py", line 51, in impl return func(*args, **kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/jit.py", line 860, in save concrete_program = static_func.concrete_program_specify_input_spec( File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 527, in concrete_program_specify_input_spec concrete_program, _ = self.get_concrete_program( File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 436, in get_concrete_program concrete_program, partial_program_layer = self._program_cache[cache_key] File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 801, in getitem self._caches[item_id] = self._build_once(item) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 785, in build_once concrete_program = ConcreteProgram.from_func_spec( File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in impl return wrapped_func(*args, **kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/base.py", line 51, in impl return func(*args, **kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 740, in from_func_spec error_data.raise_new_exception() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/dygraph/dygraph_to_static/error.py", line 336, in raise_new_exception six.exec("raise new_exception from None") File "", line 1, in TypeError: In transformed code:

File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/models/sentiment_analysis_model.py", line 151, in forward
_, pooled_output = self.skep(input_ids,
File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/skep/modeling.py", line 392, in forward
    pooled_output = self.pooler(sequence_output)
    if not return_dict:
        return (sequence_output, pooled_output) + encoder_outputs[1:]
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    return BaseModelOutputWithPoolingAndCrossAttentions(
        last_hidden_state=sequence_output,

File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/layers/math_op_patch.py", line 313, in __impl__
other_var = create_scalar(
File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/layers/math_op_patch.py", line 98, in create_scalar
return create_tensor(block, value, dtype, shape=[1])
File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/layers/math_op_patch.py", line 82, in create_tensor
value = float(value)

TypeError: float() argument must be a string or a number, not 'tuple'

这个怎么解决呢

tigerbaby1515 avatar Nov 02 '22 09:11 tigerbaby1515

  1. 删除 ~/.paddlenlp目录
  2. 升级到最新的PaddleNLP 2.4.2版本

wawltor avatar Nov 02 '22 10:11 wawltor

但是现在又出来一个新问题

senta = Taskflow("sentiment_analysis", model="skep_ernie_1.0_large_ch") [2022-11-03 04:08:34,407] [ INFO] - Already cached /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/skep_ernie_1.0_large_ch.vocab.txt [2022-11-03 04:08:34,412] [ INFO] - tokenizer config file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/tokenizer_config.json [2022-11-03 04:08:34,412] [ INFO] - Special tokens file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/special_tokens_map.json Traceback (most recent call last): File "", line 1, in File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/taskflow.py", line 569, in init self.task_instance = task_class(model=self.model, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/sentiment_analysis.py", line 255, in init self._get_inference_model() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/task.py", line 245, in _get_inference_model self._construct_model(self.model) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/sentiment_analysis.py", line 264, in _construct_model model_instance = SkepSequenceModel.from_pretrained(self._task_path, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/model_utils.py", line 348, in from_pretrained base_model = cls.base_model_class(*base_args, **base_kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/utils.py", line 159, in impl init_func(self, *args, **kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/skep/modeling.py", line 270, in init self.embeddings = SkepEmbeddings(vocab_size, hidden_size, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/skep/modeling.py", line 54, in init self.word_embeddings = nn.Embedding(vocab_size, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/nn/layer/common.py", line 1461, in init self.weight[padding_idx] = 0.0 File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/framework.py", line 2189, in setitem return setitem_impl(self, item, value) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/variable_index.py", line 696, in setitem_impl var._bump_inplace_version() AttributeError: 'Parameter' object has no attribute '_bump_inplace_version'

tigerbaby1515 avatar Nov 02 '22 12:11 tigerbaby1515

但是现在又出来一个新问题

senta = Taskflow("sentiment_analysis", model="skep_ernie_1.0_large_ch") [2022-11-03 04:08:34,407] [ INFO] - Already cached /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/skep_ernie_1.0_large_ch.vocab.txt [2022-11-03 04:08:34,412] [ INFO] - tokenizer config file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/tokenizer_config.json [2022-11-03 04:08:34,412] [ INFO] - Special tokens file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/special_tokens_map.json Traceback (most recent call last): File "", line 1, in File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/taskflow.py", line 569, in init self.task_instance = task_class(model=self.model, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/sentiment_analysis.py", line 255, in init self._get_inference_model() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/task.py", line 245, in _get_inference_model self._construct_model(self.model) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/sentiment_analysis.py", line 264, in _construct_model model_instance = SkepSequenceModel.from_pretrained(self._task_path, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/model_utils.py", line 348, in from_pretrained base_model = cls.base_model_class(*base_args, **base_kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/utils.py", line 159, in impl init_func(self, *args, **kwargs) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/skep/modeling.py", line 270, in init self.embeddings = SkepEmbeddings(vocab_size, hidden_size, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/transformers/skep/modeling.py", line 54, in init self.word_embeddings = nn.Embedding(vocab_size, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/nn/layer/common.py", line 1461, in init self.weight[padding_idx] = 0.0 File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/framework.py", line 2189, in setitem return setitem_impl(self, item, value) File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddle/fluid/variable_index.py", line 696, in setitem_impl var._bump_inplace_version() AttributeError: 'Parameter' object has no attribute '_bump_inplace_version'

你的PaddlePaddle是什么版本了?

wawltor avatar Nov 03 '22 00:11 wawltor

paddle-bfloat 0.1.7 paddle2onnx 1.0.1 paddlefsl 1.1.0 paddlenlp 2.4.2 paddlepaddle-gpu 2.3.2.post112

tigerbaby1515 avatar Nov 03 '22 01:11 tigerbaby1515

麻烦尝试升级paddlepaddle-gpu 到2.4rc0版本

wawltor avatar Nov 03 '22 07:11 wawltor

senta = Taskflow("sentiment_analysis", model="skep_ernie_1.0_large_ch") [2022-11-03 23:37:04,962] [ INFO] - Already cached /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/skep_ernie_1.0_large_ch.vocab.txt [2022-11-03 23:37:04,969] [ INFO] - tokenizer config file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/tokenizer_config.json [2022-11-03 23:37:04,969] [ INFO] - Special tokens file saved in /home/wanghan/.paddlenlp/models/skep_ernie_1.0_large_ch/special_tokens_map.json W1103 23:37:04.972504 26850 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 8.0, Driver API Version: 11.4, Runtime API Version: 10.2 W1103 23:37:04.977814 26850 gpu_resources.cc:91] device: 0, cuDNN Version: 8.5. [2022-11-03 23:37:13,432] [ INFO] - Converting to the inference model cost a little time. [2022-11-03 23:37:20,497] [ INFO] - The inference model save in the path:/home/wanghan/.paddlenlp/taskflow/sentiment_analysis/skep_ernie_1.0_large_ch/static/inference Traceback (most recent call last): File "", line 1, in File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/taskflow.py", line 569, in init self.task_instance = task_class(model=self.model, File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/sentiment_analysis.py", line 255, in init self._get_inference_model() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/task.py", line 254, in _get_inference_model self._prepare_static_mode() File "/home/wanghan/.conda/envs/paddle/lib/python3.8/site-packages/paddlenlp/taskflow/task.py", line 174, in _prepare_static_mode self.predictor = paddle.inference.create_predictor(self._config) OSError: (External) CUDA error(209), no kernel image is available for execution on the device. [Hint: Please search for the error code(209) on website (https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html#group__CUDART__TYPES_1g3f51e3575c2178246db0a94a430e0038) to get Nvidia's official solution and advice about CUDA Error.] (at /paddle/paddle/fluid/platform/device/gpu/gpu_info.cc:148)

貌似不行 不知道是不是cuda版本问题

tigerbaby1515 avatar Nov 03 '22 10:11 tigerbaby1515