optim#


clone_optimizer(optim: TOptim, new_params: torch.nn.parameter.Parameter | collections.abc.Iterator[torch.nn.parameter.Parameter]) TOptim[source]#

Clone an optimizer to get a new optim instance with new parameters.

WARNING: This is a temporary measure, and should not be used in downstream code! Once tianshou interfaces have moved to optimizer factories instead of optimizers, this will be removed.

Parameters:
  • optim – the optimizer to clone

  • new_params – the new parameters to use

Returns:

a new optimizer with the same configuration as the old one

optim_step(loss: Tensor, optim: Optimizer, module: Module, max_grad_norm: float | None = None) None[source]#

Perform a single optimization step.

Parameters:
  • loss

  • optim

  • module

  • max_grad_norm – if passed, will clip gradients using this