optim package

Subpackages

Submodules

optim.adam module

class optim.adam.AdamOptimizer(opts: Namespace, model_params: Iterable[Tensor | Dict], *args, **kwargs)[source]

Bases: BaseOptim, Adam

Adam optimizer

Parameters:
  • opts – Command-line arguments

  • model_params – Model parameters

__init__(opts: Namespace, model_params: Iterable[Tensor | Dict], *args, **kwargs) None[source]
classmethod add_arguments(parser: ArgumentParser) ArgumentParser[source]

Add arguments for ADAM optimizer

optim.adamw module

class optim.adamw.AdamWOptimizer(opts: Namespace, model_params: Iterable[Tensor | Dict], *args, **kwargs)[source]

Bases: BaseOptim, AdamW

AdamW optimizer

Parameters:
  • opts – Command-line arguments

  • model_params – Model parameters

__init__(opts: Namespace, model_params: Iterable[Tensor | Dict], *args, **kwargs) None[source]
classmethod add_arguments(parser: ArgumentParser) ArgumentParser[source]

Add arguments for AdamW optimizer

optim.base_optim module

class optim.base_optim.BaseOptim(opts: Namespace, *args, **kwargs)[source]

Bases: object

Base class for optimizer

Parameters:

opts – Command-line arguments

__init__(opts: Namespace, *args, **kwargs) None[source]
classmethod add_arguments(parser: ArgumentParser) ArgumentParser[source]

Add optimizer arguments

optim.sgd module

class optim.sgd.SGDOptimizer(opts: Namespace, model_params: Iterable[Tensor | Dict], *args, **kwargs)[source]

Bases: BaseOptim, SGD

SGD optimizer

Parameters:
  • opts – Command-line arguments

  • model_params – Model parameters

__init__(opts: Namespace, model_params: Iterable[Tensor | Dict], *args, **kwargs) None[source]
classmethod add_arguments(parser: ArgumentParser) ArgumentParser[source]

Add optimizer arguments

Module contents

optim.check_trainable_parameters(model: Module, model_params: List) None[source]

Helper function to check if any model parameters w/ gradients are not part of model_params

optim.remove_param_name_key(model_params: List) None[source]

Helper function to remove param_names key from model_params

optim.build_optimizer(model: Module, opts, *args, **kwargs) BaseOptim[source]

Helper function to build an optimizer

Parameters:
  • model – A model

  • opts – command-line arguments

Returns:

An instance of BaseOptim

optim.arguments_optimizer(parser: ArgumentParser) ArgumentParser[source]