解决EnforceNotMet: grad_op_maker_ should not be null Operator GradOpMaker has not been registered. at

简介: grad_op_maker_ should not be null Operator GradOpMaker

问题描述:使用百度飞桨训练自己搭建的模型时,在运行到:

optimizer=fluid.optimizer.Adam(learning_rate=0.001)

optimizer.minimize(avg_loss)


出现了这样一个错误。如下所示:



---------------------------------------------------------------------------EnforceNotMetTraceback (mostrecentcalllast)<ipython-input-114-71baa0f01aff>in<module>1# 配置优化器(Optimizer Function)  随机梯度下降SGD   学习率为0.0012sgd_optimezer=fluid.optimizer.SGD(learning_rate=0.1)    # learning_rate为学习率---->3sgd_optimezer.minimize(avg_loss)
</opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/decorator.py:decorator-gen-145>inminimize(self, loss, startup_program, parameter_list, no_grad_set, grad_clip)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/wrapped_decorator.pyin__impl__(func, *args, **kwargs)
23def__impl__(func, *args, **kwargs):
24wrapped_func=decorator_func(func)
--->25returnwrapped_func(*args, **kwargs)
2627return__impl__/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/base.pyin__impl__(*args, **kwargs)
85def__impl__(*args, **kwargs):
86with_switch_tracer_mode_guard_(is_train=False):
--->87returnfunc(*args, **kwargs)
8889return__impl__/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/optimizer.pyinminimize(self, loss, startup_program, parameter_list, no_grad_set, grad_clip)
592startup_program=startup_program,
593parameter_list=parameter_list,
-->594no_grad_set=no_grad_set)595596ifgrad_clipisnotNoneandframework.in_dygraph_mode():
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/optimizer.pyinbackward(self, loss, startup_program, parameter_list, no_grad_set, callbacks)
491withprogram_guard(program, startup_program):
492params_grads=append_backward(loss, parameter_list,
-->493no_grad_set, callbacks)
494# Note: since we can't use all_reduce_op now,495#  dgc_op should be the last op of one grad./opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/backward.pyinappend_backward(loss, parameter_list, no_grad_set, callbacks)
569grad_to_var,
570callbacks,
-->571input_grad_names_set=input_grad_names_set)572573# Because calc_gradient may be called multiple times,/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/backward.pyin_append_backward_ops_(block, ops, target_block, no_grad_dict, grad_to_var, callbacks, input_grad_names_set)
308# Getting op's corresponding grad_op309grad_op_desc, op_grad_to_var=core.get_grad_op_desc(
-->310op.desc, cpt.to_text(no_grad_dict[block.idx]), grad_sub_block_list)
311312# If input_grad_names_set is not None, extend grad_op_descs only whenEnforceNotMet: grad_op_maker_shouldnotbenullOperatorGradOpMakerhasnotbeenregistered. at [/paddle/paddle/fluid/framework/op_info.h:69]
PaddlePaddleCallStacks: 
00x7efdea8b2c28pvoidpaddle::platform::EnforceNotMet::Init<std::string>(std::string, charconst*, int) +36010x7efdea8b2f77ppaddle::platform::EnforceNotMet::EnforceNotMet(std::stringconst&, charconst*, int) +8720x7efdea8b3dacppaddle::framework::OpInfo::GradOpMaker() const+10830x7efdea8ac83ep40x7efdea8e1af6p50x559b94463744p_PyMethodDef_RawFastCallKeywords+59660x559b94463861p_PyCFunction_FastCallKeywords+3370x559b944cf2bdp_PyEval_EvalFrameDefault+2017380x559b94413539p_PyEval_EvalCodeWithName+76190x559b94462f57p_PyFunction_FastCallKeywords+903100x559b944cb8ccp_PyEval_EvalFrameDefault+5340110x559b94413539p_PyEval_EvalCodeWithName+761120x559b94462ef5p_PyFunction_FastCallKeywords+805130x559b944ca806p_PyEval_EvalFrameDefault+1046140x559b94413539p_PyEval_EvalCodeWithName+761150x559b94462f57p_PyFunction_FastCallKeywords+903160x559b944cb8ccp_PyEval_EvalFrameDefault+5340170x559b94413539p_PyEval_EvalCodeWithName+761180x559b94414635p_PyFunction_FastCallDict+469190x559b944cc232p_PyEval_EvalFrameDefault+7746200x559b9441381ap_PyEval_EvalCodeWithName+1498210x559b94414635p_PyFunction_FastCallDict+469220x559b944cc232p_PyEval_EvalFrameDefault+7746230x559b9441381ap_PyEval_EvalCodeWithName+1498240x559b94462f57p_PyFunction_FastCallKeywords+903250x559b944ca806p_PyEval_EvalFrameDefault+1046260x559b94413539p_PyEval_EvalCodeWithName+761270x559b94462ef5p_PyFunction_FastCallKeywords+805280x559b944caa93p_PyEval_EvalFrameDefault+1699290x559b94413539p_PyEval_EvalCodeWithName+761300x559b94414424pPyEval_EvalCodeEx+68310x559b9441444cpPyEval_EvalCode+28320x559b944d9f8dp330x559b944635d9p_PyMethodDef_RawFastCallKeywords+233340x559b94463861p_PyCFunction_FastCallKeywords+33350x559b944ceb94p_PyEval_EvalFrameDefault+18340360x559b9446c592p_PyGen_Send+674370x559b944cbe69p_PyEval_EvalFrameDefault+6777380x559b9446c592p_PyGen_Send+674390x559b944cbe69p_PyEval_EvalFrameDefault+6777400x559b9446c592p_PyGen_Send+674410x559b9446357dp_PyMethodDef_RawFastCallKeywords+141420x559b9446b3cfp_PyMethodDescr_FastCallKeywords+79430x559b944cf07cp_PyEval_EvalFrameDefault+19596440x559b94462ccbp_PyFunction_FastCallKeywords+251450x559b944ca806p_PyEval_EvalFrameDefault+1046460x559b94462ccbp_PyFunction_FastCallKeywords+251470x559b944caa93p_PyEval_EvalFrameDefault+1699480x559b94413539p_PyEval_EvalCodeWithName+761490x559b94414860p_PyFunction_FastCallDict+1024500x559b94432e53p_PyObject_Call_Prepend+99510x559b94425dbepPyObject_Call+110520x559b944cc232p_PyEval_EvalFrameDefault+7746530x559b9441381ap_PyEval_EvalCodeWithName+1498540x559b94462f57p_PyFunction_FastCallKeywords+903550x559b944cb8ccp_PyEval_EvalFrameDefault+5340560x559b9446c059p570x559b944635d9p_PyMethodDef_RawFastCallKeywords+233580x559b94463861p_PyCFunction_FastCallKeywords+33590x559b944ceb94p_PyEval_EvalFrameDefault+18340600x559b9441381ap_PyEval_EvalCodeWithName+1498610x559b94462f57p_PyFunction_FastCallKeywords+903620x559b944caa93p_PyEval_EvalFrameDefault+1699630x559b9446c059p640x559b944635d9p_PyMethodDef_RawFastCallKeywords+233650x559b94463861p_PyCFunction_FastCallKeywords+33660x559b944ceb94p_PyEval_EvalFrameDefault+18340670x559b9441381ap_PyEval_EvalCodeWithName+1498680x559b94462f57p_PyFunction_FastCallKeywords+903690x559b944ca806p_PyEval_EvalFrameDefault+1046700x559b9446c059p710x559b944635d9p_PyMethodDef_RawFastCallKeywords+233720x559b94463861p_PyCFunction_FastCallKeywords+33730x559b944ceb94p_PyEval_EvalFrameDefault+18340740x559b9441381ap_PyEval_EvalCodeWithName+1498750x559b94414635p_PyFunction_FastCallDict+469760x559b94432e53p_PyObject_Call_Prepend+99770x559b94425dbepPyObject_Call+110780x559b944cc232p_PyEval_EvalFrameDefault+7746790x559b9446c43cp_PyGen_Send+332800x559b9446357dp_PyMethodDef_RawFastCallKeywords+141810x559b9446b3cfp_PyMethodDescr_FastCallKeywords+79820x559b944cf07cp_PyEval_EvalFrameDefault+19596830x559b94462ccbp_PyFunction_FastCallKeywords+251840x559b944caa93p_PyEval_EvalFrameDefault+1699850x559b9441381ap_PyEval_EvalCodeWithName+1498860x559b94414635p_PyFunction_FastCallDict+469870x559b94522b5bp880x559b9446b8fbp_PyObject_FastCallKeywords+1179890x559b944cee86p_PyEval_EvalFrameDefault+19094900x559b94462ccbp_PyFunction_FastCallKeywords+251910x559b944caa93p_PyEval_EvalFrameDefault+1699920x559b94413d09p_PyEval_EvalCodeWithName+2761930x559b94462f57p_PyFunction_FastCallKeywords+903940x559b944fe383p950x559b94434584p_PyMethodDef_RawFastCallDict+404960x559b944347c1p_PyCFunction_FastCallDict+33970x559b944d0007p_PyEval_EvalFrameDefault+23575980x559b94462ccbp_PyFunction_FastCallKeywords+251990x559b944caa93p_PyEval_EvalFrameDefault+1699


# 配置优化器(Optimizer Function)  随机梯度下降SGD   学习率为0.001# clone操作一定要在定义优化器之前进行!!!   否则也是会报错的。 sgd_optimezer=fluid.optimizer.SGD(learning_rate=0.1)    # learning_rate为学习率sgd_optimezer.minimize(avg_loss)


clone操作一定要在定义优化器之前进行!!! 否则也是会报错的。 解决方法如下:



先配置优化器,再进行 clone 操作。

目录
相关文章
|
Java easyexcel 测试技术
EasyExcel ——NullPointrtException:null at sun.awt.FontConfiguration
EasyExcel 导出 Excel 文档,在开发机可以正常导出。上了测服之后,导出报空指针。
1956 0
EasyExcel ——NullPointrtException:null at sun.awt.FontConfiguration
|
6月前
|
消息中间件 SQL 关系型数据库
实时计算 Flink版操作报错之错误提示“null column 15 Encountered at line 43”如何解决
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
|
JSON 前端开发 API
【跨域报错解决方案】Access to XMLHttpRequest at ‘http://xxx.com/xxx‘ from origin ‘null‘ has been blocked by
【跨域报错解决方案】Access to XMLHttpRequest at ‘http://xxx.com/xxx‘ from origin ‘null‘ has been blocked by
3441 0
|
3月前
|
NoSQL Java Redis
【Azure Spring Cloud】Java Spring Cloud 应用部署到Azure上后,发现大量的 java.lang.NullPointerException: null at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426) at ... 异常
【Azure Spring Cloud】Java Spring Cloud 应用部署到Azure上后,发现大量的 java.lang.NullPointerException: null at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426) at ... 异常
Operator ‘==‘ cannot be applied to ‘int‘, ‘null‘
Operator ‘==‘ cannot be applied to ‘int‘, ‘null‘
springboot制作的登录拦截器出错:java.lang.StackOverflowError: null at javax.servlet.http.HttpServletRequestWra
springboot制作的登录拦截器出错:java.lang.StackOverflowError: null at javax.servlet.http.HttpServletRequestWra
176 0
|
消息中间件 PHP
laravel6 使用rabbitmq报错:Call to a member function make() on null at Queue\\Jobs\\Job.php:215
laravel6 使用rabbitmq报错:Call to a member function make() on null at Queue\\Jobs\\Job.php:215
183 0
Unable to handle kernel NULL pointer dereference at virtual address 00000000问题的解决
今天在编译好内核模块后,安装内核模块memdev.ko的时候,出现了Unable to handle kernel NULL pointer dereference at virtual address 00000000等如图所示的问题:     在百度和google找了很多答案,明显就是跟指针有关系。
3196 0
|
6月前
|
SQL 关系型数据库 MySQL
实时计算 Flink版产品使用合集之从MySQL同步数据到Doris时,历史数据时间字段显示为null,而增量数据部分的时间类型字段正常显示的原因是什么
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStreamAPI、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
6月前
|
SQL 关系型数据库 MySQL
python在mysql中插入或者更新null空值
这段代码是Python操作MySQL数据库的示例。它执行SQL查询从表`a_kuakao_school`中选取`id`,`university_id`和`grade`,当`university_id`大于0时按升序排列。然后遍历结果,根据`row[4]`的值决定`grade`是否为`NULL`。若不为空,`grade`被格式化为字符串;否则,设为`NULL`。接着构造UPDATE语句更新`university`表中对应`id`的`grade`值,并提交事务。重要的是,字符串`NULL`不应加引号,否则更新会失败。
154 2