Skip to content

Commit 759ffca

Browse files
committed
some improvements
test=develop
1 parent 99dffb9 commit 759ffca

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

paddle/fluid/framework/details/build_strategy.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ class ParallelExecutorPassBuilder : public ir::PassBuilder {
8080
};
8181

8282
std::shared_ptr<ir::PassBuilder> BuildStrategy::CreatePassesFromStrategy(
83-
bool from_user) const {
84-
if (finalized_by_user_) {
83+
bool finalize_strategy) const {
84+
if (is_finalized_) {
8585
return pass_builder_;
8686
}
8787
pass_builder_.reset(new ParallelExecutorPassBuilder(*this));
88-
if (from_user) {
89-
finalized_by_user_ = true;
88+
if (finalize_strategy) {
89+
is_finalized_ = true;
9090
}
9191
return pass_builder_;
9292
}

paddle/fluid/framework/details/build_strategy.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,20 @@ struct BuildStrategy {
7575

7676
bool remove_unnecessary_lock_{false};
7777

78+
// NOTE:
79+
// Before you add new options, think if it's a general strategy that works
80+
// with other strategy. If not, the strategy should be created through
81+
// CreatePassesFromStrategy and the pass can be managed separately.
82+
7883
// User normally doesn't need to call this API.
7984
// The PassBuilder allows for more customized insert, remove of passes
8085
// from python side.
8186
// A new PassBuilder is created based on configs defined above and
8287
// passes are owned by the PassBuilder.
8388
std::shared_ptr<ir::PassBuilder> CreatePassesFromStrategy(
84-
bool from_user) const;
89+
bool finalize_strategy) const;
90+
91+
bool IsFinalized() const { return is_finalized_; }
8592

8693
// Apply the passes built by the pass_builder_. The passes will be
8794
// applied to the Program and output an ir::Graph.
@@ -98,7 +105,7 @@ struct BuildStrategy {
98105
#endif
99106

100107
private:
101-
mutable bool finalized_by_user_ = false;
108+
mutable bool is_finalized_ = false;
102109
mutable std::shared_ptr<ir::PassBuilder> pass_builder_;
103110
};
104111

paddle/fluid/pybind/pybind.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ All parameter, weight, gradient are variables in Paddle.
791791
"reduce_strategy",
792792
[](const BuildStrategy &self) { return self.reduce_; },
793793
[](BuildStrategy &self, BuildStrategy::ReduceStrategy strategy) {
794+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
794795
self.reduce_ = strategy;
795796
},
796797
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.
804805
[](const BuildStrategy &self) { return self.gradient_scale_; },
805806
[](BuildStrategy &self,
806807
BuildStrategy::GradientScaleStrategy strategy) {
808+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
807809
self.gradient_scale_ = strategy;
808810
},
809811
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.
815817
"debug_graphviz_path",
816818
[](const BuildStrategy &self) { return self.debug_graphviz_path_; },
817819
[](BuildStrategy &self, const std::string &path) {
820+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
818821
self.debug_graphviz_path_ = path;
819822
},
820823
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.
824827
"enable_data_balance",
825828
[](const BuildStrategy &self) { return self.enable_data_balance_; },
826829
[](BuildStrategy &self, bool b) {
830+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
827831
self.enable_data_balance_ = b;
828832
}) // FIXME(chengudo): enable_data_balance seems not important
829833
.def_property(
@@ -832,6 +836,7 @@ All parameter, weight, gradient are variables in Paddle.
832836
return self.enable_sequential_execution_;
833837
},
834838
[](BuildStrategy &self, bool b) {
839+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
835840
self.enable_sequential_execution_ = b;
836841
},
837842
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.
841846
return self.remove_unnecessary_lock_;
842847
},
843848
[](BuildStrategy &self, bool b) {
849+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
844850
self.remove_unnecessary_lock_ = b;
845851
},
846852
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,6 +856,7 @@ All parameter, weight, gradient are variables in Paddle.
850856
return self.fuse_elewise_add_act_ops_;
851857
},
852858
[](BuildStrategy &self, bool b) {
859+
PADDLE_ENFORCE(!self.IsFinalized(), "BuildStrategy is finlaized.");
853860
self.fuse_elewise_add_act_ops_ = b;
854861
},
855862
R"DOC(The type is BOOL, fuse_elewise_add_act_ops indicate whether

0 commit comments

Comments
 (0)