Scaling Laws for Adversarial Attacks on Language Model ActivationsScaling Laws for Adversarial Attacks on Language Model Activations
The authors study adversarial attacks on language model activations and state that controlling the activations of a single token can precisely determine up to about 119 subsequent tokens (pythia-1.4b-v0), and they give a linear scaling law.
Attacker goal: make the model output the attacker-specified t-token sequence as the argmax continuation. Knowledge and capability: can directly modify the activations (residual stream, after the embedding layer) of the first a tokens in the context, adding a perturbation vector P; the authors state that retrieval-augmented and multimodal models inject external data directly as activations, providing this kind of access. Victim system: a language model. The control experiment also considers an attacker who can only replace the first a input tokens.
- Can the activations (residual stream) of a language model be precisely controlled by adversarial perturbations to determine subsequent generation? The authors state that retrieval-augmented and multimodal models inject external data directly as activations, giving this attack surface practical significance.
- Add perturbation P to the activations of the first a tokens in the context, use Adam to optimize the cross-entropy loss so that the model's argmax outputs a specified t-token sequence; scan t and fit a sigmoid to read off tmax at the 50% success rate, estimate the scaling law tmax = κfa/n, and compare with a greedy token replacement attack.
- Across 8 models (33M–2.8B), κ ranges from 24.2 (pythia-70m) to 128.4 (pythia-1.4b-v0), and the pythia series χ is between about 15–25; the token replacement attack has κtoken≈0.12; attack strength does not decrease within a 100-token gap between attack and target, and at 2000 tokens κ≈8.
- Future directions listed by the authors: attacking deeper activations, using natural language contexts and targets, and limiting perturbation size (L∞/L2 norms). Experiments use only random token sequences and 8 open-source models, and the attack is not demonstrated on commercial models or real retrieval/multimodal systems.
- Evaluated models
- pythia-70mpythia-160mpythia-410m-dedupedpythia-1.4b-v0pythia-2.8b-v0Phi-1Phi-1.5TinyStories-33M
- Benchmarks
- 随机均匀采样的 token 序列作为上下文 S 和目标 T(无现成基准)
- Metrics
- 攻击成功率 p(a, t)(argmax 命中目标 token 的比例)tmax(成功率降至 50% 的目标长度)attack multiplier κattack resistance χ
Stanislav Fort's paper demonstrates a class of adversarial attacks targeting language model activations, in which manipulating a relatively small number of model activations can precisely control the predictions of up to the next 1000 tokens. Experiments verify the scaling law t_max = κa, namely that the upper limit on the number of controllable target tokens is linear in the number of activation tokens controlled by the attacker. The attack resistance χ (the number of input control bits needed to control one output bit), which measures attack difficulty, is stable at about 16 to 25 across different language models and across two orders of magnitude of model scale. The authors find that attacking activations is predictably far stronger than attacking tokens, but whether via activations or tokens, one input bit can exert a similar amount of output control, which supports the hypothesis that adversarial attacks arise from a dimensionality mismatch between input and output spaces. The paper also points out that multimodal and some retrieval models directly incorporate additional data sources in the form of activations, bypassing tokenized input, thereby opening a new and broad attack surface.
Paper analysis
What problem does this paper attempt to solve?
Research on adversarial attacks on language model activations: how many subsequent tokens can be precisely determined by controlling the activations of a small number of tokens, and seeking its scaling law.
Core question: to what extent can an attacker precisely control subsequently generated tokens by manipulating the activations (residual stream) of a small number of tokens in a language model, and how does this control capability scale with attack size.
- Why it matters (per the authors): Adversarial attacks bear on model security and reliability; the authors claim that retrieval-augmented models (e.g., Borgeaud et al., 2022) and multimodal models (e.g., Alayrac et al., 2022) concatenate external data directly into the model as activations, bypassing tokenized input, opening an attack surface for directly manipulating activations to attackers who can control the retrieval pipeline or modality inputs.
- Gaps in existing research (per the paper): Adversarial example research has focused mainly on image classifiers; language model inputs are discrete tokens and generation is autoregressive, differing from the image classification setting, and the case where output dimensionality far exceeds input dimensionality is difficult to experiment with in computer vision.
- Core hypothesis: The authors hypothesize that the key cause of adversarial susceptibility is a mismatch between the dimensionality of the attacker-controllable input space and that of the output space, and on this basis predict that the controllable target length tmax is linear in attack length a.
- What the paper proposes: A set of adversarial attack methods and theoretical analysis on activations, giving the empirical scaling law tmax = κfa/n, defining attack multiplier κ and attack resistance χ, measured on 8 models (33M–2.8B), and compared with a token replacement attack.
- Threat model:
- Goal: Make the model output the attacker-specified t-token sequence as the argmax-sampled continuation.
- Knowledge: The paper optimizes in a white-box manner (using model gradients), but does not explicitly define the threat model using white-box/black-box terminology.
- Capability: Directly modify the activations of the first a tokens in the context (after the embedding layer) by adding an arbitrary perturbation vector P; in the comparison experiment the attacker can only replace the first a input tokens.
- Victim system: Language models; the authors claim retrieval-augmented and multimodal models are scenarios that practically expose activation access.
What related research exists?
Related work falls into four groups: adversarial attacks and the dimensionality hypothesis, scaling laws, activation manipulation and jailbreaks, and system-level attack surfaces; this paper has no learned baseline, and the comparison is a token replacement attack.
Adversarial attacks and the dimensionality mismatch hypothesis
- Szegedy et al. (2013)——found adversarial examples on image classifiers; this paper follows their technique of directly optimizing perturbations with gradients.
- Goodfellow et al. (2015), Abadi et al. (2016), Ilyas et al. (2019)——the paper claims that arguments similar to "input dimensionality much larger than output dimensionality leads to adversarial susceptibility" can be traced in these works.
- Fort (2023)——proposed multi-attack: a single perturbation classifies n images into n attacker-specified classes; this paper borrows this setting to have a single activation perturbation simultaneously attack n context-target pairs.
Scaling laws
- Kaplan et al. (2020), Hoffmann et al. (2022)——scaling laws of language model performance with parameter count and data amount; Frantar et al. (2023)——scaling laws of sparsely connected models.
- Fort et al. (2021)——empirical dependence between classification accuracy and near out-of-distribution robustness; Herculano-Houzel (2012), Kabadayi et al. (2016)——scaling relationship between neuron count and brain mass in biological neural networks.
Activation manipulation and jailbreaks
- Turner et al. (2023)——activation addition, which can control model outputs to some extent without optimization.
- Zou et al. (2023a)——directly modifying model activations (representation engineering).
- Zou et al. (2023b)——using a mix of greedy and gradient methods to find token suffixes that jailbreak LLMs; Wang et al. (2023)——claims that larger models are more easily jailbroken because they are better at following instructions.
System-level attack surfaces and attacks on vision models
- Debenedetti et al. (2023)——the paper cites its view: understanding the full LLM system rather than only analyzing the main model is important for security, and additional components on top of the main model open additional attack surfaces; Casper et al. (2023)——similar issues are also emphasized among open problems of RLHF.
- Fort (2021a, 2021b)——attacks on vision models such as CLIP.
Baselines and benchmarks: The paper uses no external benchmarks or learned baselines; the comparison method is the greedy per-token exhaustive replacement attack implemented by the paper itself (Algorithm 2), compared with the activation attack on pythia-70m (Table 2).
Positioning of this paper: The authors claim that language models can serve as a controllable test-bed, exponentially adjusting input and output space dimensionality via a and t respectively, entering the "output dimensionality dominant" experimental regime unreachable in computer vision.
How does the paper address this problem?
Perturb the activations of the first a tokens and use gradient optimization to make the model output a specified sequence, sweep the target length and fit a sigmoid to read off tmax, and estimate the scaling law tmax = κfa/n.
Overall approach: treat the language model as a classifier from continuous activations to t-token continuations (V^t in total), add perturbation P to the activations of the first a tokens, use gradient descent to make the model's argmax output the attacker-specified target sequence, then systematically scan parameters such as attack length a and target length t, and fit the scaling law.
Problem setting and formalization
- The input sequence S contains s tokens; the attacker controls the activations of the first a tokens (a ≤ s), with the goal of making the model continue with a specified t-token sequence T.
- Success criterion: for the j-th token in T, after concatenating S with the first j−1 target tokens and adding perturbation P, the argmax prediction equals T[j]; if all hit, the attack succeeds.
- Theoretical prediction: tmax = κ f a / n, where κ is the model-specific attack multiplier, f is the fraction of activation dimensions used, and n is the number of context-target pairs the same perturbation must attack simultaneously. Meaning: the controllable target length is proportional to the effective attack strength fa/n.
- From geometric theory, κ = dp/(χ log2 V), where d is the activation dimensionality, p is the floating-point precision (16 bit), V is the vocabulary size, and χ is attack resistance (the number of input bits needed to control 1 bit of output at the input side); theory predicts that with fixed χ, κ is proportional to d.
Activation attack and optimization
- Split the model after the embedding layer into fbefore and fafter, with the perturbation added to the embedding output; the authors claim they explored splitting at deeper layers, but all detailed experiments are performed after the embedding layer.
- The loss is the standard language modeling cross-entropy, computed and averaged position by position over the t target tokens (Algorithm 1).
- Optimize P with the Adam optimizer, learning rate 10−1, 300 steps; the stopping condition is reaching the step limit or the target sequence becoming the argmax continuation.
κ measurement procedure
- Both context S and target T are uniformly randomly sampled from the vocabulary; for a fixed (a, t), repeat the experiment multiple times, with the success rate being the proportion of argmax hits on target tokens, yielding the p(a, t) curve.
- Fit a sigmoid to p(a, t) and read off tmax where the success rate drops to 50% (the authors note 50% is an arbitrarily chosen threshold).
- Use multi-attack (n = 1 to 8, with gradients accumulated over n (S, T) pairs) and the dimension fraction f (randomly uniformly selecting dimensions) to push the effective attack strength below a = 1, verifying that tmax depends only on fa/n.
Comparison: token replacement attack
- Greedy, per-token exhaustive search: for each of the first a tokens, iterate over all V candidates and keep the one that minimizes the target continuation loss (Algorithm 2), guaranteeing convergence within aV steps.
- Similarly fit a sigmoid to read off the minimum attack length amin, compute κtoken = t/amin, and use it to test the theoretical prediction κtoken/κ = log2(V)/(dp).
Gap between attack and target
- Fixing pythia-70m, insert s random tokens between attack and target (s from 1 to 2000, logarithmically spaced), measure the κ(s) curve, and test the decay of attack strength with gap.
What experiments did the paper conduct?
Measured the activation attack scaling law on 8 models: pythia series κ is 24.2–128.4, χ about 15–25; token replacement attack κtoken≈0.12; strength does not decrease within a 100-token gap.
Experimental setup
- Models tested: EleutherAI/pythia-70m, 160m, 410m-deduped, 1.4b-v0, 2.8b-v0, microsoft/phi-1, phi-1.5, roneneldan/TinyStories-33M, 8 in total, with parameter counts from 33M to 2.8B, activation dimension d from 512 to 2560, and vocabularies of about 50,000 each.
- Data: Both the context S and the target T are token sequences sampled uniformly at random from the vocabulary; there is no existing benchmark.
- Optimization setup: Adam, learning rate 10−1, 300 steps; activations in float16; a single A100 GPU (Google Colab).
- Metrics: attack success rate p(a, t) (the proportion of argmax hits on the target token); tmax (the target length at which the success rate drops to 50% after fitting a sigmoid); κ = tmax/a; χ = dp/(κ log2 V).
- Sweep ranges: t from 1 to usually more than 1000 (log-spaced); a = 1–16 (varies by model); n = 1–8; each (a, t) setting was repeated multiple times with standard deviations recorded (the paper does not report the specific number of repetitions).
- Control: greedy token replacement attack on pythia-70m, s = 40, t = 1, 2, 4.
Main results
According to Table 1 (activation attack, f = 1, variation in n folded into the fit):
Swipe horizontally to read the table
Model Parameters d κ d/κ χ pythia-70m 70M 512 24.2 ± 0.8 21.2 ± 0.7 21.7 ± 0.7 pythia-160m 160M 768 36.2 ± 2.0 21.2 ± 1.2 21.7 ± 1.2 pythia-410m-deduped 410M 1024 70.1 ± 2.3 14.6 ± 0.5 15.0 ± 0.5 pythia-1.4b-v0 1.4B 2048 128.4 ± 3.7 16.0 ± 0.5 16.3 ± 0.5 pythia-2.8b-v0 2.8B 2560 104.9 ± 2.2 24.4 ± 0.5 25.0 ± 0.5 Phi-1 1.3B 2048 42.8 ± 2.3 47.9 ± 2.6 49.0 ± 2.6 Phi-1.5 1.3B 2048 78.4 ± 5.1 26.1 ± 1.7 26.8 ± 1.7 TinyStories-33M 33M 768 27.2 ± 2.2 28.2 ± 2.3 28.9 ± 2.3 - The authors state that tmax is linear in the effective attack strength fa/n, consistent with the theoretical prediction (Figure 5b, each subplot of Figure 7).
- The authors state that χ for the pythia series is about 15–25 and remains close to constant across two orders of magnitude of model scale, which they argue supports the hypothesis that "adversarial susceptibility is a dimension mismatch problem"; Phi-1's χ = 49.0 ± 2.6 is clearly higher than the pythia series.
- The authors state that κ grows with the activation dimension d rather than with parameter count, consistent with the theoretical prediction κ ∝ d.
Consistency of the dimension ratio with multi-attack
- What was measured: On pythia-1.4b-v0, a (1–8), n (1–8), f (1/8–1/2) and combinations were varied separately, for 12 experiment groups in total (Figure 6).
- Results: All combinations fall on the same theoretical line tmax = κfa/n; the fitted κ = 128.4 ± 3.7 is consistent within 2σ with the κ = 119.2 ± 2.9 estimated using only a and n (Figure 5 main text; the figure caption says 119.0 ± 2.9).
- Authors' interpretation: The attack strength depends only on the product fa/n, independent of the specific implementation.
Comparison with token replacement attack
- What was measured: Greedy exhaustive replacement of the first a tokens on pythia-70m, s = 40, t = 1, 2, 4 (Figure 9).
- Results: amin is 11.7 ± 0.2, 16.7 ± 0.2, and 33.4 ± 1.1 respectively; the weighted average κtoken ≈ 0.12, i.e., about 8 input tokens are needed to control 1 output token; the activation attack corresponds to χ ≈ 21.7, and the token attack χtoken = 8.3 (Table 2).
- Authors' interpretation: The theoretical prediction is κtoken/κ ≈ 2 × 10−3, and the measured value is ≈ 5 × 10−3, which the authors describe as matching within an order of magnitude; the token attack is in fact more efficient when counted in bits (χtoken = 8.3 < 21.7), which the authors consider reasonable because models are trained on tokens rather than arbitrary activation vectors, and they state that tokenization is in some sense a strong defense.
Gap between attack and target
- What was measured: On pythia-70m, 1–2000 random tokens were inserted between the attack and the target, and κ(s) was measured (Figure 8).
- Results: κ does not drop noticeably within a gap of 100 tokens (labeled 24.3 ± 0.7 on the figure); afterward it decreases linearly with log(s); at a gap of 2000 tokens, κ ≈ 8.
- Authors' interpretation: Even when the attack and the target are separated by the entire context window, the activations of the first token can still control about 8 output tokens.
Other ablations and analyses
- Deeper-layer splitting: The authors state that they explored splitting the model at deeper layers to perform the activation attack, with equally good results, but give no detailed numbers (Conclusion).
- Natural-language context/target: The authors state that preliminary experiments showed no large difference compared with random tokens, without giving numbers (Conclusion).
- Two estimates of κ for pythia-1.4b-v0: Figure 5 (varying only a and n) gives 119.2 ± 2.9, Figure 6 (incorporating variation in f) gives 128.4 ± 3.7, and Table 1 uses the latter.
What are some points that can be further explored?
The authors list three future directions (deeper layers, natural language, norm-limited perturbations); experiments are limited to random tokens, 8 open-source models, and float16.
Limitations and future directions noted by the authors
- Attacking deeper activations: The authors claim it is worth exploring attacks on activations after the first layer, and claim they tested this and it worked equally well (Conclusion).
- Natural language contexts and targets: The authors claim it is worth replacing randomly sampled tokens with natural language strings, and claim preliminary experiments showed no large difference (Conclusion).
- Size-limited perturbations: The authors claim it is worth studying attacks that limit perturbation size with L∞ or L2 norms as in computer vision (Conclusion).
- 50% threshold is arbitrary: The authors note that the 50% success rate threshold used for tmax is arbitrarily chosen and could be chosen otherwise (Section 3.4).
- Exploiting activation precision: The authors point out that after training the model may not use the full 16-bit precision, so the effective precision peffective may be less than p (Section 2.3, 2.5).
- Effect of adversarial training: The authors assume χ is constant across models, but note that adversarial training would likely change χ (Section 2.4).
Scope of experiments
- The models tested are 5 from the pythia series, 2 from the Phi series, and 1 TinyStories, 8 open-source models in total, with 33M–2.8B parameters (Table 1).
- Contexts and targets are all tokens uniformly randomly sampled from the vocabulary; the paper reports no quantitative results on natural language text (Section 3.4, Conclusion).
- All activation attacks are performed on activations after the embedding layer; the deeper-layer split is only a qualitative statement (Section 3.1).
- The token replacement comparison is only performed on pythia-70m with s = 40 and t = 1/2/4 (Section 4.5).
- The paper reports neither the number of repetitions for each (a, t) setting nor a demonstration of the attack on commercial models or real retrieval/multimodal systems; the practical attack surface is argued only by citing the architectures of Borgeaud et al. (2022) and Alayrac et al. (2022) (Introduction).
Summarize the main content of the paper
The authors propose and measure a scaling law for adversarial attacks on language model activations, claiming that the activation of a single token can control tens to hundreds of output tokens, with χ approximately constant across model scales.
An empirical study on adversarial attacks on language model activations: the attacker adds perturbations to the activations of the first a tokens in the context (after the embedding layer), causing the model's argmax output to be a specified t-token sequence, and systematically measures the scaling law of this control capability.
- Motivation: The authors hypothesize that adversarial susceptibility stems from a mismatch between the dimensionality of the attacker-controllable input and the dimensionality of the output; language models can adjust input and output dimensionality via a and t respectively, making them a controllable test-bed for studying this hypothesis. The authors claim that retrieval-augmented and multimodal models inject external data directly as activations, giving activation attacks a practical attack surface.
- Method: Use Adam (learning rate 10−1, 300 steps) to optimize the cross-entropy loss of the activation perturbation; scan target length t and fit a sigmoid, read off tmax at the 50% success rate, and verify the scaling law tmax = κfa/n (f is the dimension fraction, n is the number of sequences attacked simultaneously).
- Main results: Across 8 models (33M–2.8B), κ ranges from 24.2 ± 0.8 (pythia-70m) to 128.4 ± 3.7 (pythia-1.4b-v0) (Table 1); the pythia series attack resistance χ is between 15.0–25.0, approximately constant across two orders of magnitude of model scale, which the authors claim supports the dimensionality mismatch hypothesis.
- Token comparison: On pythia-70m, the greedy token replacement attack has κtoken ≈ 0.12 (about 8 input tokens control 1 output token); the measured strength ratio to the activation attack is ≈ 5 × 10−3, with a theoretical prediction of 2 × 10−3; the authors claim that after converting to bits the two attack strengths are close, and that tokenization itself amounts to a defense.
- Robustness: Attack strength does not decrease within a 100-token gap between attack and target; at a 2000-token gap, κ ≈ 8 (pythia-70m, Figure 8).
- Authors' conclusion: Activation attacks can precisely control up to O(100) subsequent tokens, constituting a vulnerability worth attention; future directions include attacking deeper layers, natural language contexts, and norm-limited perturbations.