Add TurboQuant KV cache compression (arXiv 2504.19874)#405
Closed
joelnishanth wants to merge 1 commit into
Closed
Conversation
Adds opt-in TurboQuant KV cache compression for long-context LLM inference. 3-bit PolarQuant + 1-bit QJL residual correction for keys. New files in Source/Cmlx/turbo-quant/: - turbo_quant.h: Header-only C++ Lloyd-Max codebook, WHT, QJL - turbo_quant_ops.cpp: Encode/decode in mlx::core::fast - turbo_quant_bridge.cpp: C bridge for Swift FFI - turbo_quant_decl.h: Forward declarations Modified: - Package.swift: turbo-quant header search path - include/mlx/c/fast.h: C bridge declarations - MLXFast.swift: Swift bindings Reference: Zandieh et al., arXiv 2504.19874 (2025) Benchmarks: https://github.com/joelnishanth/mlx-swift-turboquant Co-authored-by: Cursor <cursoragent@cursor.com>
5 tasks
Collaborator
|
You shouldn't do it this way -- the modification is to the |
Collaborator
|
FWIW I think so far people have been adding turboquant in the lm layer. Here is a comment on adding it to mlx: |
Author
|
ah makes sense , i do have some benchmarking numbers but i dont want duplicate efforts if there has been significant progress made |
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 opt-in TurboQuant KV cache compression for long-context LLM inference on Apple Silicon. TurboQuant (Zandieh et al., arXiv 2504.19874) applies 3-bit PolarQuant + 1-bit QJL residual correction to compress the KV cache, achieving ~5x memory reduction for cached tokens with minimal quality impact.
Source/Cmlx/turbo-quant/(outside mlx/mlx-c submodules)turbo_quant.h: Header-only Lloyd-Max codebook, Walsh-Hadamard rotation, QJL projectionturbo_quant_ops.cpp: Encode/decode inmlx::core::fastnamespaceturbo_quant_bridge.cpp: C bridge for Swift FFIMLXFast.swift:turboQuantEncode(keys:values:bits:)— compress K/V tensorsturboDecodeK(packed:)/turboDecodeV(packed:)— decompressAll TurboQuant code lives in a dedicated
turbo-quant/directory outside the mlx and mlx-c submodules, keeping the dependency boundary clean.Expected Performance
Based on the TurboQuant paper (Table 1):
Companion PRs
Test plan
References
— Joel Nishanth · offlyn.AI
Made with Cursor