EPFL's SIPIT Recovers Exact Prompts From AI Hidden States in 28 Seconds
A new proof shows transformer hidden states are lossless encodings of their inputs, and a linear-time algorithm recovers the exact prompt from them.
ProTakeaways
- Decoder-only transformers are proven almost-surely injective at initialization and throughout gradient descent training.
- Around 5 billion pairwise comparisons across six major LLMs found zero hidden-state collisions.
- SIPIT recovers exact input prompts from hidden states with linear-time guarantees.
- SIPIT hits 100% accuracy in 28s on GPT-2, versus 6132s and 0% for HardPrompts.
- Inversion works on FP4-quantized Mistral-7B and Llama-3.1-8B exploring under 0.22% of vocabulary.
- Hidden states, KV-caches, and intermediate activations are effectively verbatim user prompts.
A common assumption about transformer language models is that they lose information as data flows through them. Non-linear activations, LayerNorm, and many-to-one attention all seem like operations that could collapse different inputs into the same internal state. A new paper from EPFL and Sapienza University of Rome argues that intuition is wrong, and backs it up with both a mathematical proof and a practical algorithm that reconstructs the exact input text from a model's hidden activations.
The result matters for anyone who has treated hidden states, KV-caches, or intermediate embeddings as safe abstractions of a prompt. They are not abstractions at all. They are the prompt, encoded losslessly, and recoverable in linear time.
The lossy transformer myth
The starting point is a widely held belief: because transformer components are non-injective in isolation, the model as a whole must discard information. Since Transformer architectures rely heavily on non-linearities, normalization, and many-to-one attention mechanisms, it is often assumed that they discard information: different inputs could collapse to the same hidden state, making exact recovery of the input impossible.
The authors challenge that view with three linked contributions. First, a proof that decoder-only transformers are almost-surely injective as maps from token sequences to last-token representations. Second, an empirical stress test with billions of collision checks across six modern language models. Third, an algorithm called SIPIT that recovers the exact input prompt from hidden states with provable linear-time guarantees.
Why collisions vanish
The math relies on treating a transformer as a real-analytic function of its parameters. Real-analytic functions have a useful property: either they are identically zero, or their zero set has Lebesgue measure zero. In practice this means that if you can find even one parameter setting where two prompts produce different last-token states, then the set of parameters where they collide is vanishingly small.
The authors verify this analyticity module by module. Each building block is real-analytic: polynomials (embeddings, projections), exponential and softmax (attention), reciprocal square root (LayerNorm with ε > 0), analytic activations in the MLP, and affine maps. They then explicitly construct witness parameter settings that separate any two distinct prompts, ruling out the degenerate case.
The second half of the proof handles training. A gradient descent step is itself a real-analytic map, and its Jacobian determinant is not identically zero. That means each update behaves like a smooth change of coordinates that cannot squash a positive-volume region onto a lower-dimensional set. Therefore, pushing forward an absolutely continuous distribution through φ yields another absolutely continuous distribution. Absolute continuity of the parameter law survives any finite number of gradient descent steps, so injectivity established at initialization persists throughout training.
Billions of collision tests, zero collisions
Theory is one thing. The authors also ran an exhaustive empirical search. They collected 100k prompts by uniformly sampling from a mixture of four datasets: wikipedia-en, C4, The Pile, and python-github-code. For each prompt, they extracted the last-token representation and systematically checked whether any two distinct prompts produced identical embeddings. This process required around 5 billion pairwise comparisons.
Across all models and layers, no collisions were found. Minimum pairwise distances stayed well above the collision threshold of 10^-6 in every experiment. A second stress test made the search even more adversarial by taking the 10 closest prompt pairs and appending every possible vocabulary token, generating over 343 billion candidate pairs per model. Still no collisions.
The models tested include:
- Llama-3.1-8B and Llama-3.1-70B
- Mistral-7B-v0.1
- Phi-4-mini-instruct and Phi-4 (14B)
- Gemma-3 (1B, 4B, 12B)
- GPT-2 Small, Medium, Large
- TinyStories-33M
Quantization did not break the property either. Across all tested models quantization (1) does not introduce any collisions, (2) more than doubles the minimum distance between representations, thereby preserving the integrity of the representation space, and (3) maintains this separation even as model size increases substantially.
SIPIT: turning theory into an inversion algorithm
Injectivity guarantees uniqueness, but not efficient recovery. That is where SIPIT (Sequential Inverse Prompt via ITerative updates) comes in. The algorithm exploits causal masking: the hidden state at position t depends only on the tokens at positions 1 through t. So once you know the prefix, the state at position t uniquely identifies the next token.
Here is the core loop in plain terms:
- Start with an empty reconstructed prefix.
- At position t, use a policy (uniform random or gradient-guided) to propose a candidate token.
- Append it to the prefix, run the forward pass, and compare the resulting hidden state to the observed one.
- If they match within tolerance, accept the token and move to position t+1. Otherwise, propose the next candidate.
The gradient-guided policy is the key to efficiency. It maintains a continuous proxy embedding that is updated by descending the squared distance between the predicted and observed hidden state, then ranks vocabulary tokens by proximity to this proxy. Worst-case complexity is T·|V| verifier calls, but in practice SIPIT explores a tiny fraction of the vocabulary.
Recovery in practice
On GPT-2 Small with 20-token prompts, SIPIT achieved 100 percent token-level accuracy in an average of 28 seconds. The comparisons are stark:
| Method | Accuracy | Mean time |
|---|---|---|
| HardPrompts | 0% | 6132s |
| BruteForce (random policy) | 100% | 3889s |
| SIPIT (gradient-guided) | 100% | 28s |
The vocabulary scaling is equally striking. SIPIT reconstructs all inputs with perfect accuracy while exploring, on average, less than 0.22% of the vocabulary, demonstrating that the gradient-based heuristic is both robust to quantization noise and highly efficient. On FP4-quantized Mistral-7B (32K vocab) inversion took around 112 seconds; on Llama-3.1-8B (128K vocab) it took around 549 seconds, with the fraction of vocabulary explored staying essentially constant.
Why this changes the threat model
The paper reframes hidden states as a privacy-sensitive surface. Any pipeline that stores, caches, or transmits intermediate activations is effectively handling the raw prompt. A leaked KV-cache, a shared inference service, or an API that exposes intermediate representations becomes a vector for prompt extraction with mathematically guaranteed exactness.
This has legal weight too. The authors note that regulators have argued LLM parameters may not constitute personal data because training text is transformed into abstract representations. But that argument does not extend to inference-time hidden states. Under this result, those states are lossless encodings of user input, and any system that persists them should be treated the same as a system storing the verbatim prompt.
Limits and open threads
SIPIT as presented assumes access to all per-position hidden states at a given layer. Recovering the exact input from only a final embedding is guaranteed in principle by the injectivity theorem, but the authors leave designing an efficient algorithm for that setting to future work. The analysis also targets decoder-only text transformers with real-analytic activations; extensions to multimodal architectures and to approximate inversion under heavier noise are open questions.
There are also adversarial failure cases. If two vocabulary embeddings are set exactly equal, or two positional embeddings collide by construction, injectivity breaks. These require deliberately engineered parameter choices, which do not arise under standard training but matter for anyone designing custom architectures with quantization, weight tying, or discrete bottlenecks.
The SIPIT implementation is available on GitHub, and the full paper includes the complete proofs, extended experiments across model families, and details on real-analytic activations used in modern LLMs.