Repository navigation
Granite nvfp4 underflow fix - #1836
Conversation
This protection only seems to be strictly necessary for NVFP4. We've verified that the existing int4 quant does produce coherent results, but it's likely that this will also help there. Branch: GraniteNVFP4UnderflowFix AI-usage: full (Claude + Sonnet 5) Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
These are always protected in Ollama and turn out to be critical here too for these models. Branch: GraniteNVFP4UnderflowFix AI-usage: full (Claude + Sonnet 5) Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Branch: GraniteNVFP4UnderflowFix AI-usage: none Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
zcbenz
left a comment
There was a problem hiding this comment.
This problem is unique to nvfp4 because the MLX's nvfp4 quantization currently miss global scale, which would be fixe by #1844. I think this change would work for a specific problem for now but we would have to revert it once getting global scale support, so I think we are not going to accept this and will wait for #1844.
|
@zcbenz Thanks for the review! I tried out the fix on #1844, but it doesn't seem to help for the dense models where we're seeing this issue ( gh pr checkout 1844
uv run mlx_lm convert --model ~/models/ibm-granite/granite-4.2-3b/ --mlx-path ./granite-4.2-3b-mlx-nvfp4-1844 --quantize --q-mode nvfp4
# [INFO] Loading
# [INFO] Using dtype: bfloat16
# [INFO] Quantizing
# [INFO] Quantized model with 4.501 bits per weight.
uv run mlx_lm generate --model ./granite-4.2-3b-mlx-nvfp4-1844/ --prompt "Tell me a short story"
# ==========
# -fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore
# ==========
# Prompt: 20 tokens, 251.845 tokens-per-sec
# Generation: 100 tokens, 147.237 tokens-per-sec
# Peak memory: 2.177 GBWhen I try on our internal MoE that was also experiencing this issue, I get a stack trace: uv run mlx_lm convert --model ~/models/ibm-research/sample-moe --mlx-path ./sample-moe-mlx-nvfp4-1844 --quantize --q-mode nvfp4
# [INFO] Loading
# [INFO] Using dtype: bfloat16
# [INFO] Quantizing
# [INFO] Quantized model with 4.501 bits per weight.
uv run mlx_lm generate --model ./sample-moe-mlx-nvfp4-1844 --prompt "Tell me a short story" |
|
NOTE: I did do |
|
You are facing this issue because mlx release does not include this fix yet. You should pip intall mlx from source. |
|
@nastya236 @zcbenz Following the suggestion above, I did install |
|
@gabe-l-hart hmm thanks for the update! of course, thanks for looking into this. please reopen the PR! |
|
@nastya236 It looks like I don't have permission to re-open the PR. Is that something you can do as a |
|
Thanks for testing the global scale PR! |
Description
This PR fixes underflows in the recent IBM Granite 4.2 models (https://huggingface.co/collections/ibm-granite/granite-42-language-models) and existing GraniteMoE models (eg https://huggingface.co/ibm-granite/granite-3.1-3b-a800m-instruct) when quantizing to
nvfp4.Details
I found these issues while adding MLX support to Ollama (ollama/ollama#17972) and verified that they also existed in native
mlx-lm. The fix is to protect several key tensors from quantization below 8-bit.Open Questions
It looks like there's no way to differentiate between target quants when applying the precision guards. In testing, the
int4quants work smoothly without these guards, so it appears to be unique tonvfp4, but it seems to be better to protect here for all sub-8-bit quants. Does this sound like the right choice?Testing
GraniteForCausalLM (dense)
Baseline NVFP4
$ uv run mlx_lm generate --model ./granite-4.2-3b-mlx-nvfp4-baseline/ --prompt "Tell me a short story" ========== -fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore-fore ========== Prompt: 20 tokens, 254.589 tokens-per-sec Generation: 100 tokens, 146.458 tokens-per-sec Peak memory: 2.177 GBBranch NVFP4
GraniteMoeForCausalLM (MoE)
NOTE: The existing 3.1 MoE models don't exhibit the underflow errors in baseline, but a private internal model does:
Baseline NVFP4
Branch NVFP4
AI Usage
git-ai-stats