From 9dd25b46974618a0af78b0ed735658857f6dcb14 Mon Sep 17 00:00:00 2001 From: hutuxian Date: Fri, 21 Jun 2019 09:56:37 +0800 Subject: [PATCH] Cherry-pick: fix errors in python3 (#18239) (#18243) * fix relative import error in python3 * fix debug string info --- python/paddle/fluid/executor.py | 2 +- python/paddle/fluid/trainer_desc.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index bf9754ce2bf..1bca5bb3a14 100644 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -758,7 +758,7 @@ class Executor(object): def _dump_debug_info(self, program=None, trainer=None): with open(str(id(program)) + "_train_desc.prototxt", "w") as fout: - fout.write(trainer._desc()) + fout.write(str(trainer)) if program._fleet_opt: with open("fleet_desc.prototxt", "w") as fout: fout.write(str(program._fleet_opt["fleet_desc"])) diff --git a/python/paddle/fluid/trainer_desc.py b/python/paddle/fluid/trainer_desc.py index 806d09895ad..a37ae6dea11 100644 --- a/python/paddle/fluid/trainer_desc.py +++ b/python/paddle/fluid/trainer_desc.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys +from os import path __all__ = ['TrainerDesc', 'MultiTrainer', 'DistMultiTrainer', 'PipelineTrainer'] @@ -23,6 +25,11 @@ class TrainerDesc(object): with open(proto_file, 'r') as f: text_format.Parse(f.read(), self.proto_desc) ''' + # Workaround for relative import in protobuf under python3 + # TODO: should be fixed + cur_path = path.dirname(__file__) + sys.path.append(cur_path) + sys.path.append(cur_path + "/proto") from proto import trainer_desc_pb2 self.proto_desc = trainer_desc_pb2.TrainerDesc() import multiprocessing as mp @@ -68,6 +75,9 @@ class TrainerDesc(object): from google.protobuf import text_format return self.proto_desc.SerializeToString() + def __str__(self): + return str(self.proto_desc) + class MultiTrainer(TrainerDesc): def __init__(self): -- GitLab