feat: add --kv-bits CLI args for server KV cache quantization#934
Open
lichengzhe wants to merge 1 commit intoml-explore:mainfrom
Open
feat: add --kv-bits CLI args for server KV cache quantization#934lichengzhe wants to merge 1 commit intoml-explore:mainfrom
lichengzhe wants to merge 1 commit intoml-explore:mainfrom
Conversation
Expose kv_bits, kv_group_size, and quantized_kv_start as server CLI arguments, passing them through to stream_generate. This allows users to trade off slight quality loss for significant memory savings when serving long-context requests. These parameters already exist in generate_step() but were not accessible from the server CLI.
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
Expose KV cache quantization parameters as server CLI arguments:
--kv-bits,--kv-group-size, and--quantized-kv-start.Motivation
generate_step()already supports KV cache quantization viakv_bits,kv_group_size, andquantized_kv_startparameters, and the CLImlx_lm.generateexposes them. However,mlx_lm.serverdoes not — users serving models via the OpenAI-compatible API have no way to enable KV cache quantization.This is particularly useful for long-context serving scenarios where KV cache memory is the bottleneck. For example, serving a 35B MoE model with 262K context on a 128GB Mac can easily exhaust memory with multiple concurrent long-context requests. KV cache quantization (4-bit or 8-bit) significantly reduces memory per cache entry.
Changes
--kv-bits(choices: 4, 8),--kv-group-size(default: 64),--quantized-kv-start(default: 0) to the server argument parserstream_generate()in_serve_singleUsage
Benchmark
Tested with Qwen3.5-35B-A3B (mxfp4) on Mac Mini M4 Pro 64GB:
Speed is comparable (slight overhead expected). The main benefit is memory savings for long-context workloads.