未验证 提交 9dd25b46 编写于 作者: H hutuxian 提交者: GitHub

Cherry-pick: fix errors in python3 (#18239) (#18243)

* fix relative import error in python3
* fix debug string info
上级 f7f54d39
......@@ -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"]))
......
......@@ -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):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册