Notes ai-security
Memory Accounting
Contents
If you can verify the contents of memory, then you can verify claims about workloads which use that memory. In this post, we describe using memory accounting to verify that an H200 is only using its memory in ways consistent with running inference on a declared model.1
Two parties take part in memory accounting: a prover and a verifier.
-
Prover: The party serving inference using the GPUs.
-
Verifier: The party checking the memory use is consistent with inference.
In this post, we assume that the prover and verifier are different parties. For example, an AI company (prover) and a third-party auditor (verifier), or two nation-states (one the prover and one the verifier). If memory accounting were being used as a security system to verify the integrity of a company’s own compute, then the prover and the verifier may be the same organisation.2
How does memory accounting work?
During a setup phase, the prover declares what will be in their HBM during inference. From then onwards, the verifier, at random intervals, issues memory challenges. The prover must respond to these memory challenges with a hash of some of the data stored in the HBM. The verifier checks two things:
-
How long the response took. The setup is such that the prover can only respond to the challenge under the pass threshold if the data is in HBM,3 rather than slower storage elsewhere in the system.
-
Whether the hash is correct. The verifier compares the response to the declared data. If the data returned is not consistent with the workload that was declared at the start, then the prover fails.
For the full list, see the assumptions in the appendix.
What problems does our proof of concept address?
Problem #1. Both DRAM and HBM have high read speeds to the verifier. The verifier cannot reliably distinguish between a read from DRAM and a read from HBM.
Our solution: the challenge requires the prover to compute a matrix multiplication (matmul) on the challenged data. A GPU computes this matmul faster than a CPU. Data in DRAM must first cross the PCIe link to the GPU, which has a lower bandwidth than HBM. Therefore, a prover can respond quickly to the challenge only if they already have the challenged data in HBM.
See the challenge phase for our implementation of a challenge.
Problem #2. It is difficult to distinguish between true positives (due to cheating) and false positives (due to network jitter)
Our solution (part 1): each challenge is a hash chain: a sequence of steps, called links. Each link reads one 1 MiB block, computes the matmul on it and hashes the result. The hash selects the block for the next link, so the prover cannot read the blocks in advance or in parallel. Our chains have 128 links.4
The difference between an honest and a cheating response time increases linearly with the number of links.5 The network jitter occurs one time per challenge, for any number of links. That makes it easier to detect cheating.
Our solution (part 2): The verifier does not decide whether a prover has cheated based on a single challenge. Instead, the verifier collects a set of response times over a period of time called the test window. The verifier then tests whether the mean response time over the test window is above the threshold the verifier calculates from the timing baseline.
The variance of the mean response time goes down as the number of challenges in a test window goes up. The difference between the honest mean and the cheating mean stays constant. With more challenges, the threshold therefore separates the two better: an honest prover is rarely above it, and a cheating prover is rarely below it.
See Chain for our implementation of a chain. See the statistical test for our statistical test.
Problem #3. The weights are fixed, so the prover can declare them one time and the verifier can check each response against them. The activations and KV cache change with each layer during inference. The prover therefore can’t declare them in advance.
Our solution: with each response, the prover declares its input and the layer that it had reached. The verifier recomputes inference up to that layer, using the declared weights. The verifier then runs the same challenge on its own copy of the activations and KV cache. The two responses must be equal.
The verifier sets a fixed logical order for the activations and KV cache, so the verifier can rebuild them in the same order. A challenge selects data by logical position, and a table on the prover maps each logical position to its physical location in HBM.
The encoded weights do not fill HBM. The prover fills the remaining memory with pseudorandom filler from the verifier’s seed, and the unused dynamic region with encoded zeros (using the encoding described in the next section). Thus, the verifier can challenge “empty” memory.
Our implementation uses vLLM’s deterministic inference mode so that the verifier’s recomputation is equal to the prover’s activations, bit for bit.
See dynamic challenges in the appendix for our dynamic challenge implementation.
Problem #4. The prover can compress the declared data. For example, the prover declares the vector [7, 3, 9, 0, 0, 0, 0, 0]. The prover holds only [7, 3, 9] in HBM. Before the prover responds to a challenge, the prover appends the 5 zeros. The response is still quick. The prover now has free space in HBM for undeclared data.
Our solution: we require the prover to hold all the HBM contents in an incompressible encoding.67 Our encode operation is slow, so the prover can respond to a challenge in time only if the data is already encoded. The decode operation is fast, so the prover can decode the data on demand for inference.
We have modified Fisch’s Basic-VDE-PoRep for memory accounting. In our version, each 90-bit value holds 88 bits of data and uses about 500 operations to decode and about 4,200 operations to encode. The prover can encode and decode multiple 90-bit values in parallel. The core function that makes the encode operation slow is Sloth. No lower bound on the number of operations required for Sloth has been proved.
A prover that serves one model on many GPUs keeps the same model weights in each GPU’s HBM. However, the prover could always respond to a challenge from the same HBM and keep other data in the other HBMs. To prevent this, each GPU encodes with its own key, derived from a seed the verifier selects. Thus, each GPU must hold a different encoding of the same weights.
See Encode for our incompressible encoding implementation.
Can we detect a cheating prover?
We measured the response times of an honest prover and of 5 cheating provers. Each cheating prover cheated on 1% of the challenged static memory.8
We ran only about 4,300 challenges for each prover. To make Figure 6, we resampled: we drew new test windows of 5,000 response times at random from the measured ones, and calculated the mean over each test window.
With 10 million challenges in the test window, we could have set a threshold with our statistical test (see the statistical test). The threshold detects a prover that does not hold 1% of the declared data, with a false positive rate and a false negative rate of at most 1 in 1,000,000,000. 1,000 GPUs that each run 2.4 challenges per second respond to 10 million challenges in 69 minutes.
We have assumed that the honest baseline is trustworthy. Establishing a trusted baseline is future work (see “Next Problem #1”).
A longer test window gives better separation between the provers (see Figure 7)
See the experiment parameters for the full set of parameters we used in our experiments.
What is the slowdown of inference?
Our memory accounting implementation slows inference by a factor of 8.0. We measured this with 256 concurrent inference requests, while the verifier sent 3.5 challenges per second.
We used the same setup as in the timing experiment: the same GPU, model, encoding and challenges.9
| Change | Slowdown |
|---|---|
| Serving inference deterministically | 1.21× |
| Decoding the weights | 4.47× |
| Encoding and decoding activations and KV cache | 1.38× |
| Serving static and dynamic challenges | 1.08× |
| Total slowdown (product) | 8.01× |
Table 1. The slowdown that each change causes, relative to the row above it. The first row is relative to unmodified vLLM. We measured the slowdown with 256 concurrent requests (effectively the batch size).
How much unaccounted memory is there?
Unaccounted memory is the amount of HBM that a prover can use for undeclared data without detection. We measured 18.60 GiB of unaccounted HBM (13% of the 139.80 GiB in our H200).
Scratch memory holds decoded data. Inference decodes the data of one layer at a time into scratch memory, and a challenge does not verify decoded data.
| Category | Item | GiB |
|---|---|---|
| Scratch memory | GPU memory left available for temporary work | 3.75 |
| Buffer for the decoded KV cache of one layer | 0.67 | |
| Unused memory in the PyTorch allocator cache | 0.61 | |
| CUDA context and other memory outside PyTorch | 0.64 | |
| Buffer for decoded weights | 1.45 | |
| Other | 0.55 | |
| Scratch memory subtotal | 7.67 | |
| Other | Unaccounted memory from the incompressible encoding10 | 6.19 |
| Data that could move while inference is paused11 | 1.80 | |
| Data that could move while a chain is being computed | 1.62 | |
| Allowance for data below the assumed detection level (1% of challenged memory) | 1.32 | |
| Total | Estimated unaccounted memory | 18.60 |
Table 2. A breakdown of the unaccounted memory in our implementation
What are the next problems?
Next Problem #1. Establishing a trusted timing baseline. A prover can have an undeclared hardware accelerator, or faster software for the matmul and the hash. An honest response from that prover is faster than the timing baseline. The prover can use the time difference to cheat and still respond in time.
Some methods that could be helpful for establishing a trusted timing baseline:
-
The verifier inspecting the prover’s hardware.
-
Installing a direct connection between the prover and verifier: a separate network for memory accounting challenges.
-
Finding ways to increase the difference between an honest and a cheating response time.
-
Controlling for changes in response times by an honest prover.
Next Problem #2. Speeding up inference.
We measured our implementation of memory accounting to slow down inference by a factor of 8.0. Some possible ways to speed up inference that we want to attempt:
-
Making the decode operation of the incompressible encoding faster. This is currently causing a 4.47× slowdown.
-
Making the encode operation of the incompressible encoding faster. The verifier must still be able to detect an encode operation on demand.
Next Problem #3. Making memory accounting confidential. The verifier currently needs access to the weights to recompute the inference and the incompressible encoding.
We want to replace each recomputation with zero-knowledge proofs (ZKPs). The prover could then hide the weights, and possibly other confidential data, from the verifier.
Next Problem #4. Reducing the amount of unaccounted memory.
We measured 18.60 GiB of unaccounted memory out of the 139.80 GiB of HBM.
Some next steps:
-
Investigate whether activations and KV cache can be kept encoded in HBM and only be decoded when in GPU cache.
-
Add a filler to the 34 unaccounted bits in each 128-byte row of the incompressible encoding.
-
Interrupt inference immediately when a challenge starts, instead of a graceful pause.
-
Verify data that is in scratch memory.
Next Problem #5. Verifying DRAM and HBM in parallel.
Memory accounting verifies only HBM. The prover can run an undeclared workload from DRAM. We can make stronger guarantees if the fastest unverified memory is SSD rather than DRAM.
Next Problem #6. Red-teaming and formalising the security properties of memory accounting.
We expect more red-teaming will find some issues with our proof of concept.
For a longer list of future work, see future work.
We thank Naci Cankaya, Pascal Berrang, Wayne Tee and Irene Giacomelli for their comments on a draft of this post. All remaining mistakes are ours.
Appendix
The system splits a GPU’s memory into two regions: static and dynamic.
Static memory is any memory that does not change during inference. In the protocol, this is the model weights and any pseudo-random filler data used to verify memory declared as empty.
Dynamic memory is memory that updates during inference: KV cache, activations, and scratch. Dynamic memory also contains dynamic filler, which is used to verify empty dynamic memory when the KV cache doesn’t saturate the dynamic memory region.
Footnotes
-
DRAM could still be used for training and for performing inference on another model than the one that was declared. More details in “Next Problem #5. Verifying DRAM and HBM in parallel.” ↩
-
This could be applied in a similar way to what Anthropic described: “through a separate but related project, which signs our inference traffic and recomputes inference on a trusted server” (https://www.anthropic.com/research/provable-inference) ↩
-
Memory accounting is not able to verify whether the data is held in GPU cache rather than HBM. ↩
-
Dynamic challenges also have 128 links. ↩
-
Only up to a limit. A very long chain gives the prover sufficient time to copy or re-encode the missing data back into HBM during the challenge. See “How much unaccounted memory is there?” ↩
-
Our incompressible encoding adds a pseudorandom value derived from a key to the data during encode and then computes a modular square root. The result looks like random data. Therefore the data cannot be compressed while it is encoded. Decode recovers the original data exactly. ↩
-
The verifier recomputes the incompressible encoding to verify that the prover has computed it correctly. ↩
-
These results are for our static challenges. We use slightly different parameters for our dynamic challenges. For the corresponding graphs for dynamic challenges, see dynamic results ↩
-
Both experiments used batches of 256 requests. The throughput run generated 256 tokens per request and the timing run generated 48. The mean scheduled wait was 250 ms for throughput and 62.5 ms for timing. ↩
-
The 128-byte encoding packs eleven 90-bit values, each comprising an 89-bit root modulo 2^89 − 1 and a one-bit flag, leaving 34 fixed zero bits per row. Each value holds 88 bits of data, so a row holds 121 bytes of data. A prover can use the zero bits for undeclared data. They are 34 of the 1,024 bits in a row: 4.39 GiB of the 132.13 GiB of challenged memory. Our verifier counts more than this as unaccounted. It counts whole bits per 64-bit word. The 990 used bits in the 16 words of a row are 61.875 bits per word, and the verifier rounds this down to 61. It thus counts 3 of every 64 bits as unaccounted: the 6.19 GiB in the table. A filler for the zero bits has not been implemented. ↩
-
This estimate assumes that the prover’s mean wait before a challenge is not longer than the honest mean (about 20 ms). Our verifier does not yet test this mean. ↩