Shawn’s Blog
  • πŸ—‚οΈ Collections
    • πŸ–₯️ Slides Gallery
    • πŸ§‘β€πŸ³οΈ Cooking Ideas
    • 🍱 Cookbook
    • πŸ’¬ Language Learning
    • 🎼 Songbook
  • βš™οΈ Projects
    • βš› Continual Learning Arena
  • πŸ“„ Papers
    • AdaHAT
    • FG-AdaHAT
  • πŸŽ“ CV
    • CV (English)
    • CV (Mandarin)
  • About
  1. Components
  2. Optimizer
  • Welcome to CLArena
  • Getting Started
  • Configure Pipelines
  • Continual Learning (CL)
    • CL Main Experiment
    • Save and Evaluate Model
    • Full Experiment
    • Output Results
  • Continual Unlearning (CUL)
    • CUL Main Experiment
    • Full Experiment
    • Output Results
  • Multi-Task Learning (MTL)
    • MTL Experiment
    • Save and Evaluate Model
    • Output Results
  • Single-Task Learning (STL)
    • STL Experiment
    • Save and Evaluate Model
    • Output Results
  • Components
    • CL Dataset
    • MTL Dataset
    • STL Dataset
    • CL Algorithm
    • CUL Algorithm
    • MTL Algorithm
    • STL Algorithm
    • Backbone Network
    • Optimizer
    • Learning Rate Scheduler
    • Trainer
    • Metrics
    • Lightning Loggers
    • Callbacks
    • Other Configs
  • Implement Your Modules (TBC)
  • API Reference
  1. Components
  2. Optimizer

Configure Optimizer (STL)

Modified

August 26, 2025

Optimizer is the component that manages the learning process by updating model parameters based on the computed gradients.

Optimizers are a sub-config under the experiment index config (CL Main). To configure a custom optimizer, create a YAML file in the optimizer/ folder. As continual learning involves multiple tasks, each task can be assigned an optimizer for training. We support a uniform optimizer across all tasks and distinct optimizers for each task. Below are examples of both configurations.

Example

configs
β”œβ”€β”€ __init__.py
β”œβ”€β”€ entrance.yaml
β”œβ”€β”€ experiment
β”‚   β”œβ”€β”€ example_clmain_train.yaml
β”‚   └── ...
β”œβ”€β”€ optimizer
β”‚   β”œβ”€β”€ sgd_10_tasks.yaml
β”‚   └── sgd.yaml
...

Uniform Optimizer for All Tasks

configs/experiment/example_clmain_train.yaml
defaults:
  ...
  - /optimizer: sgd.yaml
  ...
configs/optimizer/sgd.yaml
_target_: torch.optim.SGD
_partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
lr: 0.01
weight_decay: 0.0

Distinct Optimizer For Each Task

Distinct optimizers are specified as a list. The length of the list must match the train_tasks field in the experiment index config (CL Main). Below is an example of distinct optimizers for 10 tasks.

defaults:
  ...
  - /optimizer: sgd_10_tasks.yaml
  ...
configs/optimizer/sgd_10_tasks.yaml
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0
- _target_: torch.optim.SGD
  _partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
  lr: 0.01
  weight_decay: 0.0

Supported Optimizers & Required Config Fields

In CLArena, we do not implement custom optimizers. We use the built-in optimizers from PyTorch in the torch.optim module.

Note

Optimization-based approaches in continual learning methodology focus on designing mechanisms from the perspective of manipulating optimization step. Typically, these approaches involve using different optimizers for various tasks. However, the evolution of optimization can be directly integrated into the CL algorithm so we don’t particularly design our own CL optimizers.

To choose an optimizer, assign the _target_ field to the class name of the optimizer. For example, to use SGD, set the _target_ field to torch.optim.SGD. Include _partial_: true as well (see below). Each optimizer has its own hyperparameters and configurations, which means it has its own required fields. The required fields are the same as the arguments of the class specified by _target_. The arguments for each optimizer class can be found in the PyTorch documentation.

PyTorch Documentation (Built-In Optimizers)

Warning

Make sure to include the field _partial_: true to enable partial instantiation. PyTorch optimizers need the model parameters as an argument to be fully instantiated, but during configuration we do not have that argument yet, so the optimizer can only be partially instantiated.

Optimizer is the component that manages the learning process by updating model parameters based on the computed gradients.

Optimizer is a sub-config under the experiment index config (MTL). To configure a custom optimizer, you need to create a YAML file in optimizer/ folder. Below shows an example of the optimizer config.

Example

configs
β”œβ”€β”€ __init__.py
β”œβ”€β”€ entrance.yaml
β”œβ”€β”€ experiment
β”‚   β”œβ”€β”€ example_mtl_train.yaml
β”‚   └── ...
β”œβ”€β”€ optimizer
β”‚   └── sgd.yaml
...
configs/experiment/example_mtl_train.yaml
defaults:
  ...
  - /optimizer: sgd.yaml
  ...
configs/optimizer/sgd.yaml
_target_: torch.optim.SGD
_partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
lr: 0.01
weight_decay: 0.0

Supported Optimizers & Required Config Fields

In CLArena, we didn’t implement our own optimizers, but rather use the built-in optimizers from PyTorch in torch.optimmodule.

To choose an optimizer, assign the _target_ field to the class name of the optimizer. For example, to use SGD, set _target_ field to torch.optim.SGD. Meanwhile, include _partial: true as well (see below). Each optimizer has its own hyperparameters and configurations, which means it has its own required fields. The required fields are the same as the arguments of the class specified by _target_. The arguments of each optimizer class can be found in PyTorch documentation.

PyTorch Documentation (Built-In Optimizers)

Warning

Make sure to include field _partial_: true to enable partial instantiation. PyTorch optimizer need the model parameters as an argument to be fully instantiated, but we are now in the phase of configuration and certainly don’t have that argument, so the optimizer can be only partially instantiated.

Optimizer is the component that manages the learning process by updating model parameters based on the computed gradients.

Optimizer is a sub-config under the experiment index config (STL). To configure a custom optimizer, you need to create a YAML file in optimizer/ folder. Below shows an example of the optimizer config.

Example

configs
β”œβ”€β”€ __init__.py
β”œβ”€β”€ entrance.yaml
β”œβ”€β”€ experiment
β”‚   β”œβ”€β”€ example_stl_train.yaml
β”‚   └── ...
β”œβ”€β”€ optimizer
β”‚   └── sgd.yaml
...
configs/experiment/example_stl_train.yaml
defaults:
  ...
  - /optimizer: sgd.yaml
  ...
configs/optimizer/sgd.yaml
_target_: torch.optim.SGD
_partial_: true # partially instantiate optimizer without 'params' argument. Make sure this is included in any case!
lr: 0.01
weight_decay: 0.0

Supported Optimizers & Required Config Fields

In CLArena, we didn’t implement our own optimizers, but rather use the built-in optimizers from PyTorch in torch.optimmodule.

To choose an optimizer, assign the _target_ field to the class name of the optimizer. For example, to use SGD, set _target_ field to torch.optim.SGD. Meanwhile, include _partial: true as well (see below). Each optimizer has its own hyperparameters and configurations, which means it has its own required fields. The required fields are the same as the arguments of the class specified by _target_. The arguments of each optimizer class can be found in PyTorch documentation.

PyTorch Documentation (Built-In Optimizers)

Warning

Make sure to include field _partial_: true to enable partial instantiation. PyTorch optimizer need the model parameters as an argument to be fully instantiated, but we are now in the phase of configuration and certainly don’t have that argument, so the optimizer can be only partially instantiated.

Back to top
Backbone Network
Learning Rate Scheduler
 
 

©️ 2025 Pengxiang Wang. All rights reserved.