Add user-friendly error message in optimizer ops to give a hint about the position sensitive problem of run(startup_program) !19605
Created by: chenwhql
When run(startup_program)
is executed before optimizer.minimize
, because the parameters added by optimizer
are not initialized, which will cause run failed. The error message is like:
this error occur to RunTimeInferShape
phase. the program doesn't check whether the tensor in LearningRate
variable is initialized, and get the dim of variable used to compare directly, which is the reason that this error messgae is not easy to understand.
So this PR add extra error message in related ops to give users a hint, the related ops are in paddle/fluid/operators/optimizers
. I just add error hint in the first persistable var checking. The result after changed is like:
related changed op and corresponding optimizer:
- sgd_op: SGDOptimizer
- momentum_op: MomentumOptimizer, DGCMomentumOptimizer, LarsMomentumOptimizer
- adagrad_op: AdagradOptimizer
- adam_op: AdamOptimizer, LambOptimizer
- adamax_op: AdamaxOptimizer
- decayed_adagrad_op: DecayedAdagradOptimizer
- adadelta_op: AdadeltaOptimizer
- ftrl_op: FtrlOptimizer
no need to change op:
- rmsprop_op: RMSPropOptimizer
I have confirmed that all optimizer can trigger expected error hint when the exe.run(startup_program)
is executed before optimizer.minimize
.
The unittests code: test_optimizer_vars_init.py