Reweighted SAM: Delta-SAM Optimization
- The paper introduces delta-SAM, which dynamically reweights per-instance gradients to create a shared adversarial perturbation that better approximates individual perturbations.
- It demonstrates improved performance on NLP tasks such as GLUE and STS while reducing adversarial risk and incurring only modest extra computational overhead.
- The method is theoretically derived using a second-order Hessian approximation and an unbiased estimator based on shared Gaussian perturbations, making complex per-instance computations tractable.
Searching arXiv for the specified paper and closely related SAM literature to ground the article. Reweighted SAM denotes a family of sharpness-aware training procedures in which a single shared adversarial weight perturbation is constructed for a mini-batch by reweighting per-instance gradients, so that the shared perturbation better approximates the stronger per-instance adversaries without incurring their prohibitive cost. In the formulation introduced as delta-SAM, or “Sharpness-Aware Minimization with Dynamic Reweighting,” the perturbation direction is obtained from a dynamically reweighted batch gradient whose weights are theoretically motivated by a second-order analysis of per-instance adversarial risk (Zhou et al., 2021).
1. Position within sharpness-aware optimization
Sharpness-Aware Minimization (SAM) adversarially perturbs model weights and minimizes the loss at the worst-case point in a small neighborhood. For a batch of size with per-instance loss , the per-batch SAM objective is
In practice, the inner maximizer is approximated by a single first-order step using the batch-average loss , yielding
The outer minimization then updates to reduce the perturbed empirical risk (Zhou et al., 2021).
Within this framework, standard per-batch SAM aggregates gradients over the mini-batch by averaging,
and one SAM step roughly doubles compute, requiring two forward and two backward passes per batch. Reweighted SAM retains the shared-perturbation structure of SAM but replaces the uniform averaging implicit in the batch gradient with instance-dependent weights. This suggests a reinterpretation of SAM in which the central design question is not only how large the perturbation radius should be, but also how the shared perturbation direction should reflect heterogeneity across instances in the same mini-batch.
2. Per-batch and per-instance adversaries
The motivation for reweighting arises from the gap between a single perturbation shared by all examples in a batch and the stronger objective in which each example receives its own adversarial perturbation. The per-instance objective is
In first-order practice, one would take
0
for each 1 (Zhou et al., 2021).
The associated sharpness increases are defined as
2
Since the inner maximizers are independent in 3, 4. The reweighted construction is therefore motivated by the observation that sharing one perturbation across the batch yields a weaker adversary than summing per-instance worst cases (Zhou et al., 2021).
The difficulty is computational. Per-instance perturbations are computationally expensive because the inner problem must be solved separately for each instance, requiring 5 backward passes and effectively distinct model copies, approximately 6 forward and 7 backward passes per batch. The data further reports that this is often unaffordable in practice. Reweighted SAM is designed precisely for this efficiency bottleneck: it attempts to retain a single batch-level perturbation while moving that perturbation toward the behavior of the per-instance adversary.
3. Theoretical derivation of dynamic reweighting
The delta-SAM derivation uses a second-order expansion
8
together with the structured Hessian assumption
9
Under the single-step inner maximization, the SAM-style perturbations are
0
Under these assumptions, the gradient of the per-instance adversarial risk, for the outer minimization and without differentiating through 1, is
2
This expression identifies the target direction that a shared perturbation should approximate if it is to mimic the gradient induced by per-instance adversarial training (Zhou et al., 2021).
For a reweighted shared perturbation 3, let
4
An ideal choice is
5
which guarantees
6
because 7 is positive definite. Since 8 is not directly available, the paper motivates approximating it by a reweighted batch gradient proportional to 9 (Zhou et al., 2021).
4. Reweighted perturbation and the delta-SAM algorithm
The dynamic weights are defined as
0
and the reweighted batch loss is
1
with 2 treated as constants for the batch. Then
3
which leads to the normalized reweighted batch gradient
4
and the perturbation
5
Writing 6 and 7, this becomes
8
This is the core “Reweighted SAM” perturbation in delta-SAM (Zhou et al., 2021).
The algorithmic step for a mini-batch 9 proceeds as follows. First, one shared 0 is sampled and, in practice, rescaled to 1. In no_grad mode, the method computes per-instance losses 2, 3, and 4, and then computes dynamic weights 5. Second, it forms 6 and backpropagates to obtain 7. Third, it computes the adversarial perturbation 8. Fourth, with perturbed weights 9, it computes the standard unweighted empirical risk 0, backpropagates, and updates 1 using the optimizer, such as SGD or Adam (Zhou et al., 2021).
The implementation details are integral to the method’s intended behavior. The three forward-only passes used to estimate 2 are performed in no_grad mode; a single shared random perturbation is used per batch to keep overhead small; the perturbation vector is normalized; and the training update is performed on the unweighted loss to avoid biasing training targets. This suggests that the reweighting is intended only to shape the adversarial direction, not to redefine the empirical objective.
5. Estimation of dynamic weights
The practical obstacle is efficient estimation of
3
Delta-SAM proposes a simple, unbiased estimator based on one shared random Gaussian weight perturbation 4 per batch and three forward passes, without backpropagation. Under the same Hessian assumption, the paper states
5
and
6
Using a single shared 7 per batch, the dynamic weight is defined as
8
where 9 avoids division by zero (Zhou et al., 2021).
The numerator is described as proxying curvature along 0 via the Hessian, while the denominator proxies gradient magnitude along 1, so that the ratio tracks 2. This is the mechanism by which delta-SAM obtains per-instance weights without computing per-instance Hessians or per-instance adversarial perturbations. A plausible implication is that the estimator’s quality depends not only on the validity of the structured Hessian assumption but also on the variance introduced by using only one random perturbation sample per batch.
The practical settings reported for this estimator include 3 with 4 rescaled to 5, and denominator floors 6 searched in 7, with the paper often using 8. Perturbation radius 9 is searched in 0 on GLUE; for STS, 1; and summarization uses 2 (Zhou et al., 2021).
6. Empirical behavior, computational profile, and limitations
The reported empirical results cover natural language understanding, self-supervised semantic textual similarity, and summarization. On GLUE development sets, BERTbase with SAM attains an average of 83.9, while delta-SAM attains 84.7; task-wise examples include MRPC 3, RTE 4, CoLA 5, and SST-2 6. For RoBERTa_large, SAM attains 89.6 and delta-SAM 90.1, with reported gains including MRPC 7, CoLA 8, and RTE 9 (Zhou et al., 2021).
In self-supervised STS, measured by Spearman’s 0, Mirror-BERTbase reports baseline 74.85, +SAM 75.50, +delta-SAM 75.72, +SAM w/ random noise 76.44, and +delta-SAM w/ random noise 76.71. Mirror-RoBERTabase reports baseline 74.98, +SAM 75.18, +delta-SAM 75.27, +SAM w/ random noise 75.90, and +delta-SAM w/ random noise 76.31. On CNN/DailyMail summarization with BART-large, the baseline reports RG-1 44.16, RG-2 21.28, RG-L 40.90, while +delta-SAM reports RG-1 44.70, RG-2 21.54, RG-L 41.81, which the data identifies as the best RG-1 and RG-L among compared methods (Zhou et al., 2021).
The paper also reports adversarial risk analysis using the per-instance metric 1 with 2. On MRPC and RTE, delta-SAM achieves lower 3 than SAM, with examples MRPC 4 and RTE 5, together with higher accuracy, approaching per-instance perturbation performance. The reported ablations state that reweighting matters, that smaller datasets show larger gains, and that moderate values of 6 matching baseline SAM often work best, whereas very large 7 can destabilize training. The paper further notes that using random input noise in self-supervised STS improves results, and that delta-SAM with random noise outperforms baselines that also use random noise (Zhou et al., 2021).
The computational profile is central to the method’s practical claim. Standard SAM uses two forward and two backward passes per batch, with time overhead approximately 8 vanilla training. Per-instance SAM requires approximately 9 forward and 0 backward passes, plus memory for distinct perturbations; empirically it is reported as approximately 1 delta-SAM for batch size 16. Delta-SAM uses the same number of backward passes as standard SAM, plus three forward-only passes per batch to estimate 2, and empirically adds only about 18% extra computational cost over SAM on average. A concrete example is BERTbase on SST-2: 118 min for SAM versus 132 min for delta-SAM, approximately 12% slower (Zhou et al., 2021).
The limitations stated in the source are correspondingly specific. Delta-SAM remains slower than vanilla training because of the extra forward passes, even though it is much cheaper than per-instance SAM. Its theoretical derivation depends on the second-order expansion and the Hessian approximation 3; deviations from these assumptions may limit the accuracy of the reweighting. The source also identifies potential extensions, including better curvature estimation, multiple random perturbation samples to reduce estimator variance, integration with ASAM or GSAM or trust-region methods, and per-layer or blockwise reweighting on broader task families such as sequence tagging and question answering. This suggests that reweighted SAM is best understood not as a replacement for sharpness-aware optimization in general, but as a specific mechanism for approximating per-instance adversarial weight perturbations under a constrained computational budget (Zhou et al., 2021).