Skip to content
naver-aiPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

FOAM: Factored One-sided Adam-Moment for Practical and Scalable SOAP

arXiv

NeurIPS 2026

Jaemyung Yu, Byeongho Heo, Sangdoo Yun, Dongyoon Han

NAVER AI Lab

Updates

  • Nov 23, 2026: Code released

Overview

FOAM is a memory-efficient variant of SOAP (eigenvalue-corrected Shampoo). SOAP rotates each weight matrix into the eigenbases of both of its Kronecker factors and keeps a dense Adam second moment in that rotated space. FOAM rotates only the input side, and keeps the second moment in factored form, as in Adafactor: one vector per dimension instead of one value per entry.

This repository is built on Distributed Shampoo from facebookresearch/optimizers (commit d24a149). FOAM is added as two options of the existing EigenvalueCorrectedShampooPreconditionerConfig, so the rest of Distributed Shampoo (distributed training, checkpointing, grafting, ...) works unchanged. The changes are listed in NOTICE.

Installation

Requires Python 3.12 and PyTorch 2.8 or later. The DDP, HSDP and hybrid-shard distributed configs of Distributed Shampoo need PyTorch 2.10 or later.

git clone https://github.com/naver-ai/foam.git
cd foam
pip install .

The package installs the Python module distributed_shampoo, the same module name as upstream Distributed Shampoo. Install it instead of upstream, not next to it.

Usage

Use FOAM for the hidden-layer matrices and Adam for the other parameters (embeddings, output layer, biases and normalization layers):

import math

from distributed_shampoo import (
    AdamPreconditionerConfig,
    DistributedShampoo,
    EigenvalueCorrectedShampooPreconditionerConfig,
    EighEigendecompositionConfig,
    SingleDeviceDistributedConfig,
    WeightDecayType,
)

model = instantiate_model()
# Separate parameters into hidden layers (only 2D) and other parameters.
hidden_layer_params = ...
other_params = ...

optimizer = DistributedShampoo(
    [
        # FOAM for hidden layer parameters.
        {
            "params": hidden_layer_params,
            "preconditioner_config": EigenvalueCorrectedShampooPreconditionerConfig(
                amortized_computation_config=EighEigendecompositionConfig(),
                use_in_side_only=True,  # Rotate only the input side (dim 1) of each matrix.
                use_factored_eigenvalues=True,  # Factored second moment, one vector per dimension.
            ),
            "precondition_frequency": 10,
            # The two settings below keep each matrix as a single 2D block.
            "max_preconditioner_dim": math.inf,
            "distributed_config": SingleDeviceDistributedConfig(
                target_parameter_dimensionality=2,
            ),
        },
        # Adam for other parameters.
        {
            "params": other_params,
            "start_preconditioning_step": math.inf,
            "grafting_config": AdamPreconditionerConfig(
                beta2=0.95,
                epsilon=1e-8,
            ),
        },
    ],
    lr=1e-3,
    betas=(0.95, 0.95),
    epsilon=1e-8,
    weight_decay=0.1,
    weight_decay_type=WeightDecayType.DECOUPLED,
)

The two options:

Option Effect
use_in_side_only Change the basis of dim 1 only (the input dimension of nn.Linear weights). A block whose dim 1 exceeds side_only_max_dim (default 8192) is not rotated. This applies to the blocks after reshaping (distributed_config, max_preconditioner_dim); 1D blocks are rotated in full, including weights of shape (1, N) or (N, 1) when size-1 dims are squeezed (finite target_parameter_dimensionality).
use_factored_eigenvalues Replace the dense corrected eigenvalues (prod(dims) entries) with one vector per dimension (sum(dims) entries). The full second moment is rebuilt as their outer product.

The eigenbasis can be computed with torch.linalg.eigh (EighEigendecompositionConfig, optionally with tolerance > 0 to skip the eigendecomposition while the current eigenbasis is still accurate) or the QR algorithm (QREigendecompositionConfig). For every other option, see the Distributed Shampoo README.

Example: GPT-2 small

examples/gpt2 pre-trains GPT-2 small on FineWeb 10B with FOAM, with the setting of the paper, on one node with 8 GPUs.

Tests

pip install -e ".[dev]"
python -m unittest distributed_shampoo/preconditioner/tests/factored_eigenvalue_corrected_shampoo_preconditioner_list_test.py
make test  # the CPU test suite of Distributed Shampoo

Citation

@article{yu2026foam,
    title={Factored One-sided Adam-Moment for Practical and Scalable SOAP},
    author={Yu, Jaemyung and Heo, Byeongho and Yun, Sangdoo and Han, Dongyoon},
    journal={arXiv preprint arXiv:2611.16905},
    year={2026}
}

FOAM is built on Distributed Shampoo; please also cite:

@misc{shi2023pytorchshampoo,
    title={A Distributed Data-Parallel PyTorch Implementation of the Distributed Shampoo Optimizer for Training Neural Networks At-Scale},
    author={Hao-Jun Michael Shi and Tsung-Hsien Lee and Shintaro Iwasaki and Jose Gallego-Posada and Zhijing Li and Kaushik Rangadurai and Dheevatsa Mudigere and Michael Rabbat},
    howpublished={\url{https://github.com/facebookresearch/optimizers/tree/main/distributed_shampoo}},
    year ={2023},
    eprint={2309.06497},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}

License

FOAM
Copyright (c) 2026-present NAVER Corp.

Licensed under the BSD 3-Clause License in the LICENSE file in the root directory of this source tree.

This repository contains Distributed Shampoo (Copyright (c) Meta Platforms, Inc. and affiliates, BSD license), and the GPT-2 example follows the structure of nanoGPT (MIT License). Each source file states its origin in its header; NOTICE has the license texts and the list of changes to Distributed Shampoo.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages