def set_recomputation_options(opts,
                              allow_recompute=True,
                              allow_stateful_recompute=None):  # pylint: disable=unused-argument
  """Set re-computation options.

  Args:
    allow_recompute: Whether or not to re-compute instructions during training.
      If this is enabled then we will attempt to pattern match
      instructions/pipeline stages in the forward pass and recompute them in the
      backward pass to avoid having to preserve activations which increase the
      maximum memory liveness. Enabling this option can reduce memory usage at
      the expense of extra computation. Any stateful operations cannot be
      recomputed.
    allow_stateful_recompute: Deprecated.

  Returns:
    The IpuOptions configuration protobuf.
  """

  opts.speed_size_config.allow_recompute = allow_recompute

  return opts