KV RAM: Layer, Head, Length and Byte Unit
Key caches grow in layers, batches, active length, key-value headers and header.
Learning objectives and first steps2 objectives . 1 first fix
Try to do it after reading
- Explains the mechanisms and premises of the KV memory book: layer, head, length and byte units
- Positioning the mechanism ' s fault limits with fixed examples
Suggested first
- Size shape & RAM unit
Issues and mechanisms
Key caches grow in layers, batches, active length, key-value headers and header. It can be calculated to determine whether the service supports long context and co-development, but it cannot predict apparent needs by using only the size of model parameters. Query head may be different from key head and cache accuracy may be different from weight accuracy; Each dimension should come from a real configuration.
The plain cache takes two loads, saving keys and values. The bytes approximate the number of two-folder layers, batches, cache length, key-value headers, head peacekeeping and each element byte. Page segments, block alignment, metadata, pre-allocation and quantitative scalings may also increase or change occupancy. A distinction should be made between the total presence of actual used, operational and equipment reports and their non-mixing as an indicator.
A concrete example
Synthesis sets 16 layers, lot 2, length 2, 248, four key headers, first dimension 64, two bytes per element. The serial number gets 6,710,100,864 bytes, or 64 MiB. The length is doubled to 128 MiB and the volume is doubled to 256 MiB. This is only a cache, and model weights, activations and subworking areas need to be added.
Borders and checks
Decimal MB, unlike binary MiB, should be reported in units. The use of slide windows may be only partial, but some of the realizations are pre-allocated for long periods of time; Sharing prefixes may also be reused by reference rather than copied. A true memory layout must be checked and a peak value for a service cannot be directly rolled out from the algorithm concept.
A method of verification
The RAM can be divided into three columns of theoretical mass elements, and of actual usage of the distributor and retention of equipment. When theoretical values are small and peaking, pre-allocation, page break and temporary slings are checked and cannot be attributed immediately to the loading of parameters. Each dimension in a synthetic book should read from the configuration or stencing shape and indicate whether the batch contains a beam search candidate. Otherwise, multi-candidature caches for the same request could be missed, leading to overly optimistic capacity planning.
Check understanding
The weight of the weight is four bits. Must the cache also be four bits?
Not necessarily. The weight and KV are different objects with formatting, scaling and computing configurations. You need to see the realization separately. You cannot use weight accuracy to replace the cache book.
Double the length and volume. What happens to the plain cache?
The other dimensions are four times the same, as the two are multiplied. Services may also change schedule owing to insufficient memory, and end-to-end delays may not necessarily change in a simple proportion at this time.
Sources and reconciliations
Definitions, methods and interfaces are available.
- Hugging Face Transformers — How caching works
- GQA — Training Generalized Multi-Query Transformer Models
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.