TL;DR
This paper introduces a principled framework that prevents corrupted or adversarial context from degrading an LLM's performance below its zero-shot baseline. By combining dynamic early-exiting with distribution-free risk control, the proposed method provides rigorous safety guarantees against "garbage in, garbage out" scenarios while simultaneously boosting computational efficiency when context is helpful.
What Problem Does This Paper Address?
In-context learning (ICL) allows large language models (LLMs) to adapt to new tasks simply by appending examples or instructions to the prompt. However, this flexibility is a double-edged sword: if the user-provided context is corrupted, misleading, or intentionally adversarial, the model's performance can tank.
Recent research shows that LLMs tend to "overthink" when given harmful context. Instead of relying on solid internal representations formed in intermediate layers, the model overfits to the bad context in its deeper layers, leading to degraded or unsafe outputs.
The authors address this challenge by establishing a built-in safeguard. They anchor the model's risk tolerance to its zero-shot performance—a stable baseline that undergoes extensive pre-deployment safety testing—ensuring that bad context cannot drag the model's accuracy below this safe floor.
Methods
The authors introduce three main technical components to achieve risk-controlled early exiting:
- Safe Context-Aware Predictor: The model evaluates tokens layer by layer. If its confidence score $C_l$ at layer $l$ meets or exceeds a calibrated threshold $\lambda$, it exits early and returns a prediction. If no layer meets the threshold, the system completely discards the context and falls back to a standard zero-shot prediction.
-
Context-Aware Loss Function: To explicitly measure overthinking, the authors design a novel loss function that computes the difference between the early-exit model's loss (with context) and the full model's zero-shot loss (without context): $$\ell_c(\lambda; x, y, c) := \ell(\bar{y}_\lambda(x, c), y) - \ell(\hat{y}(x), y)$$ A positive loss indicates that the context is harmful (worse than zero-shot), while a negative loss indicates it is helpful.
-
Domain-Preserving Risk Transformation: To find the optimal threshold $\lambda$, the authors use the Learn-then-Test (LTT) risk control framework. Standard LTT requires losses to be bounded between $[0, 1]$. Prior works simply clipped negative losses to zero, which discards valuable information about helpful context and leads to overly conservative models. This paper introduces a linear scaling technique that maps the loss from $[-1, 1]$ to $[0, 1]$, applies LTT, and then mathematically reverses the transformation to preserve the original loss distribution.
Datasets
The framework was evaluated across 9 diverse tasks spanning two main paradigms:
- In-Context Learning (Classification): Stanford Sentiment Treebank (SST-2), FinancialPhrasebank, TweetEval (Hate, Atheism, and Feminist sub-datasets), AG News, Text REtrieval Conference (TREC), and Unnatural. These tasks were tested using Llama-2-7B, Llama-3-8B, and their LayerSkip variants.
- Open-Ended Question Answering: SQuAD v2.0, utilizing a T5-Large backbone to evaluate multi-token generation with a mix of answerable (helpful) and unanswerable (adversarial/harmful) context documents.
Key Insights and Ideas
- Early Exiting as a Safety Filter: Halting inference at intermediate layers acts as a natural defense mechanism against bad context, blocking the deeper attention heads that over-index on misleading prompt data.
- Preserving the "Good" with Scaling: Retaining negative loss values during calibration is crucial. By scaling rather than clipping negative losses, the framework successfully differentiates between "performing at the baseline" and "outperforming the baseline," allowing the model to aggressively exploit helpful context for massive efficiency gains.
- Smart Fallbacks: On unanswerable or misleading questions in SQuAD v2.0, the system triggered a fallback to zero-shot predictions 3.3x more frequently than on clean, answerable questions, demonstrating excellent context-quality discrimination.
Key Results
- Robust Risk Control: Across all 5 models and 9 datasets, the empirical risk consistently remained bounded below the user-specified tolerance level ($\epsilon$).
- Substantial Speedups: By avoiding unnecessary deeper layers when confidence was high, the proposed scaling approach achieved an average of 53% fewer layers evaluated on ICL classification tasks compared to the traditional loss-clipping baseline.
- Generative Efficiency: On open-ended QA (SQuAD v2.0), the method evaluated up to 81.8% fewer layers, significantly reducing the computational footprint of multi-token generation.
Limitations and Future Work
- Layer Cutoff Heuristic: The authors empirically restricted early exiting to the second half of the model's layers (e.g., layer 16 out of 32) because early layers are frequently overconfident in incorrect answers. This cutoff might require manual tuning for different model architectures.
- Token-Level Granularity: The per-token thresholding strategy works well for short-answer QA but may face challenges in long-form generation, where a model might exhibit high confidence on a few intermediate tokens while generating a harmful response overall.
- Mixed Prompts: The current framework assumes context is uniformly helpful or harmful; future work is needed to handle prompts where helpful and corrupting information co-occur.
Summary updated