mirror of
https://github.com/kvcache-ai/Mooncake.git
synced 2026-11-05 01:17:55 +00:00
[GH-ISSUE #4346] [RFC]: Opt-in client-side FP8 codec for complete Store KV chunks #1091
Labels
No labels
ascend
auto-closed
bug
bug
CI/Build
Common
documentation
enhancement
feature request
good first issue
help wanted
high priority
MetaX
nightly-failure
pull-request
PyTorch Backend
question
RFC
Roadmap
stale
Store
Tests
Transfer Engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/Mooncake#1091
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stmatengss on GitHub (Sep 27, 2026).
Original GitHub issue: https://github.com/kvcache-ai/Mooncake/issues/4346
Changes proposed
Motivation and scope
Applications that store FP16/BF16 KV chunks in Mooncake currently supply bytes in their chosen representation. An application opting into lossy storage needs an explicit contract for quantization, scales, reconstruction, format compatibility and failure behavior. Changing only a tensor dtype does not define that storage contract.
Propose an optional codec above the existing Store bytes API, with a CPU scaled-E4M3FN implementation as the first concrete algorithm. This reduces the stored representation size for sufficiently large chunks; it does not make attention execute in FP8, and it does not establish a throughput or model-quality improvement.
This RFC accompanies a draft implementation for review. The proposed v1 format should not be treated as a released compatibility promise until reviewed.
Design: three responsibilities
ScaledFp8Codecis the first implementation. The core has no Torch, Store RPC, CUDA or RDMA dependency.MooncakeDistributedStore, withput,get_intoandstorage_key. It handles tensor validation, representation keys and synchronous buffer lifetime.The master and Transfer Engine continue storing/transferring opaque bytes. Framework adapters still own model/token/layout/shard identity, K/V interpretation, page tables and component completeness.
TensorDescintentionally describes only contiguous CPU memory; it does not replace the existing reshard placement descriptors.Numeric and storage contract
max(abs(x))/448, or 1 for an all-zero group. Normalize in FP32, clamp and convert to E4M3FN with round-to-nearest-even.__mc_codec__/fp8-e4m3fn-v1-g<group_size>/<logical-key>. The logical key must already identify the model revision, token sequence, original dtype/layout and shard. The prefix isolates representations, not tenants or model identity.getis reported asStoreReadError, because that API does not distinguish absence from read failure.For
Nelements and rankR, the record is32 + 8*R + 4*ceil(N/group_size) + Nbytes, versus2*Nraw. At group size 128, the asymptotic ratio is about 1.94x before the fixed header and Store overhead. Small chunks or groups can expand. No adaptive raw fallback is proposed.Relation to LMCache and existing Mooncake work
LMCache's distributed serde separates synchronous serialization, asynchronous execution and the L2 storage wrapper. We borrow the transform/backend boundary; this first implementation keeps execution synchronous to avoid introducing thread pools, futures and cancellation semantics before they are needed. The inspected LMCache FP8 serde performs a direct FP8 cast. This proposal adds group scales and an independently validated record; it is not wire-compatible with LMCache serde.
Related work was checked before filing:
python/mooncakesource and private native extension, with staging for the existing legacy wheel builder.Searches of issues and open PRs for quantization, FP8, codec and KV compression found no existing proposal implementing this same contract.
Alternatives and deliberate exclusions
GPU/NPU kernels, batch/range reads, asynchronous execution, multi-component transactions, framework serving integration and new eviction/replication policies are outside the initial scope.
Validation and acceptance
The draft implements independent PyTorch reference comparisons, exhaustive finite FP16/BF16 input-bit-pattern coverage, a golden wire fixture, corruption/configuration mismatch checks and Store-error tests. C++ buffer tests cover unaligned memory, capacity, overlap, every truncated length and every single-bit corruption, including ASan/UBSan.
Before serving adoption: validate a real Linux Store TCP round trip, then relevant RDMA/GPU/framework paths; measure encode/decode time, temporary memory, persisted and transferred bytes, retrieval latency, and model quality on a fixed workload. The CPU implementation is a reference baseline, not a bandwidth-saturating codec.
Review questions: Is the flattened-group contract an appropriate first boundary? Should v1 framing/namespace be accepted as specified? Which workload and quality threshold should gate the first serving adapter?
Before submitting a new issue...
AI assistance: Codex assisted with source research, implementation, tests and this proposal. Human line-by-line review remains pending; the associated implementation is a draft.
@github-actions[bot] commented on GitHub (Sep 27, 2026):
Thanks for opening this issue, @stmatengss!
11641725A maintainer will triage this when possible. To help us respond faster, please include:
Useful links: Documentation · Contributing guide