@@ -650,9 +650,9 @@ All parameter, weight, gradient are variables in Paddle.
650
650
[](ir::Pass &self, const std::string &name, const std::string &attr) {
651
651
self.Set <std::string>(name, new std::string (attr));
652
652
})
653
- .def (" set_int" , [](ir::Pass &self, const std::string &name, int val) {
654
- self.Set <const int >(name, new int (val));
655
- } );
653
+ .def (" set_int" , [](ir::Pass &self, const std::string &name,
654
+ int val) { self.Set <const int >(name, new int (val)); })
655
+ . def ( " type " , &ir::Pass::Type );
656
656
657
657
py::class_<ir::PassBuilder, std::shared_ptr<ir::PassBuilder>> pb (
658
658
m, " PassBuilder" );
@@ -791,6 +791,7 @@ All parameter, weight, gradient are variables in Paddle.
791
791
" reduce_strategy" ,
792
792
[](const BuildStrategy &self) { return self.reduce_ ; },
793
793
[](BuildStrategy &self, BuildStrategy::ReduceStrategy strategy) {
794
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
794
795
self.reduce_ = strategy;
795
796
},
796
797
R"DOC( The type is STR, there are two reduce strategies in ParallelExecutor,
@@ -804,6 +805,7 @@ All parameter, weight, gradient are variables in Paddle.
804
805
[](const BuildStrategy &self) { return self.gradient_scale_ ; },
805
806
[](BuildStrategy &self,
806
807
BuildStrategy::GradientScaleStrategy strategy) {
808
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
807
809
self.gradient_scale_ = strategy;
808
810
},
809
811
R"DOC( The type is STR, there are three ways of defining :math:`loss@grad` in
@@ -815,6 +817,7 @@ All parameter, weight, gradient are variables in Paddle.
815
817
" debug_graphviz_path" ,
816
818
[](const BuildStrategy &self) { return self.debug_graphviz_path_ ; },
817
819
[](BuildStrategy &self, const std::string &path) {
820
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
818
821
self.debug_graphviz_path_ = path;
819
822
},
820
823
R"DOC( The type is STR, debug_graphviz_path indicate the path that
@@ -824,6 +827,7 @@ All parameter, weight, gradient are variables in Paddle.
824
827
" enable_data_balance" ,
825
828
[](const BuildStrategy &self) { return self.enable_data_balance_ ; },
826
829
[](BuildStrategy &self, bool b) {
830
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
827
831
self.enable_data_balance_ = b;
828
832
}) // FIXME(chengudo): enable_data_balance seems not important
829
833
.def_property (
@@ -832,6 +836,7 @@ All parameter, weight, gradient are variables in Paddle.
832
836
return self.enable_sequential_execution_ ;
833
837
},
834
838
[](BuildStrategy &self, bool b) {
839
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
835
840
self.enable_sequential_execution_ = b;
836
841
},
837
842
R"DOC( The type is BOOL. If set True, the execution order of ops would be the same as what is in the program. Default False.)DOC" )
@@ -841,6 +846,7 @@ All parameter, weight, gradient are variables in Paddle.
841
846
return self.remove_unnecessary_lock_ ;
842
847
},
843
848
[](BuildStrategy &self, bool b) {
849
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
844
850
self.remove_unnecessary_lock_ = b;
845
851
},
846
852
R"DOC( The type is BOOL. If set True, some locks in GPU ops would be released and ParallelExecutor would run faster. Default False.)DOC" )
@@ -850,15 +856,19 @@ All parameter, weight, gradient are variables in Paddle.
850
856
return self.fuse_elewise_add_act_ops_ ;
851
857
},
852
858
[](BuildStrategy &self, bool b) {
859
+ PADDLE_ENFORCE (!self.IsFinalized (), " BuildStrategy is finlaized." );
853
860
self.fuse_elewise_add_act_ops_ = b;
854
861
},
855
862
R"DOC( The type is BOOL, fuse_elewise_add_act_ops indicate whether
856
863
to fuse elementwise_add_op and activation_op,
857
864
it may make the execution faster. Default False)DOC" )
858
- .def (" _create_passes_from_strategy " ,
865
+ .def (" _finalize_strategy_and_create_passes " ,
859
866
[](BuildStrategy &self) -> std::shared_ptr<ir::PassBuilder> {
860
- return self.CreatePassesFromStrategy ();
861
- });
867
+ return self.CreatePassesFromStrategy (true );
868
+ },
869
+ R"DOC( Allow user to customized passes. Normally model-specific
870
+ optimization passes should be defined in this way. BuildStrategy
871
+ cannot be updated after being finalized.)DOC" );
862
872
863
873
pe.def (py::init<const std::vector<platform::Place> &,
864
874
const std::unordered_set<std::string> &,
0 commit comments