---
title: 'CAST: Continuous Adaptive Sparse Trainer'
url: https://www.emergentmind.com/topics/continuous-adaptive-sparse-trainer-cast
type: topic
---

# CAST: Continuous Adaptive Sparse Trainer

Continuous Adaptive Sparse Trainer (CAST) is a sparsity-aware retraining framework for transforming pretrained large language models into hardware-friendly semi-structured sparse models, especially the \(2\!:\!4\) format, while preserving language modeling quality and zero-shot performance. CAST is presented as a **fully continuous and differentiable sparsity-aware training framework** for semi-structured sparse models: it keeps the model dense during forward propagation throughout training, dynamically updates a binary \(N\!:\!M\) mask from current weight magnitudes, selectively decays would-be-pruned weights toward zero, and applies the final hard mask only after training. Its three core components are **AdamS**, **Weight Scaling**, and **Knowledge Distillation**. In the reported LLaMA2-7B \(2\!:\!4\) setting, an extended CAST run yields a sparse model with a perplexity increase of \(0.09\) and a \(0.36\%\) gain in zero-shot accuracy relative to the dense model, using \(40\)B retraining tokens, i.e. \(2\%\) of the original \(2\)T-token pretraining budget [2509.25996].

## 1. Definition and problem setting

CAST targets **semi-structured** or **\(N\!:\!M\)** sparsity. If a layer weight matrix is \(W^k \in \mathbb{R}^{R_k \times C_k}\), each row is partitioned into contiguous groups
\[
g_r^{(i)} = \{iM, iM+1, \dots, (i+1)M-1\},
\]
and the mask \(M^k\) must satisfy
\[
\sum_{j \in g_r^{(i)}} M^k[r,j] = N.
\]
The sparse weights are
\[
\hat W^k = W^k \odot M^k.
\]
The main target is **\(2\!:\!4\) sparsity**, where exactly \(2\) of every \(4\) weights remain nonzero. The paper motivates this regime by its deployment relevance: \(2\!:\!4\) sparsity is natively supported on NVIDIA GPUs and can enable up to \(2\times\) speedup in both prefill and decoding under suitable kernels [2509.25996].

CAST is positioned against two limitations in prior LLM sparsification. First, many methods optimize masks and weights separately, as in one-shot pruning followed by optional retraining. Second, STE-based semi-structured retraining methods use a discrete sparse forward pass and surrogate backpropagation, which CAST argues introduces discontinuity and biased gradients. CAST instead keeps the forward model dense during optimization and uses the evolving semi-structured mask only to determine which parameters receive sparsity-inducing decay. This suggests a different notion of “continuous”: continuity is preserved at the level of model optimization, not through soft masks or hard-concrete gate parameterizations.

## 2. Semi-structured sparsification as dense training with dynamic masking

The defining mechanism of CAST is a repeated projection of each \(4\)-weight group onto the top-\(2\)-by-magnitude pattern, without using that hard mask in the forward graph. Every \(T_1=10\) iterations, CAST recomputes the mask. For each group, the second-largest absolute value \(\xi\) defines the binary decision rule
\[
M_t^k[r,j] =
\begin{cases}
1, & \text{if } |W_t^k[r,j]| \ge \xi \\
0, & \text{if } |W_t^k[r,j]| < \xi
\end{cases}
\qquad j \in g_r^{(i)}.
\]
This enforces an exact \(2\!:\!4\) pattern at every mask refresh. The final sparse model is then
\[
\hat W_T^k = W_T^k \odot M_T^k.
\]

A common misconception is that CAST uses continuous masks, soft top-\(k\) relaxations, or STE-style sparse forward propagation. The paper states the opposite. CAST does **not** introduce mask logits, sigmoid gates, Gumbel relaxations, or straight-through estimators for the mask itself. Its “fully continuous and differentiable” characterization derives from the fact that the model remains dense during forward propagation throughout training, so the task loss is optimized over dense weights and scaling factors. The discrete \(2\!:\!4\) mask acts only as a selector for sparsity pressure.

This leads to a distinct training trajectory. Important weights keep receiving task gradients and remain among the top two magnitudes in their group. Unimportant weights recurrently lose the within-group competition and are selectively driven toward zero. By the end of training, the final hard projection is intended to be almost lossless because the suppressed coordinates are already negligible in magnitude.

## 3. Core components: AdamS, Weight Scaling, and Knowledge Distillation

CAST introduces three coupled components.

**AdamS** is a sparsity-inducing Adam-style optimizer. The paper begins from the standard lasso-style objective
\[
\min_{\mathbf{\Theta}} \mathcal{L}(\mathbf{\Theta}, x) + \lambda \|\mathbf{\Theta}\|_1,
\]
but argues that ordinary \(L_1\) decay is insufficient for semi-structured \(2\!:\!4\) optimization. AdamS applies selective \(L_1\)-style decay only to currently masked parameters and linearly increases the relative weight of decay over training:
\[
\tilde{\mathcal{G}}_t = (1-\alpha_t)\mathcal{G}_t + \alpha_t \lambda \operatorname{Sign}(\theta_{t-1}),
\qquad
\alpha_t = \frac{t}{T}.
\]
Its full update is
\[
\mu_t = \beta_1 \mu_{t-1} + (1-\beta_1) g_t,
\]
\[
\tilde\mu_t = (1-\alpha_t)\mu_t + \alpha_t \lambda \operatorname{Sign}(\theta_{t-1}),
\qquad
\hat\mu_t = \tilde\mu_t/(1-\beta_1^t),
\]
\[
v_t = \beta_2 v_{t-1} + (1-\beta_2)\tilde\mu_t^2,
\qquad
\hat v_t = v_t/(1-\beta_2^t),
\]
\[
\theta_t = \theta_{t-1} - \gamma_t \frac{\hat\mu_t}{\sqrt{\hat v_t}+\epsilon}.
\]
The distinguishing claim is that AdamS decouples the first-order moment from stale \(L_1\) sign accumulation while still using Adam-style adaptive scaling.

**Weight Scaling** compensates for magnitude shrinkage induced by repeated decay. For a matrix \(W^k\), CAST introduces trainable scaling factors \(A^k\) and applies row-wise or group-wise multiplicative rescaling. In the row-wise form,
\[
W^{\text{scale},k} = \operatorname{Diag}(A^k) W^k.
\]
The more general implementation reshapes \(W^k\) into groups and uses \(A^k \in \mathbb{R}^{R_k \times n}\), with \(n=2\) in experiments. Because scaling is multiplicative, it preserves the learned sparsity pattern. The factors are initialized to \(1\), trained jointly, and folded into weights before deployment, so the paper reports no inference-time overhead [2509.25996].

**Knowledge Distillation** uses the dense model as a self-teacher. CAST employs KL divergence on output distributions,
\[
\mathcal{L}_{kl} = D_{\mathrm{KL}}(P_t \parallel P_s)
= \sum_x P_t(x)\log\frac{P_t(x)}{P_s(x)},
\]
and combines it with the language modeling objective as
\[
\mathcal{L} = \eta \mathcal{L}_{kl} + (1-\eta)\mathcal{L}_{ce}.
\]
The paper reports that simple output-distribution KL performed better than more elaborate feature-level distillation, and that KD substantially improves retraining efficiency under constrained token budgets.

## 4. Training algorithm, optimization behavior, and common misconceptions

CAST begins from a pretrained dense checkpoint, computes an initial \(2\!:\!4\) mask, initializes the scaling parameters to ones, and then iterates a dense-forward sparse-aware retraining loop. At each step, if \(t \bmod T_1 = 0\), the \(2\!:\!4\) mask is recomputed from current magnitudes. Forward propagation uses the scaled dense weights. Backpropagation computes gradients through the dense network. AdamS then applies selective decay to currently masked coordinates, with \(\alpha_t=t/T\) gradually increasing sparsity pressure toward the end of training.

This schedule clarifies a second misconception: CAST is not a sparse-training method in the sense of sparse forward and backward execution throughout retraining. The paper explicitly states that training is still dense. The gain is a deployable sparse endpoint rather than a sparse compute path during retraining. Knowledge distillation also adds overhead; the paper estimates roughly \(1/3\) more FLOPs. CAST therefore trades retraining efficiency for final sparse-model quality and hardware compatibility [2509.25996].

The constrained optimization target is introduced as
\[
\min_{\hat{\Theta} \in S(N,M,\Theta)} \mathbb{E}_{x \sim p(x)} \, \mathcal{L}(\hat{\Theta}, x),
\]
where \(S(N,M,\Theta)\) denotes the set of weights satisfying the \(N\!:\!M\) constraint. CAST operationalizes this objective indirectly through dynamic mask recomputation plus selective decay, rather than by solving a discrete constrained problem or by introducing soft mask variables.

## 5. Empirical results, scaling law, and deployment behavior

CAST is evaluated on GPT-2, OPT, LLaMA2, and LLaMA3, spanning \(125\)M to \(13\)B parameters, using strict \(2\!:\!4\) sparsity throughout the main experiments. The main retraining budget is often \(7.5\)B tokens, with extended runs denoted \( \mathrm{CAST}^{\dagger} \). On LLaMA2-7B, the dense baseline reports WikiText perplexity \(5.12\) and average zero-shot accuracy \(57.16\). Standard CAST at \(7.5\)B tokens yields \(5.58\) and \(55.91\), while \( \mathrm{CAST}^{\dagger} \) at \(40\)B tokens yields \(5.21\) and \(57.52\), corresponding to a perplexity increase of \(0.09\) and a \(0.36\%\) zero-shot gain relative to dense [2509.25996].

Relative to prior sparse baselines on LLaMA2-7B under similar budgets, CAST improves over Wanda, MaskLLM, Naive Retraining, and SR-STE. The ablation results attribute nontrivial contributions to all three components: removing KD, replacing AdamS mask learning with a fixed mask, or removing Weight Scaling all reduce zero-shot accuracy. The paper further proposes a token-only empirical scaling law
\[
L_i(D) = A_i + \frac{B_i}{D^{\beta}},
\]
with \(\beta = 0.2849\), and reports \(R^2 \approx 0.99\) for LLaMA2-7B and 13B and \(R^2=0.98\) for LLaMA3-8B. The fitted law predicts that dense-level sparse recovery requires \(95.3\)B retraining tokens for LLaMA2-7B, \(56.3\)B for LLaMA2-13B, and \(1211\)B for LLaMA3-8B.

Deployment results are central to CAST’s rationale. Under TensorRT-LLM on NVIDIA hardware, the reported throughput speedups range from \(1.40\times\) to \(2.09\times\), with memory use reduced to about \(57\%\)–\(58\%\) of dense. CAST also remains robust under quantization and downstream adaptation. On LLaMA2-7B, the sparse model at 3-bit AWQ reports perplexity \(5.56\), versus \(5.82\) for the dense 3-bit model. In LoRA fine-tuning on GSM8K, sparse LLaMA2-7B improves from \(40.3\%\) to \(46.9\%\), and sparse LLaMA2-13B improves from \(49.4\%\) to \(54.4\%\).

## 6. Relation to earlier sparse-training research and limitations

CAST occupies a distinct position within sparse training. “Growing Efficient Deep Networks by Structured Continuous Sparsification” optimized continuous structural gates over filters, layers, and recurrent units, but it targeted structured architecture adaptation rather than semi-structured \(2\!:\!4\) weight sparsity [2007.15353]. “Top-KAST: Top-K Always Sparse Training” maintained constant sparsity in both forward and backward passes via top-\(k\) reselection of a latent dense parameterization, whereas CAST keeps dense forward propagation and uses dynamic \(2\!:\!4\) mask updates only to determine selective decay [2106.03517]. The most direct precursor is AST, which used SR-STE-based dynamic mask learning, knowledge distillation, and optional SLoRB for semi-structured LLM retraining; CAST replaces sparse-forward STE training with dense forward optimization, AdamS, and Weight Scaling [2407.20584].

This suggests a useful clarification of what CAST is and is not. It is **not** a weight-sparse training system that preserves sparse execution throughout retraining, and it is **not** a continuous-mask method based on differentiable gates. It is a dense retraining framework that progressively aligns a pretrained LLM with a deployable \(2\!:\!4\) sparse endpoint.

Its limitations follow directly from that design. Training remains dense; KD increases retraining cost; the experimental focus is overwhelmingly on \(2\!:\!4\); and the scaling law is explicitly empirical rather than fundamental. The paper also notes that models pretrained on stronger corpora, such as LLaMA3-8B, require substantially more sparse retraining tokens to fully recover perplexity. A plausible implication is that CAST is most attractive when the deployment objective is hardware-friendly semi-structured sparsity under limited but nontrivial retraining budgets, rather than maximal training-time sparsity or sparse-from-scratch optimization.

Source: https://www.emergentmind.com/topics/continuous-adaptive-sparse-trainer-cast