feat: fused Metal q4 inference for MLX 4-bit models#82
Open
cjchanh wants to merge 1 commit intoevilsocket:mainfrom
Open
feat: fused Metal q4 inference for MLX 4-bit models#82cjchanh wants to merge 1 commit intoevilsocket:mainfrom
cjchanh wants to merge 1 commit intoevilsocket:mainfrom
Conversation
Author
|
Additional benchmark context for this PR. Benchmark resultsM5 Max (128 GB), single-device
M5 Max + iPad Air M3, distributed (0.5B)
M1 Air + iPad Air M3, distributed (0.5B)
Tested on Apple Silicon ( This is the key distinction for the patch: it does not just optimize an existing path. It enables Cake to serve MLX 4-bit checkpoints that upstream |
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.
What
This patch enables Cake to serve MLX 4-bit quantized models that upstream main cannot load. On M5 Max, Qwen2.5-7B-Instruct-4bit loaded at 9.5 GiB and generated 10 tokens at 56.71 tok/s in a bounded API run.
How
q4_matvec_f16andq4_matmul_tiled_f16MSL kernels that read packed 4-bit weights and dequantize on-the-fly during matmulQuantizedLinearlayer type that stores packed U32 weights + F16 scales/biases on Metal without expansionMetalMlxBackendVarBuilder that auto-detects MLX 4-bit format and keeps weights packedLinearWeight(Dense/Quantized)Tested
cargo test -p cake-core --features metalcargo clippy -p cake-core -p cake-cli --features metalFiles
cake-core/src/backends/metal/ops.msl— MSL kernelscake-core/src/backends/metal/mod.rs— kernel dispatch + CustomOpcake-core/src/backends/mod.rs— trait methodcake-core/src/utils/quantized_linear.rs— QuantizedWeight + LinearWeightcake-core/src/utils/mlx_quant.rs— MLX detectioncake-core/src/utils/gptq.rs— MetalMlxBackendcake-core/src/utils/mod.rs— auto-detection wiringcake-core/src/models/common/mlp.rs— quantized MLPcake-core/src/models/common/attention.rs— quantized attentioncake-core/tests/unit_tests/test_quantization.rs— q4 validation tests