Skip to content

Main content

Artificial Intelligence: Kv Cache Token Byte Count Tool

Count exact dense key-plus-value cache bytes for supplied token/layer/KV-head geometry; excludes batching, alignment, metadata, quantization overhead and allocator fragmentation.

Loading tool…

Description

Return an exact unpadded key/value-cache byte count.

Inference budgets depend on the number of stored values, sequence lengths, routing assignments and the chosen accounting basis. Logical cache bytes and padded token counts differ from actual device allocation, latency and billed usage. Caller-supplied prices, cache fractions and capacity assumptions must match the intended system.

Return an exact unpadded key/value-cache byte count.

When to use this tool

Use Artificial Intelligence: Kv Cache Token Byte Count when reconciling the stated cache, padding, routing or price basis.

How to use the tool and how it works

  1. Enter tokens, layers, kvHeads, headDimension, bytesPerValue. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. Read result. Expand result to inspect the returned fields.

Return an exact unpadded key/value-cache byte count. Require whole tokens 0..1e9 and layers/kvHeads/headDimension/bytesPerValue 1..1e6; cacheBytes = 2*tokens*layers*heads*dimension*bytes, rendered as decimal text.1

Input fieldMeaning and unitsAccepted input
tokensTokensRequired. Safe integer. Calculation range: 0 through 1000000000, inclusive.
layersLayersRequired. Safe integer.
kvHeadsKv HeadsRequired. Safe integer.
headDimensionHead DimensionRequired. Safe integer.
bytesPerValueBytes Per ValueRequired. Safe integer.
Output fieldInterpretationReturned shape
resultObject containing the returned operation-specific members listed below.Required. Object.
result.cacheBytesExact decimal-integer text: 2*tokens*layers*kvHeads*headDimension*bytesPerValue; factor two counts keys and values.Calculated result member: string.
json
{
  "input": {
    "tokens": 10,
    "layers": 2,
    "kvHeads": 4,
    "headDimension": 8,
    "bytesPerValue": 2
  },
  "output": {
    "result": {
      "cacheBytes": "2560"
    }
  }
}

Limitations and assumptions

  • The factor two counts keys and values; this excludes batch multiplicity unless already represented, padding, metadata, scales and runtime allocation overhead.
  • Outputs are nested inside result. Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
  • Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.

Alternative or Complementary methods

Use actual model/runtime layouts, allocator measurements and current provider billing records for real memory, performance or cost planning.

References

  1. Calculation and input contract: artificial-intelligence/kv-cache-token-byte-count — tool.io

Similar or alternative tools