Skip to main content

Adaptive Soft-Thresholding Algorithm

Project description

ASTRA — Adaptive Soft-Thresholding Algorithm

PyTorch implementation of the inverse-regularization sparse-recovery method Inverse Regularization for Structured Sparse Recovery with Computable Certificates. ASTRA selects per-scope regularization weights $\boldsymbol\lambda$ online by tracking the fixed point $\boldsymbol\psi(\boldsymbol w(\boldsymbol\lambda)) = \boldsymbol\lambda$ of an order-statistic gauge, rather than sweeping a $\lambda$-grid.

Install

poetry install            # core
poetry install -E plotting -E imagenet

Requires Python ≥3.11, PyTorch ≥2.10, and sparsekit for the BlockSpec / ScopeSpec algebra used throughout.

Algorithm in one screen

Inner proximal-gradient step on $f(\boldsymbol w) + \sum_j \lambda_j,\Omega_j(\boldsymbol w_{\boldsymbol s_j})$, with outer EMA tracker for $\boldsymbol\lambda$:

for t in 1..T:
    direction = optimizer.step()                         # SGD/Adam/AdamW grad or momentum
    g         = ema_grad.update(direction)               # per-block EMA
    psi       = kth_mid(|g - alpha * w|; kappa)          # order-statistic gauge per scope
    lambda    = (1 - beta_t) * lambda + beta_t * psi     # beta_t = beta_0 / (t + t_0)
    w         = prox_lambda(w - eta * direction)         # soft-threshold under conditioner alpha
# at convergence: OLS refit on the per-scope top-kappa support

Hyperparameters used in the paper: $\beta_0 = 1$, $t_0 = 100$ (effective EMA retention $\approx 0.99$); diagonal / block-diagonal / dense conditioners.

Package layout

adasoft/
├── controllers.py      EMAController, LambdaController, AlphaController
├── proximals.py        ASTRASparsifier (PASTRA), IHTSparsifier
├── optimizers.py       Adam/SGD/AdamW + ASTRA wrappers
├── optimizers/         SASTRA, IHT, Muon-style, dataset-specific variants
├── hess.py             per-layer Hessian accumulators
├── linalg.py           Cholesky / Newton-Schulz / batched solves
├── prune.py            layer-wise OBS / closed-form prune utilities
└── pruners/
    ├── admm.py         dense-conditioner ADMM (Algorithm 3 of the paper)
    ├── admm_fp16.py    fp16/bf16 ADMM with fp32 storage
    ├── sparsegpt.py    SparseGPT baseline
    ├── wanda.py        Wanda baseline
    └── base.py         PruningStrategy ABC + PrunableLinear

adasoft/data/           dataset loaders (CIFAR, C4, ImageNet, MNIST)
adasoft/models/         ResNet, WideResNet, sparse Linear/Conv layers
adasoft/train/          schedulers, sweep harness, training utils
adasoft/configs.py      Hydra/OmegaConf config plumbing
adasoft/evaluate.py     lm-eval-harness + classification eval glue

Minimal usage

import torch
from adasoft.proximals import ASTRASparsifier
from adasoft.controllers import EMAController, LambdaController, AlphaController
from sparsekit import BlockSpec, ScopeSpec, View

# Declare structured sparsity: N=2 nonzeros per scope of M=4 (2:4)
view  = View.from_existing(linear.weight)
block = BlockSpec(view, (1, 1), "b")
scope = ScopeSpec(block, (1, 4), "s")

# Wrap any torch.optim optimizer (Adam, SGD, AdamW)
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
astra = ASTRASparsifier(
    groups=[scope],
    kappas=[2],
    lambdas=LambdaController(),
    ema_grad=EMAController(rho=0.9),
    alphas=AlphaController(default=1.0),
    optimizer=opt,
)

for batch in loader:
    loss = model(batch).loss
    loss.backward()
    opt.step()
    astra.step()           # updates λ, applies block soft-threshold
    opt.zero_grad()

Layer-wise LLM pruning

adasoft.pruners.admm.admm_prune implements the dense-conditioner ADMM variant used in the Qwen3 study: closed-form $\mathbf W$-update via Cholesky of $\mathbf H + \rho \mathbf D$, scope-aware soft-threshold $\mathbf Z$-update, ADMM dual ascent on $\mathbf U$, and an OLS refit on the converged top-N support per row. An fp16/bf16 variant (Tensor-Core matmuls, fp32 master storage) is in admm_fp16.py. SparseGPT and Wanda baselines are included for comparison under the same calibration set.

License

CC BY-NC 4.0 — non-commercial. Contact the author for commercial licensing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adasoft-0.1.1.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adasoft-0.1.1-py3-none-any.whl (93.4 kB view details)

Uploaded Python 3

File details

Details for the file adasoft-0.1.1.tar.gz.

File metadata

  • Download URL: adasoft-0.1.1.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.11 Linux/6.12.74-gentoo-x86_64

File hashes

Hashes for adasoft-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7b62583b770b51a23ec94bc208e7560ecdc2640ddc051f40dd2b748a64698c7
MD5 74d605fae93d99678e1a3a5d02124880
BLAKE2b-256 6c283a4c2c8d24d64977d36c5d81d28bbb6b7c0883b2ea2a27fbcd8d5b96ef67

See more details on using hashes here.

File details

Details for the file adasoft-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: adasoft-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 93.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.13.11 Linux/6.12.74-gentoo-x86_64

File hashes

Hashes for adasoft-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cbaf7825b9d67a45137a88050e2caeb16e61eb7db1133c790df3441dbb2e6908
MD5 2a9593789fd5f73cec20b02bf1941c07
BLAKE2b-256 fdcc177b7d638fb363e02dad01ff79bd75a4014bae5a99920a121b1da379b32a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page