(
    num_updates,
    objective_fn,
    update_fn,
    variables,
    first_order,
    clip_grad_norm,
)
return [get_params(v) for v in updated_vars]
Optimization of `objective_fn` for `num_updates` of `variables`.
Optimization of `objective_fn` for `num_updates` of `variables`.
Optimization of objective_fn for num_updates of variables .
def optimizer_loop(
    num_updates,
    objective_fn,
    update_fn,
    variables,
    first_order,
    clip_grad_norm,
):
  """Optimization of `objective_fn` for `num_updates` of `variables`."""

  # Optimizer specifics.
  init, update, get_params = update_fn()

  def _body(step, preupdate_vars):
    """Optimization loop body."""
    updated_vars = optimizer_update(
        iterate_collection=preupdate_vars,
        iteration_idx=step,
        objective_fn=objective_fn,
        update_fn=update,
        get_params_fn=get_params,
        first_order=first_order,
        clip_grad_norm=clip_grad_norm,
    )

    return step + 1, updated_vars

  def _cond(step, *args):
    """Optimization truncation condition."""
    del args
    return step < num_updates

  step = tf.Variable(0, trainable=False, name='inner_step_counter')
  loop_vars = (step, [init(var) for var in variables])
  step, updated_vars = tf.while_loop(
      cond=_cond, body=_body, loop_vars=loop_vars, swap_memory=True)

  return [get_params(v) for v in updated_vars]
def optimizer_loop ( num_updates , objective_fn , update_fn , variables , first_order , clip_grad_norm , ) : # Optimizer specifics. init , update , get_params = update_fn ( ) def _body ( step , preupdate_vars ) : """Optimization loop body.""" updated_vars = optimizer_update ( iterate_collection = preupdate_vars , iteration_idx = step , objective_fn = objective_fn , update_fn = update , get_params_fn = get_params , first_order = first_order , clip_grad_norm = clip_grad_norm , ) return step + 1 , updated_vars def _cond ( step , * args ) : """Optimization truncation condition.""" del args return step < num_updates step = tf . Variable ( 0 , trainable = False , name = 'inner_step_counter' ) loop_vars = ( step , [ init ( var ) for var in variables ] ) step , updated_vars = tf . while_loop ( cond = _cond , body = _body , loop_vars = loop_vars , swap_memory = True ) return [ get_params ( v ) for v in updated_vars ]