(self, batch, rng, step=0, learning_rate=None)
return stats['loss'], stats
Runs one training step, to update model and optimizer parameters.

    Args:
      batch: Batch of labeled training data.
      rng: Single-use random number generator (JAX PRNG key).
      step: Training step number.
      learning_rate: Learning rate for the optimizer; if None, use optimizer's
          default learning rate.

    Returns:
      Tuple of (loss, optimizer_stats), with the newly computed loss and
      updated stats as reported by the optimizer.
Runs one training step, to update model and optimizer parameters.
Runs one training step to update model and optimizer parameters .
def one_step(self, batch, rng, step=0, learning_rate=None):
    """Runs one training step, to update model and optimizer parameters.

    Args:
      batch: Batch of labeled training data.
      rng: Single-use random number generator (JAX PRNG key).
      step: Training step number.
      learning_rate: Learning rate for the optimizer; if None, use optimizer's
          default learning rate.

    Returns:
      Tuple of (loss, optimizer_stats), with the newly computed loss and
      updated stats as reported by the optimizer.
    """
    if learning_rate is not None:
      self._opt_params['learning_rate'] = tl.for_n_devices(
          learning_rate, self._n_devices)

    # Split the batch across devices (batch_dim --> batch_dim // n_devices)
    # and create new rng's 1-1 with devices.
    if self._n_devices > 1:
      batch = tl.reshape_by_device(batch, self._n_devices)
      rng = jnp.stack(fastmath.random.split(rng, self._n_devices))

    weights = self._accelerated_model_with_loss.weights
    state = self._accelerated_model_with_loss.state
    if logging.vlog_is_on(1) and ((step & step - 1) == 0):
      # Prints every power of two, if debugging is enabled.
      logging.info('step[%d]', step)
      logging.info('opt_params[%s]', self._opt_params)
      logging.info('slots[%s]', self._slots)
      logging.info('weights[%s]', weights)
      logging.info('state[%s]', state)

    # NOTE: stats is a replicated dictionary of key to jnp arrays.
    (new_weights, new_slots), new_state, stats = self._accelerated_update_fn(
        (weights, self._slots), step, self._opt_params, batch, state, rng)

    if logging.vlog_is_on(1) and ((step & step - 1) == 0):
      logging.info('updated weights[%s]', new_weights)
      logging.info('stats[%s]', stats)

    self._accelerated_model_with_loss.weights = new_weights
    self._accelerated_model_with_loss.state = new_state
    self._slots = new_slots
    self._optimizer.slots = self._unreplicate(self._slots)
    return stats['loss'], stats
def one_step ( self , batch , rng , step = 0 , learning_rate = None ) : if learning_rate is not None : self . _opt_params [ 'learning_rate' ] = tl . for_n_devices ( learning_rate , self . _n_devices ) # Split the batch across devices (batch_dim --> batch_dim // n_devices) # and create new rng's 1-1 with devices. if self . _n_devices > 1 : batch = tl . reshape_by_device ( batch , self . _n_devices ) rng = jnp . stack ( fastmath . random . split ( rng , self . _n_devices ) ) weights = self . _accelerated_model_with_loss . weights state = self . _accelerated_model_with_loss . state if logging . vlog_is_on ( 1 ) and ( ( step & step - 1 ) == 0 ) : # Prints every power of two, if debugging is enabled. logging . info ( 'step[%d]' , step ) logging . info ( 'opt_params[%s]' , self . _opt_params ) logging . info ( 'slots[%s]' , self . _slots ) logging . info ( 'weights[%s]' , weights ) logging . info ( 'state[%s]' , state ) # NOTE: stats is a replicated dictionary of key to jnp arrays. ( new_weights , new_slots ) , new_state , stats = self . _accelerated_update_fn ( ( weights , self . _slots ) , step , self . _opt_params , batch , state , rng ) if logging . vlog_is_on ( 1 ) and ( ( step & step - 1 ) == 0 ) : logging . info ( 'updated weights[%s]' , new_weights ) logging . info ( 'stats[%s]' , stats ) self . _accelerated_model_with_loss . weights = new_weights self . _accelerated_model_with_loss . state = new_state self . _slots = new_slots self . _optimizer . slots = self . _unreplicate ( self . _slots ) return stats [ 'loss' ] , stats