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. Custom Implementation
  2. MTL Algorithm
  • 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
  • Custom Implementation
    • CL Dataset
    • MTL Dataset
    • STL Dataset
    • CL Algorithm
    • CUL Algorithm
    • MTL Algorithm
    • STL Algorithm
    • Backbone Network
    • Callback
  • API Reference
  • FAQs

On this page

  • Base Classes
  • Implement MTL Algorithm
  1. Custom Implementation
  2. MTL Algorithm

Implement Custom MTL Algorithm

Modified

September 6, 2025

This section guides you through implementing custom multi-task learning (MTL) algorithms for use in CLArena.

Multi-task learning algorithms define the process of learning multiple tasks simultaneously.

Base Classes

In CLArena, multi-task learning algorithms are implemented as subclasses of the base classes in clarena/mtl_algorithms/base.py. The base classes are implemented inheriting Lightning module with additional features for multi-task learning:

  • clarena.mtl_algorithms.MTLAlgorithm: the base class for all multi-task learning algorithms.

Implement MTL Algorithm

To implement MTL algorithms:

  • Inherit MTLAlgorithm.
  • Put your algorithm’s hyperparameters in save_hyperparameters() in __init__(). This enables Lightning loggers to manage them automatically.
  • Implement training_step(), validation_step(), test_step() to define the training, validation and test steps respectively.
  • Other hooks like on_train_start(), on_validation_start(), on_test_start() are also free to customize if needed.
Tip

MTLAlgorithm works the same as Lightning module. All the other hooks are free to customize. Please refer to the Lightning module documentation for details about the hooks.

Note that configure_optimizers() is already implemented in MTLAlgorithm to manage the optimizer and learning rate scheduler for each task automatically. You don’t have to implement it unless you want to override the default behaviour.


For more details, please refer to the API Reference and source code. You may take implemented MTL algorithms in CLArena as examples. Feel free to contribute by submitting pull requests in GitHub!

API Reference (MTL Algorithms) Source Code (MTL Algorithms) GitHub Pull Request

Back to top
CUL Algorithm
STL Algorithm
 
 

©️ 2025 Pengxiang Wang. All rights reserved.