[KongchangAI]
· 2 min read· 1,321 words

Sketching Algorithm Drastically Reduces Context Attribution Costs

Sketching Algorithm Drastically Reduces Context Attribution Costs

Proposes a sketching-based context attribution algorithm reducing Leave-One-Out evaluations from n to O(√log(1/ε)/ε), with proven theoretical optimality.

This article introduces the research findings of "Sketching Language Models for Context Attribution," addressing the high computational cost of Leave-One-Out (LOO) in context attribution. Traditional LOO requires full model evaluation per token, with costs growing linearly with prompt length. The researchers propose a sketching-based approximate algorithm that, under a stability assumption, estimates all LOO values with only O(√log(1/ε)/ε) evaluations, with error proportional to ε. The key technique is applying forward-mode differentiation to the backpropagation circuit to reduce sketch variance. Theoretical proofs provide a matching lower bound, showing optimality in the oracle model. Experiments on small-scale language model retrieval tasks validated coefficient decay consistency with the stability assumption, but large-scale validation remains untested. This work offers new ideas for reducing attribution costs and identifies open questions such as the universality of the stability assumption.

The Core Challenge of Context Attribution

Context attribution (Context Attribution) answers a key question: which part of the prompt, when removed, most significantly changes the language model's output? The most direct approach is Leave-One-Out (LOO)—for a prompt containing n tokens, remove each token one by one and re-run the model to observe output changes. But this method requires n full model evaluations, making the computational cost prohibitive for long prompts.

According to the recent study "Sketching Language Models for Context Attribution," researchers propose an approximate algorithm based on sketching that, under a stability assumption, requires only O(√log(1/ε)/ε) evaluation calls to estimate all LOO values, with error proportional to ε and constant probability guarantees. Compared to the n evaluations required for direct computation, this achieves significant efficiency gains in long-prompt scenarios.

Sketching Algorithm Research Overview

Leave-One-Out (LOO) is a fundamental perturbation method in model interpretability: given an input sequence, each element (such as a token) is removed in turn, and the magnitude of change in the model output is observed as a measure of that element's importance. In context attribution, LOO values directly reflect each token's marginal contribution to the model output. However, its computational cost scales linearly with input length n, because each token removal requires a full forward pass. For long prompts (such as retrieval-augmented generation scenarios with thousands of tokens), this means thousands of model calls—an enormous overhead. Therefore, approximate algorithms need to significantly reduce the number of evaluations while keeping error controllable, which is precisely the problem the sketching method attempts to solve.

Technical Breakthrough: From Arithmetic Circuits to Backpropagation

The algorithm's technical foundation comes from Gunn's recently proposed arithmetic circuit sketching method—when the circuit's Taylor coefficients satisfy a stability condition, the coefficients can be efficiently estimated. But directly applying its forward-mode differentiation sketching requires Õ(log(n)/ε²) evaluation calls, a limited improvement.

The researchers' key observation is that forward-mode differentiation can be applied to the backpropagation circuit, adding only constant overhead relative to a forward sketch of the same Taylor degree. This operation reduces the sketch variance and becomes the key to improving the evaluation upper bound. Simply put, they perform sketching not in the forward pass but in the backward pass—allowing each evaluation to carry more useful information.

Arithmetic Circuit is a directed acyclic graph composed of basic operations such as addition and multiplication during computation, commonly used to represent the computation of polynomials or complex functions. Sketching is a technique that compresses high-dimensional objects into low-dimensional "sketches" via random projection, aiming to approximately compute target quantities (such as matrix traces or polynomial coefficients) with fewer resources. On arithmetic circuits, sketching can be used to efficiently estimate Taylor coefficients: when the circuit satisfies the stability condition (i.e., higher-order Taylor coefficients decay rapidly), only a small number of evaluations is needed to reconstruct the coefficients. Forward-mode Differentiation is an automatic differentiation technique that evaluates a circuit by simultaneously computing the function value and its derivatives, but using it directly for sketching leads to high variance and requires more evaluations. The researchers combined forward-mode differentiation with backpropagation, leveraging the structure of gradients in backpropagation to reduce variance, thereby improving evaluation complexity.

Theoretical Guarantees: Matching Upper and Lower Bounds

Beyond the algorithm itself, the paper also provides a matching lower bound proof: in the oracle model, any algorithm requires at least Ω(√log(1/ε)/ε) evaluation calls. The upper and lower bounds agree in order of magnitude, indicating that the algorithm is theoretically tight—no algorithm can significantly reduce the number of evaluations under the same error requirement.

The lower bound proof draws on techniques published by Amsel, Chen, Duman Keles, Halikias, Musco, and Musco in the SIAM Journal on Matrix Analysis and Applications for lower-bounding the number of matrix-vector queries needed to estimate diagonal entries of random matrices. This cross-disciplinary transfer of tools reflects the value of the intersection between theoretical computer science and machine learning.

Oracle model in theoretical analysis typically refers to an idealized computational model that can access certain basic operations (such as matrix-vector multiplication) at unit cost but does not restrict other computational resources. In this model, the algorithm can execute queries exactly, but the number of queries is the key metric of efficiency. A lower bound proof aims to show how many queries any algorithm (even with unlimited computational power) needs at minimum under a given error requirement, thereby establishing the inherent difficulty of the problem. This paper proves the Ω(√log(1/ε)/ε) lower bound by reduction to the random matrix diagonal estimation problem, which matches the algorithm's upper bound, indicating that the algorithm is already optimal in the oracle model. This lower bound technique originates from the matrix sketching literature in numerical linear algebra, demonstrating the value of transferring theoretical tools.

Experimental Validation: Coefficient Decay and Retrieval Tasks

Empirically, the researchers validated the algorithm's performance on a small language model retrieval task. They observed a coefficient decay phenomenon consistent with the stability assumption—a prerequisite for the algorithm's effectiveness. Evaluation on retrieval tasks showed that the sketching algorithm can complete context attribution with fewer evaluations.

As a side note, the experimental scale is small and has not yet been validated on large-scale language models and long-context scenarios. Whether the stability assumption generally holds in real models still requires more empirical research.

Coefficient decay phenomenon refers to the rapid decrease of higher-order coefficients as the order increases in Taylor expansion. In sketching theory, the stability assumption requires this decay to be fast enough to ensure that a low-order sketch can effectively approximate the entire function. If coefficient decay is slow, a higher-order sketch is needed, increasing the number of evaluations. In language models, coefficient decay may be related to the model's sensitivity to input perturbations: the output's response to token removal may be concentrated in the first few orders. The experiments indirectly validated the decay by computing the distribution of LOO values, but it should be noted that observations on small-scale models may not generalize to large models, which may have more complex context dependencies leading to slower decay.

Practical Significance and Open Questions

Context attribution has practical value for understanding language model interpretability, prompt engineering optimization, and evidence tracing in retrieval-augmented generation (RAG). This work's contribution lies in introducing sketching tools from theoretical computer science into language model analysis, providing new ideas for reducing attribution costs.

One question worth noting: how long can the stability assumption hold in real models? If coefficients do not decay or decay slowly, the algorithm's advantages may be diminished. Additionally, how to extend this method to more complex measurement functions (such as generation quality scores) rather than simple output changes is also a direction for future research.

For AI application developers, this research suggests a path: instead of performing full evaluations for every token, carefully designed sketching strategies can yield reliable attribution signals with fewer calls. As prompt length grows, the relative advantage of this method becomes more pronounced.

One-line Summary

Proposes a sketching-based context attribution algorithm that reduces Leave-One-Out evaluations from n to O(√log(1/ε)/ε), and proves theoretical optimality.

Paragraph Summary

This article introduces the research findings of "Sketching Language Models for Context Attribution," aimed at solving the excessive computational cost of Leave-One-Out (LOO) in context attribution. Traditional LOO requires full model evaluations for each token, with costs growing linearly with prompt length. The researchers propose an approximate algorithm based on sketching that, under a stability assumption, requires only O(√log(1/ε)/ε) evaluations to estimate all LOO values, with error proportional to ε. The key technique is applying forward-mode differentiation to the backpropagation circuit to reduce sketch variance. Theoretical proofs provide a matching lower bound, showing the algorithm is optimal in the oracle model. Experiments on small-scale language model retrieval tasks validated the consistency of coefficient decay with the stability assumption, but have not yet been tested in large-scale scenarios. This work provides new ideas for reducing attribution costs and identifies open questions such as the universality of the stability assumption.

#context attribution#sketching algorithm#Leave-One-Out#language model interpretability#retrieval-augmented generation
Share:

Related articles