Skip to main content

CCBP (Continuous Continual Backpropagation) - Pytorch

Implementation of CCBP (Continuous Continual Backpropagation) from Learning Continually at Peak Performance with Continuous Continual Backpropagation (ICLR 2026) and Continual Backpropagation.

A lightweight wrapper that can wrap any PyTorch optimizer to mitigate loss of plasticity in non-stationary settings

Install

$ pip install ccbp-pytorch

Usage

import torch
from torch import nn
import torch.nn.functional as F
from torch.optim import Adam

from ccbp_pytorch import CCBP

# define your model

model = nn.Sequential(
    nn.Linear(10, 64),
    nn.ReLU(),
    nn.Linear(64, 64),
    nn.ReLU(),
    nn.Linear(64, 1)
)

# wrap any base optimizer with CCBP

base_opt = Adam(model.parameters(), lr = 1e-3)

opt = CCBP(
    base_opt,
    model = model,
    continuous = True,       # continuous soft reset
    replacement_rate = 0.02, # 2% max reset rate
    steepness = 16.0,        # how sharply to reset below-average neurons
    reset_interval = 20,     # reset interval
    maturity_steps = 100     # steps before eligible for reset
)

# standard training loop

for _ in range(100):
    x = torch.randn(32, 10)
    target = torch.randn(32, 1)

    opt.zero_grad()
    F.mse_loss(model(x), target).backward()
    opt.step()

To run discrete Continual Backpropagation (Dohare et al.) instead:

opt = CCBP(
    base_opt,
    model = model,
    continuous = False,
    replacement_rate = 0.001,
    reset_interval = 20,
    maturity_steps = 100
)

Research Hooks

Researchers can easily plug in custom continuous transfer functions or custom utility estimation functions:

# custom transfer function (e.g. piecewise linear clamp)
custom_transfer = lambda u: torch.clamp(1.0 - u, min = 0.0, max = 1.0)

# custom utility metric (e.g. activation dormancy or custom gradient norm)
custom_utility = lambda cfg: cfg.param.grad.abs().sum(dim = 1)

opt = CCBP(
    base_opt,
    model = model,
    continuous = True,
    transfer_fn = custom_transfer,
    utility_fn = custom_utility
)

Custom Optimizers

For non-standard optimizers (such as Lion, AdamAtan2, or Muon), specify their momentum / second moment buffer names:

from lion_pytorch import Lion

base_opt = Lion(model.parameters(), lr = 1e-4)

opt = CCBP(
    base_opt,
    model = model,
    first_moment_names = ('exp_avg',),
    second_moment_names = ()
)

You can also register a custom state adjustment handler that modifies state buffers in-place:

from torch_einops_utils import pad_ndim

def custom_adjust_fn(
    optimizer,    # the base optimizer instance
    param,        # the parameter associated with this state buffer
    alpha,        # 1d reset factors in [0, 1] per neuron (0 = keep, 1 = full reset)
    dim,          # neuron axis (0 for incoming, 1 for outgoing)
    state_name,   # e.g. 'exp_avg', 'exp_avg_sq'
    buffer,       # the state tensor to modify in-place
    policy,       # 'zero' or 'mean'
    **kwargs
):
    alpha_expanded = pad_ndim(alpha, (dim, buffer.ndim - dim - 1))
    buffer.mul_(1.0 - alpha_expanded)

CCBP.register_optimizer_handler(CustomOptimizer, custom_adjust_fn)

Benchmarks

bit flipping

$ uv run train_bit_flipping.py

Citations

@misc{mccutcheon2026learning,
    title   = {Learning Continually at Peak Performance with Continuous Continual Backpropagation},
    author  = {Luc McCutcheon and Evangelos Chatzaroulas and Saber Fallah},
    year    = {2026},
    url     = {https://openreview.net/forum?id=UJqXhFFzKu},
}
@article{dohare2024loss,
    title   = {Loss of plasticity in deep continual learning},
    author  = {Dohare, Shibhansh and Hernandez-Garcia, J. Fernando and Rahman, Parash and Sutton, Richard S. and Mahmood, A. Rupam},
    journal = {Nature},
    volume  = {632},
    pages   = {784--789},
    year    = {2024}
}
@misc{dohare2021continualbackprop,
    title   = {Continual Backprop: Stochastic Gradient Descent with Persistent Randomness},
    author  = {Shibhansh Dohare and Richard S. Sutton and A. Rupam Mahmood},
    year    = {2021},
    eprint  = {2108.06325},
    archivePrefix = {arXiv},
    primaryClass = {cs.LG},
    url     = {https://arxiv.org/abs/2108.06325},
}
@article{kumar2023maintaining,
    title   = {Maintaining Plasticity in Continual Learning via Regenerative Regularization},
    author  = {Saurabh Kumar and Henrik Marklund and Benjamin Van Roy},
    journal = {arXiv preprint arXiv:2308.11958},
    year    = {2023},
    url     = {https://arxiv.org/abs/2308.11958}
}

Metadata

Release files for ccbp-pytorch 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ccbp-pytorch 0.0.2
File Size Uploaded
ccbp_pytorch-0.0.2.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ccbp-pytorch 0.0.2
File Interpreter ABI Platform
ccbp_pytorch-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.0 kB

Release files / ccbp_pytorch-0.0.2.tar.gz

Download URL ccbp_pytorch-0.0.2.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
260a6384ce02083aab0e02dc8b598255572cd2656c3e6daf44856f9d69959e68
BLAKE2b-256 checksum
How to use checksums
35f3dd5b395286def3d820bdbce94b037656dc1668d3b3cb621fe450cef6eed2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / ccbp_pytorch-0.0.2-py3-none-any.whl

Download URL ccbp_pytorch-0.0.2-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f63543b85507767b6d9ae40443b512badaa5c41a5f7e796a0e1a8563812aad7
BLAKE2b-256 checksum
How to use checksums
926126f20d117d97d8ee779ff5fb7ffd29bd2c87bc4812dc52a78367dd47a343
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

0.0.3

2 release files

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page