KV RAM: Layer, Head, Length and Byte Unit

Key caches grow in layers, batches, active length, key-value headers and header.

Thematic shorts • IntroductionCollate in 1 diagram2 self-measured2 First-hand sources
Start Body
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.

bytes=B·L·T·2·HKV·dh·s

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.

Cache entry after length and batch extensionSets the other dimensions of the initial 64 MiB, doubles the length by 128 MiB, and doubles the volume by 256 MiB.Initial64 MiBLong context128 MiBAnd it's going to go in tandem256 MiB
Sets the other dimensions of the initial 64 MiB, doubles the length by 128 MiB, and doubles the volume by 256 MiB.

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.

  1. Hugging Face Transformers — How caching works
  2. 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.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.