Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: 使用Taskflow进行NER时出错 #9413

Open
tszxyuan123 opened this issue Nov 12, 2024 · 10 comments
Open

[Question]: 使用Taskflow进行NER时出错 #9413

tszxyuan123 opened this issue Nov 12, 2024 · 10 comments
Assignees
Labels
question Further information is requested

Comments

@tszxyuan123
Copy link

请提出你的问题

环境为windows10家庭版,paddle版本为3.0-beta的cpu版本

from paddlenlp.taskflow import Taskflow

ner = Taskflow("ner")
出现的问题是,当输入上面第二行代码时,报错,具体日志如下:
`[2024-11-12 16:05:44,254] [ INFO] - Downloading model_state.pdparams from https://bj.bcebos.com/paddlenlp/taskflow/knowledge_mining/wordtag_v1.5/model_state.pdparams

[2024-11-12 16:08:27,954] [ INFO] - Downloading config.json from https://bj.bcebos.com/paddlenlp/taskflow/knowledge_mining/wordtag_v1.1/config.json

[2024-11-12 16:08:28,355] [ INFO] - Downloading tags.txt from https://bj.bcebos.com/paddlenlp/taskflow/knowledge_mining/wordtag_v1.1/tags.txt

[2024-11-12 16:08:28,561] [ INFO] - Downloading vocab.txt from https://bj.bcebos.com/paddlenlp/taskflow/knowledge_mining/wordtag/vocab.txt

[2024-11-12 16:08:28,980] [ INFO] - Downloading special_tokens_map.json from https://bj.bcebos.com/paddlenlp/taskflow/knowledge_mining/wordtag/special_tokens_map.json

[2024-11-12 16:08:29,206] [ INFO] - Downloading tokenizer_config.json from https://bj.bcebos.com/paddlenlp/taskflow/knowledge_mining/wordtag/tokenizer_config.json

[2024-11-12 16:08:29,421] [ INFO] - Loading configuration file C:\Users\lenovo.paddlenlp\taskflow\wordtag\config.json
[2024-11-12 16:08:29,424] [ INFO] - Loading weights file C:\Users\lenovo.paddlenlp\taskflow\wordtag\model_state.pdparams
[2024-11-12 16:08:29,665] [ INFO] - Loaded weights file from disk, setting weights to model.
[2024-11-12 16:08:36,820] [ WARNING] - Some weights of the model checkpoint at C:\Users\lenovo.paddlenlp\taskflow\wordtag were not used when initializing ErnieCtmWordtagModel: ['sent_classifier.bias', 'sent_classifier.weight']

  • This IS expected if you are initializing ErnieCtmWordtagModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).

  • This IS NOT expected if you are initializing ErnieCtmWordtagModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
    [2024-11-12 16:08:36,821] [ WARNING] - Some weights of ErnieCtmWordtagModel were not initialized from the model checkpoint at C:\Users\lenovo.paddlenlp\taskflow\wordtag and are newly initialized: ['viterbi_decoder.transitions', 'crf_loss.crf.transitions']
    You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
    [2024-11-12 16:08:36,847] [ INFO] - Converting to the inference model cost a little time.
    D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\program_translator.py:747: UserWarning: full_graph=False don't support input_spec arguments. It will not produce any effect.
    You can set full_graph=True, then you can assign input spec.

    warnings.warn(
    [2024-11-12 16:08:41,319] [ INFO] - The inference model save in the path:C:\Users\lenovo.paddlenlp\taskflow\wordtag\static\inference


RuntimeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 ner = Taskflow("ner")

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\taskflow.py:809, in Taskflow.init(self, task, model, mode, device_id, from_hf_hub, **kwargs)
807 self.kwargs = kwargs
808 task_class = TASKS[self.task][tag][self.model]["task_class"]
--> 809 self.task_instance = task_class(
810 model=self.model, task=self.task, priority_path=self.priority_path, from_hf_hub=from_hf_hub, **self.kwargs
811 )
812 task_list = TASKS.keys()
813 Taskflow.task_list = task_list

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\named_entity_recognition.py:123, in NERWordTagTask.init(self, model, task, entity_only, **kwargs)
122 def init(self, model, task, entity_only=False, **kwargs):
--> 123 super().init(model="wordtag", task=task, **kwargs)
124 self.entity_only = entity_only
125 if self._user_dict:

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\knowledge_mining.py:235, in WordTagTask.init(self, model, task, tag_path, term_schema_path, term_data_path, user_dict, linking, spo_config_path, with_ie, **kwargs)
233 self._usage = usage
234 self._summary_num = 2
--> 235 self._get_inference_model()
237 if self._user_dict:
238 self._custom = Customization()

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\task.py:371, in Task._get_inference_model(self)
369 self._static_params_file = self._static_fp16_params_file
370 if self._predictor_type == "paddle-inference":
--> 371 self._config = paddle.inference.Config(self._static_model_file, self._static_params_file)
372 self._prepare_static_mode()
373 else:

RuntimeError: (NotFound) Cannot open file C:\Users\lenovo.paddlenlp\taskflow\wordtag\static\inference.pdmodel, please confirm whether the file is normal.
[Hint: Expected paddle::inference::IsFileExists(prog_file_) == true, but received paddle::inference::IsFileExists(prog_file_):0 != true:1.] (at ..\paddle\fluid\inference\api\analysis_config.cc:111)`

Uploading 图片1.png…

有查到和这个问题类似:#3242
但是我的目录中并没有中文,用户名是lenovo,为什么也会出现这种情况?

@tszxyuan123 tszxyuan123 added the question Further information is requested label Nov 12, 2024
@wawltor
Copy link
Collaborator

wawltor commented Nov 12, 2024

可以尝试删除再试试 C:\Users\lenovo.paddlenlp\taskflow\wordtag\static\

@tszxyuan123
Copy link
Author

您是说删除static这个文件夹,再重新运行ner = Taskflow("ner")吗
我刚才试了一下,依然报同样的错误
我的图片上传似乎有些问题,C:\Users\lenovo.paddlenlp\taskflow\wordtag\static\,这个文件夹中只有inference.json和inference.pdiparams,没有inference.pdmodel

@wawltor
Copy link
Collaborator

wawltor commented Nov 13, 2024

可以尝试把paddle版本切换到2.5.2版本,同时删除 ,C:\Users\lenovo.paddlenlp\taskflow\wordtag\static\

@tszxyuan123
Copy link
Author

您是说把paddlenlp的版本降到2.5.2吗,我试一下

@wawltor
Copy link
Collaborator

wawltor commented Nov 13, 2024

您是说把paddlenlp的版本降到2.5.2吗,我试一下

是的

@tszxyuan123
Copy link
Author

确实没有出现之前的报错了,但是出现了另一个错误
`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 1
----> 1 ner = Taskflow("ner")

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\taskflow.py:809, in Taskflow.init(self, task, model, mode, device_id, from_hf_hub, **kwargs)
807 self.kwargs = kwargs
808 task_class = TASKS[self.task][tag][self.model]["task_class"]
--> 809 self.task_instance = task_class(
810 model=self.model, task=self.task, priority_path=self.priority_path, from_hf_hub=from_hf_hub, **self.kwargs
811 )
812 task_list = TASKS.keys()
813 Taskflow.task_list = task_list

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\named_entity_recognition.py:123, in NERWordTagTask.init(self, model, task, entity_only, **kwargs)
122 def init(self, model, task, entity_only=False, **kwargs):
--> 123 super().init(model="wordtag", task=task, **kwargs)
124 self.entity_only = entity_only
125 if self._user_dict:

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\knowledge_mining.py:235, in WordTagTask.init(self, model, task, tag_path, term_schema_path, term_data_path, user_dict, linking, spo_config_path, with_ie, **kwargs)
233 self._usage = usage
234 self._summary_num = 2
--> 235 self._get_inference_model()
237 if self._user_dict:
238 self._custom = Customization()

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\task.py:343, in _get_inference_model(self)
339 self._static_model_file = self.inference_model_path + ".pdmodel"
340 self._static_params_file = self.inference_model_path + ".pdiparams"
342 if paddle.get_device().split(":", 1)[0] == "npu" and self._infer_precision == "fp16":
--> 343 # transform fp32 model tp fp16 model
344 self._static_fp16_model_file = self.inference_model_path + "-fp16.pdmodel"
345 self._static_fp16_params_file = self.inference_model_path + "-fp16.pdiparams"

File D:\anaconda3\Lib\site-packages\paddlenlp\taskflow\task.py:389, in _convert_dygraph_to_static(self)
386 def _check_input_text(self, inputs):
387 """
388 Check whether the input text meet the requirement.
--> 389 """
390 inputs = inputs[0]
391 if isinstance(inputs, str):

File D:\anaconda3\Lib\site-packages\decorator.py:232, in decorate..fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File D:\anaconda3\Lib\site-packages\paddle\base\wrapped_decorator.py:40, in wrap_decorator..impl(func, *args, **kwargs)
33 @decorator.decorator
34 def impl(
35 func: Callable[_InputT, _RetT1],
36 *args: _InputT.args,
37 **kwargs: _InputT.kwargs,
38 ) -> _RetT2:
39 wrapped_func = decorator_func(func)
---> 40 return wrapped_func(*args, **kwargs)

File D:\anaconda3\Lib\site-packages\paddle\jit\api.py:895, in _run_save_pre_hooks..wrapper(layer, path, input_spec, **configs)
893 for hook in _save_pre_hooks:
894 hook(layer, input_spec, configs)
--> 895 func(layer, path, input_spec, **configs)

File D:\anaconda3\Lib\site-packages\decorator.py:232, in decorate..fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File D:\anaconda3\Lib\site-packages\paddle\base\wrapped_decorator.py:40, in wrap_decorator..impl(func, *args, **kwargs)
33 @decorator.decorator
34 def impl(
35 func: Callable[_InputT, _RetT1],
36 *args: _InputT.args,
37 **kwargs: _InputT.kwargs,
38 ) -> _RetT2:
39 wrapped_func = decorator_func(func)
---> 40 return wrapped_func(*args, **kwargs)

File D:\anaconda3\Lib\site-packages\paddle\base\dygraph\base.py:101, in switch_to_static_graph..impl(*args, **kwargs)
99 def impl(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:
100 with framework._dygraph_guard(None):
--> 101 return func(*args, **kwargs)

File D:\anaconda3\Lib\site-packages\paddle\jit\api.py:1209, in save(layer, path, input_spec, **configs)
1200 property_vals.append(
1201 (
1202 immediate_val,
1203 layer.class.name + '.' + attr_func,
1204 )
1205 )
1206 continue
1208 concrete_program = (
-> 1209 static_func.concrete_program_specify_input_spec(
1210 inner_input_spec,
1211 with_hook=with_hook,
1212 is_prim_infer=is_prim_infer,
1213 )
1214 )
1216 elif 'forward' == attr_func:
1217 if configs.skip_forward:
1218 # do not jit.save forward function

File D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\program_translator.py:1026, in ASTStaticFunction.concrete_program_specify_input_spec(self, input_spec, with_hook, is_prim_infer)
1024 has_input_spec = desired_input_spec is not None
1025 if has_input_spec:
-> 1026 concrete_program, _ = self.get_concrete_program(
1027 *desired_input_spec,
1028 with_hook=with_hook,
1029 is_train=self._is_train_mode(),
1030 is_prim_infer=is_prim_infer,
1031 )
1032 return concrete_program
1033 else:

File D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\program_translator.py:914, in ASTStaticFunction.get_concrete_program(self, *args, **kwargs)
908 (
909 concrete_program,
910 partial_program_layer,
911 ) = self._program_cache.get_program_without_cache(cache_key)
912 else:
913 # 3. check whether hit the cache or build a new program for the input arguments
--> 914 concrete_program, partial_program_layer = self._program_cache[
915 cache_key
916 ]
917 partial_program_layer._debug_name = self._debug_name
918 return concrete_program, partial_program_layer

File D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\program_translator.py:1665, in ProgramCache.getitem(self, item)
1663 self._recent_key = item_id
1664 if item_id not in self._caches:
-> 1665 self._caches[item_id] = self._build_once(item)
1666 # Note: raise warnings if number of traced program is more than max_tracing_count
1667 current_tracing_count = len(self._caches)

File D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\program_translator.py:1603, in ProgramCache._build_once(self, cache_key)
1600 enable_prim = cache_key.kwargs['build_strategy'].build_cinn_pass
1602 if use_pir_api():
-> 1603 concrete_program = ConcreteProgram.pir_from_func_spec(
1604 func_spec=cache_key.function_spec,
1605 input_spec=cache_key.input_args_with_spec,
1606 input_kwargs_spec=cache_key.input_kwargs_with_spec,
1607 class_instance=cache_key.class_instance,
1608 **cache_key.kwargs,
1609 )
1610 else:
1611 concrete_program = ConcreteProgram.from_func_spec(
1612 func_spec=cache_key.function_spec,
1613 input_spec=cache_key.input_args_with_spec,
(...)
1616 **cache_key.kwargs,
1617 )

File D:\anaconda3\Lib\site-packages\decorator.py:232, in decorate..fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)

File D:\anaconda3\Lib\site-packages\paddle\base\wrapped_decorator.py:40, in wrap_decorator..impl(func, *args, **kwargs)
33 @decorator.decorator
34 def impl(
35 func: Callable[_InputT, _RetT1],
36 *args: _InputT.args,
37 **kwargs: _InputT.kwargs,
38 ) -> _RetT2:
39 wrapped_func = decorator_func(func)
---> 40 return wrapped_func(*args, **kwargs)

File D:\anaconda3\Lib\site-packages\paddle\base\dygraph\base.py:101, in switch_to_static_graph..impl(*args, **kwargs)
99 def impl(*args: _InputT.args, **kwargs: _InputT.kwargs) -> _RetT:
100 with framework._dygraph_guard(None):
--> 101 return func(*args, **kwargs)

File D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\program_translator.py:1276, in ConcreteProgram.pir_from_func_spec(func_spec, input_spec, input_kwargs_spec, class_instance, **kwargs)
1274 error_data = getattr(e, error.ERROR_DATA, None)
1275 if error_data:
-> 1276 error_data.raise_new_exception()
1277 raise
1279 # 3. Gets all ParamBases and buffered VarBases in the function

File D:\anaconda3\Lib\site-packages\paddle\jit\dy2static\error.py:454, in ErrorData.raise_new_exception(self)
446 new_exception = self.create_exception()
447 # NOTE(liym27):
448 # Why raise new_exception from None?
449 #
450 # In Python 3, by default, an new exception is raised with trace information of the caught exception.
451 # This only raises new_exception and hides unwanted implementation details from tracebacks of the
452 # caught exception.
--> 454 raise new_exception from None

TypeError: In transformed code:

TypeError: create_forward.<locals>.forward() takes from 1 to 10 positional arguments but 11 were given

`

@tszxyuan123
Copy link
Author

请问这个还是版本问题吗

@tszxyuan123
Copy link
Author

当我设置paddlepaddle==2.6.1,paddlenlp==2.6.1时,就没有再报错了,可以正常使用了

@fengjunkuan2006
Copy link

兄弟,真心感谢你,我被这个问题困扰很久了,看了你的答复换了paddlenlp的版本也解决了。

当我设置paddlepaddle==2.6.1,paddlenlp==2.6.1时,就没有再报错了,可以正常使用了

@tszxyuan123
Copy link
Author

客气,有帮助就好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants