Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • Issue
  • #26058

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
大约 2 年 前同步成功

通知 2325
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 1423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 1,423
    • Issue 1,423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
    • 合并请求 543
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 8月 09, 2020 by saxon_zh@saxon_zhGuest

多线程预测报错

Created by: ARDUJS

运行环境

  • PaddlePaddle 1.7.2
  • paddlehub = 1.6.0
  • python 3.7.5
  • linux

运行代码

重写了reader和task函数

import paddlehub as hub
import config as user_config
import MultiSequenceLabelReader as R
from MultiSequenceLabelReader import MultiSequenceLabelReader
from multi_sequence_task import MultiSequenceTask
# from Main import M

import _thread
import threading



model_name = "chinese-electra-small"
module = hub.Module(name=model_name)
inputs, outputs, program = module.context(
   trainable=False, max_seq_len=256)

class label_map(object):
   def get_labels(self):
       return R.entity2id


reader = MultiSequenceLabelReader(
       dataset=label_map(),
       vocab_path=module.get_vocab_path(),
       max_seq_len=user_config.max_sequence_len,
       sp_model_path=module.get_spm_path(),
       word_dict_path=module.get_word_dict_path())

sequence_output = outputs["sequence_output"]

# 设置模型program需要输入的变量feed_list
# 必须按照以下顺序设置
feed_list = [
   inputs["input_ids"].name, inputs["position_ids"].name,
   inputs["segment_ids"].name, inputs["input_mask"].name
]


# In[8]:


# 选择优化策略
strategy = hub.AdamWeightDecayStrategy(
   warmup_proportion=user_config.warmup_proportion,
   weight_decay=user_config.weight_decay,
   learning_rate=user_config.learning_rate)


# In[10]:


# 配置运行设置
config = hub.RunConfig(
       eval_interval=user_config.eval_step,
       save_ckpt_interval=user_config.model_save_step,
       use_data_parallel=user_config.use_data_parallel,
       use_cuda=user_config.use_cuda,
       num_epoch=user_config.num_epoch,
       batch_size=user_config.batch_size,
       checkpoint_dir=user_config.checkpoint_dir,
       strategy=strategy)

seq_label_task = MultiSequenceTask(
           data_reader=reader,
           feature=sequence_output,
           feed_list=feed_list,
           max_seq_len=user_config.max_sequence_len,
           num_classes=len(R.entity2id),
           config=config,
           add_crf=True)


def my_thread_0():
   seq_label_task.predict(["你好啊"])

def my_thread_1():
   seq_label_task.predict(["你好啊"])


t0 = threading.Thread(target=my_thread_0)
t1 = threading.Thread(target=my_thread_1)

t0.start()
t1.start()
t0.join()
t1.join()


seq_label_task.predict(["你好啊"])

报错信息

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py:789: UserWarning: The following exception is not an EOF exception.
  "The following exception is not an EOF exception.")
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "thread_demo.py", line 78, in my_thread_1
    seq_label_task.predict(["你好啊"])
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 1010, in predict
    run_states = self._run()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 1077, in _run
    return_numpy=self.return_numpy)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 790, in run
    six.reraise(*sys.exc_info())
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/six.py", line 693, in reraise
    raise value
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 785, in run
    use_program_cache=use_program_cache)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 838, in _run_impl
    use_program_cache=use_program_cache)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py", line 912, in _run_program
    fetch_var_name)
paddle.fluid.core_avx.EnforceNotMet: 

--------------------------------------------
C++ Call Stacks (More useful to developers):
--------------------------------------------
0   std::string paddle::platform::GetTraceBackString<std::string const&>(std::string const&, char const*, int)
1   paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int)
2   paddle::operators::MulOp::InferShape(paddle::framework::InferShapeContext*) const
3   paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, paddle::platform::Place const&, paddle::framework::RuntimeContext*) const
4   paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, paddle::platform::Place const&) const
5   paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, paddle::platform::Place const&)
6   paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool)
7   paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator<std::string> > const&, bool, bool)

------------------------------------------
Python Call Stacks (More useful to users):
------------------------------------------
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/framework.py", line 2525, in append_op
    attrs=kwargs.get("attrs", None))
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/common/paddle_helper.py", line 166, in _copy_vars_and_ops_in_blocks
    to_block.append_op(**op_info)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/common/paddle_helper.py", line 274, in clone_program
    dest_program.global_block())
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 409, in _build_env
    self.env.main_program, for_test=True)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 507, in main_program
    self._build_env()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 842, in load_parameters
    self.exe, dirname, self.main_program, predicate=if_exist)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 377, in init_if_load_best_model
    self.load_parameters(best_model_path)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/finetune/task/base_task.py", line 1006, in predict
    self.init_if_load_best_model()
  File "thread_demo.py", line 75, in my_thread_0
    seq_label_task.predict(["你好啊"])
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/threading.py", line 890, in _bootstrap
    self._bootstrap_inner()

----------------------
Error Message Summary:
----------------------
PreconditionNotMetError: The Input variable Y(fc_0.w_0) has not been initialized. You may need to confirm if you put exe.run(startup_program) after optimizer.minimize function.
  [Hint: Expected framework::product(y_dims) != 0, but received framework::product(y_dims):0 == 0:0.] at (/paddle/paddle/fluid/operators/mul_op.cc:61)
  [operator < mul > error]
指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/Paddle#26058
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7