Lightning indexer

Index key cache

×

state · kept between calls

The indexer key of every position so far, in FP8 with one float32 scale per 128 features, kept between forward calls.

shape
kˉI\bar k^{I} k_I [B batch, T cached positions, 128 index d_h]

Prefill writes rows 0 … T − 1 and scores its queries against them. Each position holds 128 FP8 features and their scale, allocated for 16,384 positions per sequence slot (model.py 56).

Sources

In codeself.k_cache, self.k_scale_cache

Open pinned code ↗

Contextual evidence

The indexer keeps its own FP8 key cache with one float32 scale per 128 features; each call writes its keys and scores its queries against every cached position so far.

model.py 453–480 ↗ · deepseek-ai/DeepSeek-V3.2-Exp @ 87e509a2e5a1

Excerpt
        self.register_buffer("k_cache", torch.zeros(args.max_batch_size, args.max_seq_len, self.head_dim, dtype=torch.float8_e4m3fn), persistent=False)
        self.register_buffer("k_scale_cache", torch.zeros(args.max_batch_size, args.max_seq_len, self.head_dim // block_size, dtype=torch.float32), persistent=False)

… lines 455–475 omitted …

        self.k_cache[:bsz, start_pos:end_pos] = k_fp8
        self.k_scale_cache[:bsz, start_pos:end_pos] = k_scale
        weights = self.weights_proj(x.float()) * self.n_heads ** -0.5
        weights = weights.unsqueeze(-1) * q_scale * self.softmax_scale
        index_score = fp8_index(q_fp8.contiguous(), weights, self.k_cache[:bsz, :end_pos].contiguous(), self.k_scale_cache[:bsz, :end_pos].contiguous())

Reference defaults the configuration does not override: maximum sequence length, YaRN RoPE settings and the softmax scale correction.

model.py 56–86 ↗ · deepseek-ai/DeepSeek-V3.2-Exp @ 87e509a2e5a1

Excerpt
    max_seq_len: int = 4096 * 4

… lines 57–80 omitted …

    original_seq_len: int = 4096
    rope_theta: float = 10000.0
    rope_factor: float = 40
    beta_fast: int = 32
    beta_slow: int = 1
    mscale: float = 1.