From b6d997f41b011c99ddaf0534428de3397a3bad3e Mon Sep 17 00:00:00 2001 From: Yibo Zhu Date: Sat, 29 Jun 2019 07:27:36 +0800 Subject: [PATCH 1/3] tensorflow: quick fix for scope problem --- byteps/tensorflow/ops.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/byteps/tensorflow/ops.py b/byteps/tensorflow/ops.py index 870fbaf76..785f3f183 100644 --- a/byteps/tensorflow/ops.py +++ b/byteps/tensorflow/ops.py @@ -81,6 +81,8 @@ def _push_pull(tensor, scope='', name=None): name = 'BytePSPushPull_%s' % _normalize_name(tensor.name) if scope == '' and not _executing_eagerly(): scope = tf.compat.v1.get_default_graph().get_name_scope() + if scope != '': + scope += '/' full_name = scope + name full_name = full_name.encode("ascii") TF_LIB_CTYPES.byteps_tensorflow_declare_tensor(ctypes.c_char_p(full_name)) @@ -114,6 +116,8 @@ def broadcast(tensor, root_rank, scope='', name=None, is_variable=True): name = 'BytePSBroadcast_%s' % _normalize_name(tensor.name) if scope == '' and not _executing_eagerly(): scope = tf.compat.v1.get_default_graph().get_name_scope() + if scope != '': + scope += '/' full_name = scope + name full_name = full_name.encode("ascii") TF_LIB_CTYPES.byteps_tensorflow_declare_tensor(ctypes.c_char_p(full_name)) From 6ac2ef18868e79afdba417cfddc45e63623dba04 Mon Sep 17 00:00:00 2001 From: Yimin Jiang Date: Sat, 29 Jun 2019 14:39:42 +0800 Subject: [PATCH 2/3] tensorflow: improve ops.py compatibility --- byteps/tensorflow/ops.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/byteps/tensorflow/ops.py b/byteps/tensorflow/ops.py index 785f3f183..8eaeb9d4d 100644 --- a/byteps/tensorflow/ops.py +++ b/byteps/tensorflow/ops.py @@ -80,7 +80,10 @@ def _push_pull(tensor, scope='', name=None): if name is None and not _executing_eagerly(): name = 'BytePSPushPull_%s' % _normalize_name(tensor.name) if scope == '' and not _executing_eagerly(): - scope = tf.compat.v1.get_default_graph().get_name_scope() + try: + scope = tf.get_default_graph().get_name_scope() + except: + scope = tf.compat.v1.get_default_graph().get_name_scope() if scope != '': scope += '/' full_name = scope + name @@ -115,7 +118,10 @@ def broadcast(tensor, root_rank, scope='', name=None, is_variable=True): if name is None and not _executing_eagerly(): name = 'BytePSBroadcast_%s' % _normalize_name(tensor.name) if scope == '' and not _executing_eagerly(): - scope = tf.compat.v1.get_default_graph().get_name_scope() + try: + scope = tf.get_default_graph().get_name_scope() + except: + scope = tf.compat.v1.get_default_graph().get_name_scope() if scope != '': scope += '/' full_name = scope + name From 64c1cbeaf34212123196ff906eea5a3b36012a11 Mon Sep 17 00:00:00 2001 From: Yimin Jiang Date: Sat, 29 Jun 2019 14:56:35 +0800 Subject: [PATCH 3/3] tensorflow: replace try-except with if-else --- byteps/tensorflow/ops.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/byteps/tensorflow/ops.py b/byteps/tensorflow/ops.py index 8eaeb9d4d..8b4475c2c 100644 --- a/byteps/tensorflow/ops.py +++ b/byteps/tensorflow/ops.py @@ -80,10 +80,10 @@ def _push_pull(tensor, scope='', name=None): if name is None and not _executing_eagerly(): name = 'BytePSPushPull_%s' % _normalize_name(tensor.name) if scope == '' and not _executing_eagerly(): - try: - scope = tf.get_default_graph().get_name_scope() - except: + if 'v1' in dir(tf.compat): scope = tf.compat.v1.get_default_graph().get_name_scope() + else: + scope = tf.get_default_graph().get_name_scope() if scope != '': scope += '/' full_name = scope + name @@ -118,10 +118,10 @@ def broadcast(tensor, root_rank, scope='', name=None, is_variable=True): if name is None and not _executing_eagerly(): name = 'BytePSBroadcast_%s' % _normalize_name(tensor.name) if scope == '' and not _executing_eagerly(): - try: - scope = tf.get_default_graph().get_name_scope() - except: + if 'v1' in dir(tf.compat): scope = tf.compat.v1.get_default_graph().get_name_scope() + else: + scope = tf.get_default_graph().get_name_scope() if scope != '': scope += '/' full_name = scope + name