llama-quantize: Add MoE chunk queue for faster multi-threaded quant creation - #27770
Closed
bartowski1182 wants to merge 1 commit into
Closed
llama-quantize: Add MoE chunk queue for faster multi-threaded quant creation#27770bartowski1182 wants to merge 1 commit into
bartowski1182 wants to merge 1 commit into
Conversation
bartowski1182
marked this pull request as ready for review
August 26, 2026 22:54
bartowski1182
marked this pull request as draft
August 28, 2026 11:49
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.
Overview
This changes how experts are chunked and queued into the llama-quantize process
This does NOT speed up running models, so don't get excited.. But MoE model creation speed does go up by a good margin with identical sha256sum
In ideal scenarios, we can see a 5x speedup in creation time for the particularly tricky tensor types when using 192 threads on Qwen3.6-35B-A3B:
At 48 threads on 24 cores the numbers are more modest, somewhere more like 1.5-2x increase
CPU usage goes from ~60-80% on each provided core to 100%
Additional information
The main change is that we no longer spin up a single thread per-expert, now it handles the whole 3D tensor in one threaded pass
this_nrow = min(nrows - local_row, nrows_per_chunk)guarantees that chunks get truncated at the end of its expert so we don't span expert boundaries (which would have different imatrix data)ggml_quantize_chunknow receivesstart = 0for every call here, instead of usingfirst_row * n_per_row. Since we need the per-expert base pointers anyways, we just increment them all ahead of time.It also uses better logic for deciding the threads to use per expert, if the matrices were small we'd end up with a low thread count, now it's based on the size of the whole tensor.
Checked the sha256sum of every file with and without this PR and they're identical, also checked on a dense model for sanity and it was the same.
Also compared this PR vs master with a single thread (since it's a different path) and also same sha256sum on https://huggingface.co/hf-internal-testing/Mixtral-tiny (can't afford the days it would take to quantize a 35B on a single thread..), time is same because this is a multi-threaded improvement.
Requirements