feat: lmcache-turbo-quant-serde — tqai KV-cache compression plugin for LMCache v1 - #13
Merged
Conversation
Adds integrations/lmcache/ — a standalone Python package that bridges tqai's
PolarQuantizer into LMCache's v1 distributed serde plugin system.
Key components:
- _wire.py: self-describing binary format (magic TQ01, bits/seed/shape/dtype embedded)
- _codec.py: standalone TurboQuantSerializer/Deserializer (to_bytes/from_bytes API)
- _v1_codec.py: TqaiSerializer/TqaiDeserializer conforming to
lmcache.v1.distributed.serde.base — reshapes [2,L,T,H×D]→[2,L,T,H,D]
before quantizing so PolarQuantizer sees head_dim as the last axis
- _register.py: register("tqai") via register_serde_factory; idempotent
- 47 tests across wire/codec/integration/e2e suites (all green)
- benchmarks/bench_serde.py: compression ratio, cosine quality, throughput table
Results (CPU, bfloat16, LLaMA-3 8B, 256 tokens):
4-bit: 25.8% of fp16 size, cosine=0.9954, ser=80ms, des=17ms
3-bit: 19.5% of fp16 size, cosine=0.9831 (faster after fix/bitstream-vectorize)
2-bit: 13.3% of fp16 size, cosine=0.9405, ser=48ms, des=16ms
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
integrations/lmcache/— a pip-installable package (lmcache-turbo-quant-serde) that bridges tqai'sPolarQuantizerinto LMCache's v1 distributed serde plugin system.pip install -e integrations/lmcache # or PyPI once publishedWhat's in the package
_wire.pyTQ01, bits/seed/shape/dtype embedded — no config needed to decompress_codec.pyTurboQuantSerializer/TurboQuantDeserializer(to_bytes/from_bytes) — usable without LMCache_v1_codec.pyTqaiSerializer/TqaiDeserializerconforming tolmcache.v1.distributed.serde.base_register.pyregister("tqai")viaregister_serde_factory; idempotent, non-conflicting with LMCache's ownturboquanttests/benchmarks/bench_serde.pyKey design decisions
[2, L, T, H×D];PolarQuantizerexpectshead_dimas the last axis, soTqaiSerializer.serializereshapes to[2, L, T, H, head_dim], stores that shape in the wire, andTqaiDeserializermerges back_v1_codec.pyfalls back to local ABCs when lmcache isn't installed, so the package imports cleanly without lmcache's full dep chain@lru_cacheon quantizer:PolarQuantizerholds ahead_dim×head_dimHaar rotation matrix; cache avoids rebuilding it across callsBenchmark results (CPU, bfloat16, LLaMA-3 8B)
Test plan
pytest integrations/lmcache/tests/— 47/47 passcreate_serde_processor(LMCache v1 async path)register()is idempotent; does not affect existing serdes (fp8)Depends on: PR #12 for full 3-bit performance
🤖 Generated with Claude Code