| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
AADL adds Anderson acceleration to existing PyTorch optimizers. It stores a bounded history of parameter iterates, solves a small least-squares problem, and optionally replaces a normal optimizer update with an extrapolated one.
AADL supports QR and normal-equation Anderson kernels, safeguards, mixed precision, conditioning controls, moving-average smoothing, multiple optimizer parameter groups, and PyTorch-native Post-LocalSGD integration.
Python 3.11 or greater
PyTorch (torch>=2.13) and NumPy (numpy>=2.0)
These minimum versions are enforced by the package metadata and requirements.txt.
The quickest way to get a working environment is the provided helper script, which creates a local virtual environment (.venv), installs the dependencies, and installs AADL in editable mode:
./setup_venv.sh # uses python3 by default
PYTHON=python3.11 ./setup_venv.sh # pick a specific interpreter
./setup_venv.sh --recreate # delete an existing .venv firstThen activate it:
source .venv/bin/activateIf you prefer to manage your own environment:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements.txt # core dependencies
python -m pip install -e . # install AADL (editable)The examples/ demos need extra packages (torchvision, pandas, scikit-learn, scikit-image, opencv-python, docopt, pyyaml). Install them with:
python -m pip install -r requirements-examples.txtpython -m unittest discover -s tests -t . -v # fast suite
RUN_SLOW_TESTS=1 python -m unittest discover -s tests -t . -v # full suiteThe slow suite contains numerical convergence experiments whose results can be sensitive to optimizer and PyTorch version changes. The fast suite contains the API, kernel, safeguard, and distributed-policy regression tests.
AADL has three distinct responsibilities:
This separation avoids maintaining a second implementation of DDP, LocalSGD, or FedAvg-style parameter averaging inside AADL.
import torch
import torch.nn
import torch.optim
import AADL
model = torch.nn.Linear(8, 1)
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3, momentum=0.9)
AADL.accelerate(
optimizer,
acceleration_type="anderson",
relaxation=0.5,
wait_iterations=0,
history_depth=10,
store_each_nth=1,
frequency=1,
reg_acc=1e-8,
safeguard=True,
)
def closure():
with torch.enable_grad():
optimizer.zero_grad()
loss = loss_fn(model(inputs), targets)
loss.backward()
return loss
loss = optimizer.step(closure)All size and cadence arguments are validated. Calling accelerate twice on the same optimizer raises an error; call AADL.remove_acceleration(optimizer) before changing its configuration.
AADL composes with PyTorch's native Post-LocalSGD hook and model averager:
from torch.distributed.algorithms.ddp_comm_hooks.post_localSGD_hook import (
PostLocalSGDState,
post_localSGD_hook,
)
from AADL import HistoryResetPeriodicModelAverager, average_and_accept
state = PostLocalSGDState(
process_group=None,
subgroup=None,
start_localSGD_iter=100,
)
ddp_model.register_comm_hook(state, post_localSGD_hook)
local_optimizer = torch.optim.SGD(ddp_model.parameters(), lr=1e-2)
AADL.accelerate(
local_optimizer,
acceleration_type="anderson",
safeguard=False, # acceptance is decided globally below
)
averager = HistoryResetPeriodicModelAverager(
local_optimizer, period=4, warmup_steps=100,
)
# In the training loop, use a closure for the two global loss evaluations:
local_optimizer.step(closure)
average_and_accept(
local_optimizer,
averager,
closure,
policy="vote", # or "mean_loss"
vote_threshold=0.5,
loss_weight=local_batch_size,
)average_and_accept returns None between averaging boundaries. At a boundary it returns (accepted, candidate_loss, baseline_loss) and leaves every rank on the same selected global parameters.
Available global policies are:
Both branches are averaged through PyTorch's native model-averaging utilities. Loss-only closure evaluations run under torch.no_grad(), so the closure must guard backward work with torch.is_grad_enabled() to avoid extra DDP gradient synchronization. See Distributed training for the execution sequence, policy semantics, and integration requirements.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
M. Lupo Pasini, V. Reshniak, and M. K. Stoyanov. AADL: Anderson Accelerated Deep Learning. Computer Software. https://github.com/ORNL/AADL.git. 06 Sep. 2021. Web. doi:10.11578/dc.20210723.1. Copyright ID#: 81927550
M. Lupo Pasini, J. Yin, V. Reshniak and M. K. Stoyanov, "Anderson Acceleration for Distributed Training of Deep Learning Models," SoutheastCon 2022, 2022, pp. 289-295, doi: 10.1109/SoutheastCon48659.2022.9763953.
| Back | FazBrowse Home | New Git URL |