@@ -123,22 +123,22 @@ bool AnalysisPredictor::PrepareProgram(
123
123
if (!program) {
124
124
if (!LoadProgramDesc ()) return false ;
125
125
126
+ // If not cloned, the parameters should be loaded.
127
+ // If config_.ir_optim() is True, parameters is loaded in
128
+ // OptimizeInferenceProgram(), but other persistable variables
129
+ // (like RAW type var) are not created in scope.
130
+ // If config_.ir_optim() is False, parameters is loaded in LoadParameters(),
131
+ // still need to create other persistable variables.
132
+ // So in both case, create persistable variables at first.
133
+ executor_->CreateVariables (*inference_program_, 0 , true , sub_scope_);
134
+
126
135
// Optimize the program, and load parameters and modify them in the
127
136
// scope_.
128
137
// This will change the scope_ address.
129
138
if (config_.ir_optim ()) {
130
139
status_ir_optim_enabled_ = true ;
131
140
OptimizeInferenceProgram ();
132
141
} else {
133
- // If the parent_scope is passed, we assert that the persistable variables
134
- // are already created, so just create the no persistable variables.
135
-
136
- // If not cloned, the parameters should be loaded
137
- // OptimizeInferenceProgram.
138
- // So in both cases, just the local variables are needed to load, not the
139
- // parematers.
140
- executor_->CreateVariables (*inference_program_, 0 , true , sub_scope_);
141
-
142
142
// Load parameters
143
143
LOG (INFO) << " load parameters " ;
144
144
LoadParameters ();
@@ -376,7 +376,7 @@ void AnalysisPredictor::OptimizeInferenceProgram() {
376
376
}
377
377
argument_.SetIrAnalysisPasses (passes);
378
378
argument_.SetAnalysisPasses (config_.pass_builder ()->AnalysisPasses ());
379
- argument_.SetScopeNotOwned (const_cast <framework::Scope *>( scope_.get () ));
379
+ argument_.SetScopeNotOwned (scope_.get ());
380
380
Analyzer ().Run (&argument_);
381
381
382
382
PADDLE_ENFORCE (argument_.scope_valid ());
0 commit comments