(device)
Pins global variables to the specified device.
Pins global variables to the specified device.
Pins global variables to the specified device .
def pin_global_variables(device):
  """Pins global variables to the specified device."""
  def getter(getter, *args, **kwargs):
    var_collections = kwargs.get('collections', None)
    if var_collections is None:
      var_collections = [tf.GraphKeys.GLOBAL_VARIABLES]
    if tf.GraphKeys.GLOBAL_VARIABLES in var_collections:
      with tf.device(device):
        return getter(*args, **kwargs)
    else:
      return getter(*args, **kwargs)

  with tf.variable_scope('', custom_getter=getter) as vs:
    yield vs
def pin_global_variables ( device ) : def getter ( getter , * args , * * kwargs ) : var_collections = kwargs . get ( 'collections' , None ) if var_collections is None : var_collections = [ tf . GraphKeys . GLOBAL_VARIABLES ] if tf . GraphKeys . GLOBAL_VARIABLES in var_collections : with tf . device ( device ) : return getter ( * args , * * kwargs ) else : return getter ( * args , * * kwargs ) with tf . variable_scope ( '' , custom_getter = getter ) as vs : yield vs