This paper, recently published by researchers at Singapore’s Home Team Science and Technology Agency (HTX), introduces a novel forensic technique for "wiretapping" the internal thoughts of a running Large Language Model (LLM). By extracting transient hidden states directly from GPU memory, the authors demonstrate that we can audit the behavior of a live AI service without needing its source code, weights, or even the ability to restart it.
TL;DR
The authors present a method to extract per-layer "residual stream" activations from a live, unmodified GPU process using a non-modifying debugger. This technique allows for request-level attribution—such as detecting if a model is about to refuse a prompt—with byte-exact accuracy across 33 different model architectures, all without prior knowledge of the model's internal parameters.
What Problem Does This Paper Address?
Traditional memory forensics for machine learning usually targets "static artifacts": the model weights stored on disk or the text logs of prompts and completions. However, these don't capture the transient computational state—the "hidden states" that exist only for milliseconds while the GPU is processing a specific request.
In a forensic or compliance scenario, an examiner might need to analyze a running LLM service that cannot be modified or restarted. Because LLMs reuse memory buffers immediately after a calculation, these internal states are ephemeral. Current tools can't "see" inside this black box to understand why a model produced a specific output or to verify its internal mechanics during a live session. The challenge is identifying which of the thousands of dynamic memory allocations in VRAM actually represent the model's core "residual stream" (the running sum of information passed between layers).
Methods
The researchers developed a six-stage pipeline: Attach, Clock, Identify, Read, Validate, and Use.
- Non-Modifying Attachment: They use
ptraceandcuda-gdbto attach to a running process. Crucially, they do not use code injection (likeLD_PRELOAD), ensuring the target's integrity is maintained for forensic validity. - Clocking: To know when to look at memory, they implement two types of "clocks":
- Allocator Clock: Hooks into PyTorch’s caching allocator to log the birth and death of every tensor.
- Kernel-Launch Clock: For optimized engines like vLLM that use CUDA graphs, they break on every GPU kernel launch to track data flow.
- Blind Selection: This is the core innovation. The system identifies the residual stream by looking for "hand-off chains"—patterns where one tensor is freed exactly as the next one of the same size is allocated. This allows them to find the "spine" of the model's computation without knowing the model's name or architecture.
- VRAM Reading: They read the raw bytes from video memory exactly one allocation after a tensor's birth to ensure the GPU has finished writing the results.
- Downstream Analysis: Once recovered, they apply linear probes—simple classifiers trained on standard activations—to the forensic data to interpret the model's "behavioral intent."
Datasets
The method was validated across a diverse set of models and prompts:
- Models: 33 open-source decoder-only models across nine architecture classes (including Qwen, Llama, GPT-2, and Pythia), ranging up to 7B parameters.
- Prompt Sets:
- Development: 228 chat-templated prompts used to refine the selection rules.
- Evaluation (Experiment A): 142 "untouched" prompts from HarmBench (harmful behaviors) and XSTest (exaggerated safety tests) to test refusal detection.
Key Insights and Ideas
- Structure from Shape: You can derive a model's "envelope"—its token count, hidden dimension size, and layer count—purely from the shape and timing of its memory allocations. You don't need the model's identity to map its internal structure.
- Temporal is the new Spatial: In modern GPU computing, memory addresses are recycled so quickly that "where" a tensor is matters less than "when" it appears in the sequence of allocations.
- Byte-Exact Fidelity: The researchers proved that a debugger-based approach can recover activations that are bit-for-bit identical to those captured by internal software hooks.
- Refusal is Forensically Detectable: The "refusal signal" (the internal state that indicates a model is about to say "I cannot fulfill this request") is robust enough to survive this forensic extraction process.
Key Results
- Universal Applicability: The "two-step selector" achieved byte-exact recovery on all 33 tested models.
- Refusal Detection Performance: Using a linear probe on the recovered states, the authors achieved an AUROC of 0.88 in distinguishing refusal from compliance on the held-out test set.
- Attribute Accuracy: As shown in the table below, the system was highly accurate in deriving structural attributes (token/layer counts) across different serving platforms.
- Performance Cost: The primary trade-off is speed. Attaching a debugger and breaking on every allocation causes a massive slowdown—ranging from 46x to 192x slower than native execution.
Limitations and Future Work
- Intrusiveness: While the method doesn't modify code, the significant performance hit makes it "intrusive." It’s a tool for a forensic lab, not for real-time monitoring of a high-traffic production server.
- Hardware/Software Bounds: The current implementation is specific to the PyTorch caching allocator and NVIDIA GPUs. Custom engines like TensorRT-LLM remain "untested or not testable" with the current adapters.
- Batch Size: The study focused on batch size 1. Dynamic batching and continuous batching in production environments would significantly complicate the "blind selector" logic.
- Future Directions: The authors suggest that future work could involve optimizing the debugger overhead and extending the technique to Mixture-of-Experts (MoE) architectures and larger-scale deployments.
Summary updated