Correctness of the KV cache: incremental calculation to align to full forward
The old position does not read the future token since the decoding has been returned, and their key values are therefore available for cache under the same prefix and calculation conditions.
Learning objectives and first steps2 objectives . 1 first fix
Try to do it after reading
- Explains the correctness of the KV cache: the mechanism and premise for full forward alignment of incremental calculations
- Positioning the mechanism ' s fault limits with fixed examples
Suggested first
- Re-entry Visible Range & Location Encoding
Issues and mechanisms
The old position does not read the future token since the decoding has been returned, and their key values are therefore available for cache under the same prefix and calculation conditions. New position only generates its own query key and reads the history cache. This reuse reduces double counting, provided that input, location, mask and model status are consistent with complete forward; Cache is not a summary of text that can be randomly spelt out.
The most useful correctness test is not to compare the similarities of the final sentence, but to set a fixed short sequence, which is more complete after closing the randomity and corresponds to logits on token. Check the first location and layer where the difference occurs, and then position deviations, cache length and whether this step is repeated. Samples vary in size, and it is advisable to check fractions before sampling.
A concrete example
Synthetic prefix length three. Cache is saved at zero, one, two. When processing the fourth token, the new location number should read III; The length of the focus key should include the old three and the first step. If the new position is wrongly set at zero, the rotation or absolute position relationship changes; History may be repeated if the complete prefix is sent back to the cache. Both errors may be legal in shape, so a mere examination of the dimension of the length is not sufficient to justify the reuse.
Borders and checks
Prefix sharing needs to ensure that the complete prefix, template, model version and location rules are identical; A similar string cannot share any cache. A dropout or gradient map during training also undermines simple reuse conditions. Cache failure rules should be linked to the model and source version, and the successful creation of text after loading the old cache cannot be used as evidence of value equivalents.
A method of verification
Cache equivalent tests may include batch processing of two different length samples, in contrast to the results of separate operations. Check whether left-hand completion, validity length and each sequence position are independent if only at the time of the merge; If all requests are made jointly, check whether the cache is accidentally reused across tasks. For shared prefixes, the subsequent split should be managed using an independent supplemental state or a clear reference, and one request cannot be entered into the next key that is visible to another request.
Check understanding
Why is it theoretically consistent to add up to less of the old position?
The causal structure prevents the old position from relying on the new token and determines that the old key value remains unchanged in the prefix. The new queries still read the old expressions, leaving them without regenerating rather than ignoring history.
Eventually generating a different word, do you have to say there is a bug cache?
Not necessarily. Decimal error plus sampling may cause the path to be divided fork, and should be compared with logits tolerance in fixed generation conditions; The obvious difference in the first incremental location is more conducive to positioning the realization problem.
Sources and reconciliations
Definitions, methods and interfaces are available.
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.