SpectralGuard: Detecting Memory Collapse Attacks in State Space Models
Organizations: Independent Researcher
Abstract
State Space Models (SSMs) such as Mamba achieve linear-time sequence processing through input-dependent recurrence, but this mechanism introduces a critical safety vulnerability. We show that the spectral radius rho(A-bar) of the discretized transition operator governs effective memory horizon: when an adversary drives rho toward zero through gradient-based Hidden State Poisoning, memory collapses from millions of tokens to mere dozens, silently destroying reasoning capacity without triggering output-level alarms. We prove an Evasion Existence Theorem showing that for any output-only defense, adversarial inputs exist that simultaneously induce spectral collapse and evade detection, then introduce SpectralGuard, a real-time monitor that tracks spectral stability across all model layers. SpectralGuard achieves F1=0.961 against non-adaptive attackers and retains F1=0.842 under the strongest adaptive setting, with sub-15ms per-token latency. Causal interventions and cross-architecture transfer to hybrid SSM-Attention systems confirm that spectral monitoring provides a principled, deployable safety layer for recurrent foundation models.
Figures & tables
| Symbol | Definition |
|---|---|
| Continuous state transition matrix | |
| Discretized transition at token | |
| Spectral radius (max eigenvalue magnitude) | |
| -th eigenvalue of | |
| Hidden state at token | |
| Input-dependent discretization step |
| Regime | ||
|---|---|---|
| Exp 2 non-adaptive collapse | ||
| Exp 3 adaptive v1 (single-layer) | ||
| Exp 3 adaptive v2/v3 (multi-layer) | near benign target |
| Protocol | Accuracy | 95% CI | |
|---|---|---|---|
| All-layer clamp ( ) | Baseline (no clamp) | 1.00 | [1.000, 1.000] |
| All-layer clamp ( ) | 0.99 | 0.00 | [0.000, 0.037] |
| All-layer clamp ( ) | 0.95 | 0.00 | [0.000, 0.037] |
| All-layer clamp ( ) | 0.90 | 0.00 | [0.000, 0.037] |
| All-layer clamp ( ) | 0.70 | 0.00 | [0.000, 0.037] |
| All-layer clamp ( ) | 0.50 | 0.00 | [0.000, 0.037] |
| Component | Value |
|---|---|
| Architecture | Mamba (Selective SSM) |
| 768 | |
| Layers | 24 |
| 16 | |
| Vocabulary size | 50,257 |
| Total parameters | 130M |
| Metric | Benign | Adversarial |
|---|---|---|
| Mean accuracy | 72.3% | 19.8% |
| accuracy | -52.5 points | |
| Spectral radius | 0.98 | 0.32 |
| (tokens) | 45 | |
| t-test | , | |
| Effect size | Cohen’s | |
| Model | Params | F1 | FPR | |||
|---|---|---|---|---|---|---|
| Mamba-130M | 130M | 0.619 | 0.672 | 0.9086 | 0.9090 | |
| Mamba-1.4B | 1,475M | 0.591 | 0.672 | 0.9205 | 0.9211 | |
| Mamba-2.8B | 2,897M | 0.650 | 0.724 | 0.8787 | 0.8778 |
| Seed | F1 | FPR | Precision |
|---|---|---|---|
| 42 | 0.619 | 0.672 | 0.549 |
| 123 | 0.584 | 0.557 | 0.562 |
| 456 | 0.579 | 0.648 | 0.509 |
| Mean Std |
| Method | MAE vs. Eigen | Pearson |
|---|---|---|
| SVD | ||
| Power ( ) |
| Task | Benign | Adv. | |
|---|---|---|---|
| Assoc. Recall | % | % | |
| LongBench QA | % | % | |
| GSM8K Math | % | % | |
| HumanEval Code | % | % | |
| Average | 62.5% | 18.4% |
| Setting | Defense Variant | Attacker | Prec. | Rec. | F1 | AUC | FPR | Latency | N | Model |
| Output-Only Baselines (Non-adaptive) | ||||||||||
| Non-adaptive | Perplexity Filter | Non-adaptive | 0.42 | 0.31 | 0.36 | — | 0.02 | ms | 500 | Mamba-130M |
| Non-adaptive | Toxicity Classifier | Non-adaptive | 0.08 | 0.05 | 0.06 | — | 0.01 | ms | 500 | Mamba-130M |
| Non-adaptive | Pattern Matcher | Non-adaptive | 0.15 | 0.12 | 0.13 | — | — | ms | 500 | Mamba-130M |
| Non-adaptive | Internal L2-Norm Monitor | Non-adaptive | 0.62 | 0.51 | 0.56 | — | 0.05 | ms | 500 | Mamba-130M |
| SpectralGuard Variants | ||||||||||
| Threshold ( ) | Precision | Recall (TPR) | F1-Score | FPR |
|---|---|---|---|---|
| (calibrated) | ||||
| Configuration | F1 | FPR | Latency (ms) | Rec. |
|---|---|---|---|---|
| Threshold | ||||
| 0.98 | 0.03 | 4.15 | ||
| 1.00 | 0.00 | 4.15 | ||
| (default) | 1.00 | 0.00 | 4.15 | ✓ |
| 0.95 | 0.00 | 4.15 | ||
| 0.89 | 0.00 | 4.15 | ||
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
| Experiment | Primary Hardware | Notes |
|---|---|---|
| Exp 1 (Horizon) | NVIDIA T4 (16GB) | Cloud GPU, |
| Exp 2 (HiSPA collapse) | NVIDIA T4 (16GB) | Gradient-based prompt optimization |
| Exp 3 (Defense eval) | NVIDIA T4 (16GB) | 24-layer feature extraction |
| Exp 3B (Causal clamp) | CPU-only / T4 | Intervention hooks on Mamba-130M |
| Exp 4 (Scaling/robustness) | NVIDIA T4 (16GB) | Mamba-130M/1.4B/2.8B protocol |
| Exp 5 (Zamba2) | NVIDIA A100 (40GB) | Hybrid 2.7B evaluation |
LLM Security
Large language model (LLM) security studies attacks, privacy risks, and defenses across model training, inference, and deployment.
See all 322 papers