code: def _add_global_counter(self):
      
      assert self._global_step is None
  
      # Force this into the top-level namescope. Instead of forcing top-level
      # here, we could always call this in __init__() and then keep whatever
      # namescopes are around then.
      with self.g.as_default(), self.g.name_scope(None):
        try:
          self._global_step = self.g.get_tensor_by_name('global_step:0')
        except KeyError:
          self._global_step = tf.Variable(0, name='global_step', trainable=False)
docs: Adds a global counter, called once for setup by @property global_step.