cacheunit

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

internal/cacheunit/align.go Package cacheunit computes prefix padding so the Static Prefix ends on a DeepSeek cache-unit boundary. V4 reuses a stored prefix only up to its last COMPLETE compression block; the tail incomplete block is always recomputed (DeepSeek-V4 report §3.5.2). Padding the prefix to a unit multiple maximizes the reusable, fully-persisted portion. unit must be measured empirically with bench/cmd/cacheprobe before enabling padding; unit<=0 means "unknown -> none".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignPadding

func AlignPadding(prefixTokens, unit int) int

AlignPadding returns the token count to append to a prefix of prefixTokens so its length is a multiple of unit. Returns 0 when unit<=0 or already aligned.

func PadText

func PadText(prefixTokens, unit int, count func(string) int) string

PadText returns deterministic filler to append to a prefix of prefixTokens so the total token count is a multiple of unit, as measured by count. Identical for a given (prefixTokens, unit) -> the frozen prefix stays byte-stable. count MUST be the same tokenizer used to fingerprint the prefix. "" when none.

DEPRECATED: use PadTextConcat instead. PadText assumes count(prefix)+count(pad)==count(prefix+pad), which is false for real tokenizers that merge tokens at the concatenation boundary. It is retained only for existing test compatibility.

func PadTextConcat added in v0.4.1

func PadTextConcat(prefix string, unit int, count func(string) int) string

PadTextConcat returns deterministic filler to append to prefix so the combined token count (count(prefix + padding)) is a multiple of unit. Unlike PadText, it measures the concatenated result, so it is correct even when the tokenizer merges tokens at the concatenation boundary. Identical for a given (prefix, unit) -> the frozen prefix stays byte-stable. "" when unit <= 0 or the prefix is already aligned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL