parameters: ()
return_statement: return _custom_getter, deferred_restorations
docstring: Returns a custom getter which searches `deferred_restorations`.
  
    Returns: A tuple of (_custom_getter, deferred_restorations)
      _custom_getter: The getter which should be added to variable_scopes where
        variables will be created.
      deferred_restorations: A list for _DeferredRestoration objects. Typically
        empty when the getter is set, and expanded as deferred restorations are
        requested. All new deferred restorations should be appended to the end of
        the list, where they will have priority over older deferred restorations.
docstring_summary: Returns a custom getter which searches `deferred_restorations`.
docstring_tokens: Returns a custom getter which searches deferred_restorations .
function: def _make_custom_getter_for_deferred_restorations():
    """Returns a custom getter which searches `deferred_restorations`.
  
    Returns: A tuple of (_custom_getter, deferred_restorations)
      _custom_getter: The getter which should be added to variable_scopes where
        variables will be created.
      deferred_restorations: A list for _DeferredRestoration objects. Typically
        empty when the getter is set, and expanded as deferred restorations are
        requested. All new deferred restorations should be appended to the end of
        the list, where they will have priority over older deferred restorations.
    """
    deferred_restorations = []
  
    def _custom_getter(getter,
                       name,
                       shape=None,
                       dtype=None,
                       initializer=None,
                       *args,
                       **kwargs):
      """A custom getter which processes deferred restorations."""
      # Iterate over restorations, newest first (newer restorations will take
      # precedence over older restorations, just like with immediate restorations
      # into existing variables).
      delayed_restoration = None
      found_value = False
      value_to_restore = None
      for delayed_restoration in reversed(deferred_restorations):
        checkpoint_name = delayed_restoration.map_func(name)
        if (checkpoint_name in
            delayed_restoration.checkpointed_variables_to_restore):
          found_value = True
          value_to_restore = (
              delayed_restoration
              .checkpointed_variables_to_restore[checkpoint_name])
        if found_value:
          break
      # value_to_restore may be False because this variable is not in any
      # checkpoint we are restoring, or None because we have explicitly set it to
      # None when it was previously fetched. In either case, we don't need to
      # set an initializer.
      if found_value and value_to_restore is not None:
        initializer = value_to_restore
        shape = None
      variable = getter(
          name,
          shape=shape,
          dtype=dtype,
          initializer=initializer,
          *args,
          **kwargs)
      if found_value and value_to_restore is not None:
        # Mark as already restored from this checkpoint.
        delayed_restoration.checkpointed_variables_to_restore[
            checkpoint_name] = None
        if not context.executing_eagerly():
          delayed_restoration.session.run(variable.initializer)
      if found_value:
        # Error checking should run even if we've already restored a value.
        if delayed_restoration.restored_variables.setdefault(
            checkpoint_name, variable) is not variable:
          # Naming conflict. We've tried to initialize two variables with the
          # same value from the checkpoint.
          if delayed_restoration.map_func_is_user:
            raise ValueError(
                _restore_custom_map_func_error_message(
                    mapped_name=checkpoint_name,
                    first_variable=delayed_restoration
                    .restored_variables[checkpoint_name],
                    second_variable=variable,
                    network_name=delayed_restoration.network_name,
                    network_scope_name=delayed_restoration.network_scope_name))
          else:
            raise ValueError(
                _default_naming_conflict_error_message(
                    mapped_name=checkpoint_name,
                    first_variable=delayed_restoration
                    .restored_variables[checkpoint_name],
                    second_variable=variable,
                    network_name=delayed_restoration.network_name,
                    network_scope_name=delayed_restoration.network_scope_name))
      return variable
  
    return _custom_getter, deferred_restorations
function_tokens: def _make_custom_getter_for_deferred_restorations ( ) : deferred_restorations = [ ] def _custom_getter ( getter , name , shape = None , dtype = None , initializer = None , * args , * * kwargs ) : """A custom getter which processes deferred restorations.""" # Iterate over restorations, newest first (newer restorations will take # precedence over older restorations, just like with immediate restorations # into existing variables). delayed_restoration = None found_value = False value_to_restore = None for delayed_restoration in reversed ( deferred_restorations ) : checkpoint_name = delayed_restoration . map_func ( name ) if ( checkpoint_name in delayed_restoration . checkpointed_variables_to_restore ) : found_value = True value_to_restore = ( delayed_restoration . checkpointed_variables_to_restore [ checkpoint_name ] ) if found_value : break # value_to_restore may be False because this variable is not in any # checkpoint we are restoring, or None because we have explicitly set it to # None when it was previously fetched. In either case, we don't need to # set an initializer. if found_value and value_to_restore is not None : initializer = value_to_restore shape = None variable = getter ( name , shape = shape , dtype = dtype , initializer = initializer , * args , * * kwargs ) if found_value and value_to_restore is not None : # Mark as already restored from this checkpoint. delayed_restoration . checkpointed_variables_to_restore [ checkpoint_name ] = None if not context . executing_eagerly ( ) : delayed_restoration . session . run ( variable . initializer ) if found_value : # Error checking should run even if we've already restored a value. if delayed_restoration . restored_variables . setdefault ( checkpoint_name , variable ) is not variable : # Naming conflict. We've tried to initialize two variables with the # same value from the checkpoint. if delayed_restoration . map_func_is_user : raise ValueError ( _restore_custom_map_func_error_message ( mapped_name = checkpoint_name , first_variable = delayed_restoration . restored_variables [ checkpoint_name ] , second_variable = variable , network_name = delayed_restoration . network_name , network_scope_name = delayed_restoration . network_scope_name ) ) else : raise ValueError ( _default_naming_conflict_error_message ( mapped_name = checkpoint_name , first_variable = delayed_restoration . restored_variables [ checkpoint_name ] , second_variable = variable , network_name = delayed_restoration . network_name , network_scope_name = delayed_restoration . network_scope_name ) ) return variable return _custom_getter , deferred_restorations