From 97d053346a53d5f99eb415d61b2facac9cd75106 Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Fri, 7 May 2021 14:43:55 +0800 Subject: [PATCH 01/10] fix cpp lint Change-Id: Id15806d3ae86e0a1ab9730560a14bb6a4da4661f --- .../distributed/fleet/base/fleet_base.py | 48 ++++++++++++++ .../distributed/fleet/runtime/the_one_ps.py | 63 +++++++++---------- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/python/paddle/distributed/fleet/base/fleet_base.py b/python/paddle/distributed/fleet/base/fleet_base.py index 9e200f4ee5f6e..75aa5c38d0af8 100644 --- a/python/paddle/distributed/fleet/base/fleet_base.py +++ b/python/paddle/distributed/fleet/base/fleet_base.py @@ -578,6 +578,48 @@ def stop_worker(self): """ self._runtime_handle._stop_worker() + def save(self, dirname, feed=[], fetch=[], **configs): + inference = True + + if not feed and not fetch: + inference = False + + place = paddle.CPUPlace() + executor = paddle.static.Executor(place) + + if inference: + feeded_var_names = [] + fetch_var_names = [] + + for var in feed: + if isinstance(var, str): + feeded_var_names.append(var) + elif isinstance(var, paddle.static.Variable): + feeded_var_names.append(var.name) + else: + raise ValueError("feed must be [str|Variable]") + + for var in fetch: + if isinstance(var, str): + fetch_var_names.append(var) + elif isinstance(var, paddle.static.Variable): + fetch_var_names.append(var.name) + else: + raise ValueError("feed must be [str|Variable]") + + fetch_vars = [ + paddle.static.default_main_program().global_block().var(name) + for name in fetch_var_names + ] + + self.save_inference_model(executor, dirname, feeded_var_names, + fetch_vars) + else: + increment_mode = 0 + if "mode" in configs: + increment_mode = int(configs["mode"]) + self.save_persistables(executor, dirname, mode=increment_mode) + def save_inference_model(self, executor, dirname, @@ -605,6 +647,9 @@ def save_inference_model(self, fleet.init_server() """ + warnings.warn( + "'save_inference_model' is a deprecated, will be deleted after v2.2.0, Please use fleet.save instead." + ) self._runtime_handle._save_inference_model( executor, dirname, feeded_var_names, target_vars, main_program, @@ -651,6 +696,9 @@ def save_persistables(self, executor, dirname, main_program=None, mode=0): fleet.save_persistables(exe, "dirname", paddle.static.default_main_program()) """ + warnings.warn( + "'save_persistables' is a deprecated, will be deleted after v2.2.0, Please use fleet.save instead." + ) self._runtime_handle._save_persistables(executor, dirname, main_program, mode) diff --git a/python/paddle/distributed/fleet/runtime/the_one_ps.py b/python/paddle/distributed/fleet/runtime/the_one_ps.py index 24b83662c9dbf..ce95bcd6de719 100644 --- a/python/paddle/distributed/fleet/runtime/the_one_ps.py +++ b/python/paddle/distributed/fleet/runtime/the_one_ps.py @@ -951,11 +951,11 @@ def _save_distributed_persistables(self, TheOnePSRuntime.__exclude_vars(saved_varnames), main_program.list_vars())) - fluid.io.save_vars( - executor, - main_program=main_program, - dirname=dirname, - vars=remaining_vars) + import paddle + for var in remaining_vars: + tensor = var.get_value() + paddle.save( + tensor, os.path.join(dirname, var.name), use_binary_format=True) def _ps_inference_save_persistables(self, executor, @@ -976,20 +976,19 @@ def _ps_inference_save_persistables(self, if isinstance(executor, ParallelExecutor): raise TypeError( - "in fleet.save_persistables() function, executor must be as Executor type, ParallelExecutor is not allowed" + "in fleet.save() function, executor must be as Executor type, ParallelExecutor is not allowed" ) if not isinstance(executor, Executor): raise TypeError( - "in fleet.save_persistables() function, executor must be as Executor type" - ) + "in fleet.save() function, executor must be as Executor type") if main_program is None: main_program = self.compiled_strategy.get_origin_ps_main_program() if isinstance(main_program, CompiledProgram): raise TypeError( - "in fleet.save_persistables() function, main_program must be as Program type, CompiledProgram is not allowed" + "in fleet.save() function, main_program must be as Program type, CompiledProgram is not allowed" ) # Todo(MrChengmo): Save optimizer status @@ -1011,37 +1010,33 @@ def _ps_inference_save_inference_model(self, if isinstance(executor, ParallelExecutor): raise TypeError( - "in fleet.save_inference_model() function, executor must be as Executor type, ParallelExecutor is not allowed" + "in fleet.save() function, executor must be as Executor type, ParallelExecutor is not allowed" ) if not isinstance(executor, Executor): raise TypeError( - "in fleet.save_inference_model() function, executor must be as Executor type" + "in fleet.save() function, executor must be as Executor type") + + program = self.origin_main_program if main_program is None else main_program + + if isinstance(program, CompiledProgram): + raise TypeError( + "in fleet.save() function, main_program must be as Program type, CompiledProgram is not allowed" ) - if main_program is not None: - if isinstance(main_program, CompiledProgram): - raise TypeError( - "in fleet.save_inference_model() function, main_program must be as Program type, CompiledProgram is not allowed" - ) - fluid.io.save_inference_model(dirname, feeded_var_names, - target_vars, executor, main_program, - None, None, export_for_deployment) - else: - fluid.io.save_inference_model(dirname, feeded_var_names, - target_vars, executor, - self.origin_main_program, None, None, - export_for_deployment, True) - model_basename = "__model__" - model_filename = os.path.join(dirname, model_basename) - - with open(model_filename, "rb") as f: - program_desc_str = f.read() - - program = Program.parse_from_string(program_desc_str) - program._copy_dist_param_info_from(fluid.default_main_program()) - self._ps_inference_save_persistables(executor, dirname, program, - mode) + import paddle + feed_vars = [ + program.global_block().var(name) for name in feeded_var_names + ] + infer_program = paddle.static.normalize_program(program, feed_vars, + target_vars) + infer_program._copy_dist_param_info_from(program) + + model_basename = "__model__" + model_basename = os.path.join(dirname, model_basename) + paddle.save(infer_program, model_basename) + + self._ps_inference_save_persistables(executor, dirname, program, mode) def _save_inference_model(self, *args, **kwargs): self._ps_inference_save_inference_model(*args, **kwargs) From 732bb5be659229699e77b757720fa7aa9abd536a Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Mon, 10 May 2021 11:01:49 +0800 Subject: [PATCH 02/10] fix save/load with unexpected value Change-Id: I6b51d935a57cd8629d47bcb1a7677c691115b56b --- .../distributed/table/common_sparse_table.cc | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/paddle/fluid/distributed/table/common_sparse_table.cc b/paddle/fluid/distributed/table/common_sparse_table.cc index 718fce9950719..43a43e8c342d9 100644 --- a/paddle/fluid/distributed/table/common_sparse_table.cc +++ b/paddle/fluid/distributed/table/common_sparse_table.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "paddle/fluid/distributed/table/common_sparse_table.h" - #include +#include "boost/lexical_cast.hpp" #include "glog/logging.h" #include "paddle/fluid/platform/enforce.h" @@ -25,7 +25,8 @@ class ValueBlock; } // namespace distributed } // namespace paddle -#define PSERVER_SAVE_SUFFIX "_txt" +#define PSERVER_SAVE_SUFFIX ".shard" +using boost::lexical_cast; namespace paddle { namespace distributed { @@ -100,7 +101,7 @@ struct Meta { }; void ProcessALine(const std::vector& columns, const Meta& meta, - std::vector>* values) { + const int64_t id, std::vector>* values) { auto colunmn_size = columns.size(); auto load_values = paddle::string::split_string(columns[colunmn_size - 1], ","); @@ -116,8 +117,19 @@ void ProcessALine(const std::vector& columns, const Meta& meta, "The data format in txt does not meet the field " "requirements defined in meta")); - std::transform(start, end, std::back_inserter(val), - [](std::string va) { return std::stof(va); }); + std::transform(start, end, std::back_inserter(val), [](std::string va) { + float v = 0.0; + + try { + v = lexical_cast(va); + } catch (boost::bad_lexical_cast) { + VLOG(0) << "id: " << id << " get unexpected value: " << va + << " and be reset to: 0.0" + << " with meta: " << meta.names[x]; + } + return v; + }); + values->push_back(val); offset += meta.dims[x]; } @@ -126,25 +138,29 @@ void ProcessALine(const std::vector& columns, const Meta& meta, int64_t SaveToText(std::ostream* os, std::shared_ptr block, const int mode) { int64_t save_num = 0; + for (auto& table : block->values_) { for (auto& value : table) { if (mode == SaveMode::delta && !value.second->need_save_) { continue; } - save_num += 1; - auto* vs = value.second->data_.data(); + ++save_num; + std::stringstream ss; + auto* vs = value.second->data_.data(); + auto id = value.first; + ss << id << "\t" << value.second->count_ << "\t" << value.second->unseen_days_ << "\t" << value.second->is_entry_ << "\t"; - for (int i = 0; i < block->value_length_; i++) { - ss << vs[i]; - ss << ","; + for (int i = 0; i < block->value_length_ - 1; i++) { + ss << std::to_string(vs[i]) << ","; } + ss << std::to_string(vs[block->value_length_ - 1]); ss << "\n"; os->write(ss.str().c_str(), sizeof(char) * ss.str().size()); @@ -170,7 +186,7 @@ int64_t LoadFromText(const std::string& valuepath, const std::string& metapath, while (std::getline(file, line)) { auto values = paddle::string::split_string(line, "\t"); - auto id = std::stoull(values[0]); + auto id = lexical_cast(values[0]); if (id % pserver_num != pserver_id) { VLOG(3) << "will not load " << values[0] << " from " << valuepath @@ -187,10 +203,12 @@ int64_t LoadFromText(const std::string& valuepath, const std::string& metapath, block->Init(id, false); VALUE* value_instant = block->GetValue(id); + if (values.size() == 5) { - value_instant->count_ = std::stoi(values[1]); - value_instant->unseen_days_ = std::stoi(values[2]); - value_instant->is_entry_ = static_cast(std::stoi(values[3])); + value_instant->count_ = lexical_cast(values[1]); + value_instant->unseen_days_ = lexical_cast(values[2]); + value_instant->is_entry_ = + static_cast(lexical_cast(values[3])); } std::vector block_values = block->Get(id, meta.names, meta.dims); @@ -475,7 +493,7 @@ int32_t CommonSparseTable::pull_sparse_ptr(char** pull_values, auto* value = block->InitGet(id); // std::copy_n(value + param_offset_, param_dim_, // pull_values + param_dim_ * offset); - pull_values[offset] = (char*)value; + pull_values[offset] = reinterpret_cast(value); } return 0; From 35b755bf459350183ba4db2a09d9665c86d2f7cc Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Mon, 10 May 2021 13:52:12 +0800 Subject: [PATCH 03/10] fix save/load with unexpected value Change-Id: I02bb2cdba33568569060588b26fe4c2b9557aa06 --- paddle/fluid/distributed/table/common_sparse_table.cc | 9 ++++----- python/paddle/distributed/fleet/runtime/the_one_ps.py | 6 ++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/distributed/table/common_sparse_table.cc b/paddle/fluid/distributed/table/common_sparse_table.cc index 43a43e8c342d9..a4f672c2963a8 100644 --- a/paddle/fluid/distributed/table/common_sparse_table.cc +++ b/paddle/fluid/distributed/table/common_sparse_table.cc @@ -117,15 +117,14 @@ void ProcessALine(const std::vector& columns, const Meta& meta, "The data format in txt does not meet the field " "requirements defined in meta")); - std::transform(start, end, std::back_inserter(val), [](std::string va) { + std::transform(start, end, std::back_inserter(val), [id](std::string va) { float v = 0.0; try { v = lexical_cast(va); - } catch (boost::bad_lexical_cast) { + } catch (boost::bad_lexical_cast& e) { VLOG(0) << "id: " << id << " get unexpected value: " << va - << " and be reset to: 0.0" - << " with meta: " << meta.names[x]; + << " and be reset to: 0.0"; } return v; }); @@ -198,7 +197,7 @@ int64_t LoadFromText(const std::string& valuepath, const std::string& metapath, auto block = blocks->at(shard_id); std::vector> kvalues; - ProcessALine(values, meta, &kvalues); + ProcessALine(values, meta, id, &kvalues); block->Init(id, false); diff --git a/python/paddle/distributed/fleet/runtime/the_one_ps.py b/python/paddle/distributed/fleet/runtime/the_one_ps.py index ce95bcd6de719..0168819815931 100644 --- a/python/paddle/distributed/fleet/runtime/the_one_ps.py +++ b/python/paddle/distributed/fleet/runtime/the_one_ps.py @@ -1017,14 +1017,16 @@ def _ps_inference_save_inference_model(self, raise TypeError( "in fleet.save() function, executor must be as Executor type") - program = self.origin_main_program if main_program is None else main_program + import paddle + + program = paddle.static.default_main_program( + ) if main_program is None else main_program if isinstance(program, CompiledProgram): raise TypeError( "in fleet.save() function, main_program must be as Program type, CompiledProgram is not allowed" ) - import paddle feed_vars = [ program.global_block().var(name) for name in feeded_var_names ] From 309aa3acbd7bd904f8f23814a448fd876e390239 Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Mon, 10 May 2021 14:07:16 +0800 Subject: [PATCH 04/10] fix save/load with unexpected value Change-Id: I3e4c0d3abc73b7de65a9a02a8036979872d0c2e6 --- python/paddle/distributed/fleet/runtime/the_one_ps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/distributed/fleet/runtime/the_one_ps.py b/python/paddle/distributed/fleet/runtime/the_one_ps.py index 0168819815931..4f862d2638c8f 100644 --- a/python/paddle/distributed/fleet/runtime/the_one_ps.py +++ b/python/paddle/distributed/fleet/runtime/the_one_ps.py @@ -30,7 +30,7 @@ def conv_indent(indent): return "".join([" "] * indent) -PSERVER_SAVE_SUFFIX = "_txt" +PSERVER_SAVE_SUFFIX = ".shard" class Accessor: From 1ad1dbe930a09e77aa05b8f996b4fa66d756d133 Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Mon, 10 May 2021 14:17:25 +0800 Subject: [PATCH 05/10] fix save/load with unexpected value Change-Id: Iee40943a91d096da4f161fffd842f670956e16e1 --- python/paddle/distributed/fleet/runtime/the_one_ps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/distributed/fleet/runtime/the_one_ps.py b/python/paddle/distributed/fleet/runtime/the_one_ps.py index 4f862d2638c8f..615f63607b9c6 100644 --- a/python/paddle/distributed/fleet/runtime/the_one_ps.py +++ b/python/paddle/distributed/fleet/runtime/the_one_ps.py @@ -914,7 +914,7 @@ def _save_sparse_params(self, executor, dirname, context, main_program, self.compiled_strategy.origin_main_program, True) values = [] for id, names in context.items(): - if names not in distributed_varnames: + if names[0] not in distributed_varnames: # only save sparse param to local self._worker.recv_and_save_model(id, dirname) # save sparse & distributed param on server From 618a416189c4c283cf4493d63eb2a800b35d89ce Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Mon, 10 May 2021 14:59:28 +0800 Subject: [PATCH 06/10] fix save and user interface Change-Id: Id153ff02306a27b5d99c4f112a9fae38d0a6f64b --- python/paddle/distributed/fleet/__init__.py | 1 + .../distributed/fleet/base/fleet_base.py | 7 +++--- .../tests/unittests/test_fleet_base_2.py | 24 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/python/paddle/distributed/fleet/__init__.py b/python/paddle/distributed/fleet/__init__.py index 403a02496afaa..fbf2c7920cd9b 100644 --- a/python/paddle/distributed/fleet/__init__.py +++ b/python/paddle/distributed/fleet/__init__.py @@ -62,6 +62,7 @@ run_server = fleet.run_server stop_worker = fleet.stop_worker distributed_optimizer = fleet.distributed_optimizer +save = fleet.save save_inference_model = fleet.save_inference_model save_persistables = fleet.save_persistables minimize = fleet.minimize diff --git a/python/paddle/distributed/fleet/base/fleet_base.py b/python/paddle/distributed/fleet/base/fleet_base.py index 75aa5c38d0af8..314d9fb5d01e5 100644 --- a/python/paddle/distributed/fleet/base/fleet_base.py +++ b/python/paddle/distributed/fleet/base/fleet_base.py @@ -612,13 +612,14 @@ def save(self, dirname, feed=[], fetch=[], **configs): for name in fetch_var_names ] - self.save_inference_model(executor, dirname, feeded_var_names, - fetch_vars) + self._runtime_handle._save_inference_model( + executor, dirname, feeded_var_names, fetch_vars, None, True, 0) else: increment_mode = 0 if "mode" in configs: increment_mode = int(configs["mode"]) - self.save_persistables(executor, dirname, mode=increment_mode) + self._runtime_handle._save_persistables( + executor, dirname, main_program=None, mode=increment_mode) def save_inference_model(self, executor, diff --git a/python/paddle/fluid/tests/unittests/test_fleet_base_2.py b/python/paddle/fluid/tests/unittests/test_fleet_base_2.py index d666ea6740be1..4cf363ef8e1aa 100644 --- a/python/paddle/fluid/tests/unittests/test_fleet_base_2.py +++ b/python/paddle/fluid/tests/unittests/test_fleet_base_2.py @@ -14,6 +14,8 @@ import unittest import paddle +paddle.enable_static() + import os import paddle.fluid as fluid @@ -21,18 +23,16 @@ class TestFleetBase(unittest.TestCase): def setUp(self): os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_TRAINER_ENDPOINTS"] = "127.0.0.1:36001" os.environ["PADDLE_TRAINERS_NUM"] = "2" os.environ["PADDLE_PSERVERS_IP_PORT_LIST"] = \ - "127.0.0.1:36001,127.0.0.2:36001" + "127.0.0.1:36001,127.0.0.2:36001" def test_ps_minimize(self): import paddle import paddle.distributed.fleet as fleet - os.environ["TRAINING_ROLE"] = "PSERVER" - os.environ["POD_IP"] = "127.0.0.1" - os.environ["PADDLE_PORT"] = "36001" + os.environ["TRAINING_ROLE"] = "TRAINER" + os.environ["PADDLE_TRAINER_ID"] = "1" input_x = paddle.fluid.layers.data( name="x", shape=[32], dtype='float32') @@ -47,24 +47,24 @@ def test_ps_minimize(self): role = fleet.PaddleCloudRoleMaker(is_collective=False) fleet.init(role) + strategy = paddle.distributed.fleet.DistributedStrategy() strategy.a_sync = False + strategy.a_sync_configs = {"launch_barrier": False} + optimizer = paddle.optimizer.SGD(learning_rate=0.001) optimizer = fleet.distributed_optimizer(optimizer, strategy=strategy) optimizer.minimize(avg_cost) place = fluid.CPUPlace() exe = fluid.Executor(place) + exe.run(paddle.static.default_startup_program()) pe = fluid.ParallelExecutor(use_cuda=False, loss_name=avg_cost.name) compiled_prog = fluid.compiler.CompiledProgram( fluid.default_main_program()) - self.assertRaises( - Exception, - fleet.save_inference_model, - dirname='/tmp/', - feeded_var_names=['x', 'y'], - target_vars=[avg_cost], - executor=pe) + + fleet.save(dirname="/tmp", feed=['x', 'y'], fetch=[avg_cost]) + fleet.save(dirname="/tmp") self.assertRaises( Exception, From b17ced6b3377d0f668aff9039b4de42688b987db Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Tue, 11 May 2021 10:57:56 +0800 Subject: [PATCH 07/10] fix save and user interface Change-Id: I9f05d5cc7583a5d2d25bbbc0b7df9e65d3732005 --- python/paddle/fluid/tests/unittests/test_fleet_base_2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/paddle/fluid/tests/unittests/test_fleet_base_2.py b/python/paddle/fluid/tests/unittests/test_fleet_base_2.py index 4cf363ef8e1aa..94fccb5fe9e45 100644 --- a/python/paddle/fluid/tests/unittests/test_fleet_base_2.py +++ b/python/paddle/fluid/tests/unittests/test_fleet_base_2.py @@ -64,6 +64,7 @@ def test_ps_minimize(self): fluid.default_main_program()) fleet.save(dirname="/tmp", feed=['x', 'y'], fetch=[avg_cost]) + fleet.save(dirname="/tmp", feed=[input_x, input_y], fetch=[avg_cost]) fleet.save(dirname="/tmp") self.assertRaises( From 0a72b456bb2010db4bbd97c1c107b06ec1dc869a Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Tue, 11 May 2021 17:07:21 +0800 Subject: [PATCH 08/10] fix save and user interface Change-Id: I34f10b2f12625a81b7e5b1d661828906c1112fae --- python/paddle/distributed/fleet/runtime/the_one_ps.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/paddle/distributed/fleet/runtime/the_one_ps.py b/python/paddle/distributed/fleet/runtime/the_one_ps.py index 615f63607b9c6..e8a1f5e0ad060 100644 --- a/python/paddle/distributed/fleet/runtime/the_one_ps.py +++ b/python/paddle/distributed/fleet/runtime/the_one_ps.py @@ -1018,9 +1018,7 @@ def _ps_inference_save_inference_model(self, "in fleet.save() function, executor must be as Executor type") import paddle - - program = paddle.static.default_main_program( - ) if main_program is None else main_program + program = self.origin_main_program if main_program is None else main_program if isinstance(program, CompiledProgram): raise TypeError( @@ -1030,15 +1028,18 @@ def _ps_inference_save_inference_model(self, feed_vars = [ program.global_block().var(name) for name in feeded_var_names ] + infer_program = paddle.static.normalize_program(program, feed_vars, target_vars) + infer_program._copy_dist_param_info_from(program) model_basename = "__model__" model_basename = os.path.join(dirname, model_basename) paddle.save(infer_program, model_basename) - self._ps_inference_save_persistables(executor, dirname, program, mode) + self._ps_inference_save_persistables(executor, dirname, infer_program, + mode) def _save_inference_model(self, *args, **kwargs): self._ps_inference_save_inference_model(*args, **kwargs) From e54b06a0bf12884cd26a9dd4dc804f425d48321c Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Tue, 11 May 2021 17:12:51 +0800 Subject: [PATCH 09/10] fix save and user interface Change-Id: Icf92227ebb291857f840e1d86d8554b3f9639cea --- python/paddle/distributed/fleet/__init__.py | 2 +- python/paddle/distributed/fleet/base/fleet_base.py | 12 ++++++------ .../fluid/tests/unittests/test_fleet_base_2.py | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/python/paddle/distributed/fleet/__init__.py b/python/paddle/distributed/fleet/__init__.py index fbf2c7920cd9b..4a65d3d17b9f4 100644 --- a/python/paddle/distributed/fleet/__init__.py +++ b/python/paddle/distributed/fleet/__init__.py @@ -62,7 +62,7 @@ run_server = fleet.run_server stop_worker = fleet.stop_worker distributed_optimizer = fleet.distributed_optimizer -save = fleet.save +# save = fleet.save // will add it later, and remove save_inference_model/save_persistables save_inference_model = fleet.save_inference_model save_persistables = fleet.save_persistables minimize = fleet.minimize diff --git a/python/paddle/distributed/fleet/base/fleet_base.py b/python/paddle/distributed/fleet/base/fleet_base.py index 314d9fb5d01e5..c4bc0b73b9a22 100644 --- a/python/paddle/distributed/fleet/base/fleet_base.py +++ b/python/paddle/distributed/fleet/base/fleet_base.py @@ -648,9 +648,9 @@ def save_inference_model(self, fleet.init_server() """ - warnings.warn( - "'save_inference_model' is a deprecated, will be deleted after v2.2.0, Please use fleet.save instead." - ) + # warnings.warn( + # "'save_inference_model' is a deprecated, will be deleted after v2.2.0, Please use fleet.save instead." + # ) self._runtime_handle._save_inference_model( executor, dirname, feeded_var_names, target_vars, main_program, @@ -697,9 +697,9 @@ def save_persistables(self, executor, dirname, main_program=None, mode=0): fleet.save_persistables(exe, "dirname", paddle.static.default_main_program()) """ - warnings.warn( - "'save_persistables' is a deprecated, will be deleted after v2.2.0, Please use fleet.save instead." - ) + # warnings.warn( + # "'save_persistables' is a deprecated, will be deleted after v2.2.0, Please use fleet.save instead." + # ) self._runtime_handle._save_persistables(executor, dirname, main_program, mode) diff --git a/python/paddle/fluid/tests/unittests/test_fleet_base_2.py b/python/paddle/fluid/tests/unittests/test_fleet_base_2.py index 94fccb5fe9e45..7ca08bcb9d7f9 100644 --- a/python/paddle/fluid/tests/unittests/test_fleet_base_2.py +++ b/python/paddle/fluid/tests/unittests/test_fleet_base_2.py @@ -63,9 +63,10 @@ def test_ps_minimize(self): compiled_prog = fluid.compiler.CompiledProgram( fluid.default_main_program()) - fleet.save(dirname="/tmp", feed=['x', 'y'], fetch=[avg_cost]) - fleet.save(dirname="/tmp", feed=[input_x, input_y], fetch=[avg_cost]) - fleet.save(dirname="/tmp") + fleet.fleet.save(dirname="/tmp", feed=['x', 'y'], fetch=[avg_cost]) + fleet.fleet.save( + dirname="/tmp", feed=[input_x, input_y], fetch=[avg_cost]) + fleet.fleet.save(dirname="/tmp") self.assertRaises( Exception, From e9a0d4d51b574104d7800f5ab0ee3c9c5355bf5a Mon Sep 17 00:00:00 2001 From: seiriosPlus Date: Tue, 11 May 2021 19:26:17 +0800 Subject: [PATCH 10/10] fix save and user interface Change-Id: Ia12ff4dfe795d29dfcbd406fde88a49720918ddf --- python/paddle/distributed/fleet/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/paddle/distributed/fleet/__init__.py b/python/paddle/distributed/fleet/__init__.py index 4a65d3d17b9f4..403a02496afaa 100644 --- a/python/paddle/distributed/fleet/__init__.py +++ b/python/paddle/distributed/fleet/__init__.py @@ -62,7 +62,6 @@ run_server = fleet.run_server stop_worker = fleet.stop_worker distributed_optimizer = fleet.distributed_optimizer -# save = fleet.save // will add it later, and remove save_inference_model/save_persistables save_inference_model = fleet.save_inference_model save_persistables = fleet.save_persistables minimize = fleet.minimize