ggml : fix quants nans when all the group weights are very close to zero #7313
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.
When the group abs max value is very close to zero but not zero, it may still result in a division by zero when computing the scale, which ends with a
nan
scale. To avoid this, we check the max value against an epsilon instead of zero. With the IQ quants, this could also result in aOops: found point %u not on grid
error.While doing this, I noticed that there was already a similar check with
1e-30
epsilon inmake_qx_quants
, however values this small can still result innan
, so I bumped it to1e-20
and extended it to all the cases that I could find. I used the commented code intest-backend-ops
to find these cases. It is possible that an even higher epsilon may be necessary.I don't expect this to result in lower precision in the quants since the epsilon is so small, but it may be worth checking.
Fixes #7311.