Skip to content

Commit

Permalink
allow training tower with index=0 and reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed May 7, 2020
1 parent 17c5984 commit 9f4154e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tensorpack/tfutils/tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,19 @@ def __init__(self, ns_name, vs_name='', index=0, total=1):

vs = tf.get_variable_scope()
assert vs.name == '', "Cannot nest TrainTowerContext with an existing variable scope!"
if self.has_own_variables:
if vs_name:
assert not vs.reuse, \
"Cannot create tower {} under reuse=True!".format(ns_name)
"Cannot create tower {} with vs_name={} under reuse=True!".format(ns_name, vs_name)
self._original_vs_reuse = vs.reuse

@property
def is_main_training_tower(self):
return self.index == 0

@property
def has_own_variables(self):
if self._original_vs_reuse:
return False
return self.index == 0 or len(self._vs_name) > 0

def _keys_to_freeze(self):
Expand Down

0 comments on commit 9f4154e

Please sign in to comment.