Custom quantization rules with regular expressions #244
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.
For DeepSeekV3/R1 it is handy to be able to define custom rules for picking quantization types for the various tensors. Well, this is useful in general, but particularly useful for very large models where one wants to squeeze the last bit of quantized model quality for the smallest possible model size.
This PR adds this ability. Using
one can pass custom rules to the quantization function. The rules are comma separated (but one can also use multiple
--custom-q
arguments). The custom rules are processed in order and the first match is taken. So, for instance, if I usethe second rule matches the
ffn_down
experts, but because a match was found in the first rule,IQ4_NL
will get used forblk.*.ffn_down_exps.weight
, andIQ1_S_R4
will get used for theffn_up
andffn_gate
experts tensors.To summarize how the quantization type is determined:
--attn-q-type, --attn-k-type, --attn-v-type, --attn-qkv-type, --attn-output-type, --ffn-gate-type, --ffn-down-type, --ffn-up-type
, and the tensor is one of those, the type specified that way gets used (for now)