Repository navigation
fix(torch): route eval decode through the range-safe decoder (#5606) - #5670
Merged
Merged
Conversation
The GPTQ_TORCH eval fast path multiplied packed codes by the stored FP16 scale, overflowing to inf before the caller could widen; a BF16 linear then returned NaN (0 * inf) and the embedding returned inf. Decode in decode_dtype_for_scales' dtype, widen the embedding row gather, and keep the reduction wide when the decoded weight does not fit the activation dtype. Gate the streaming and fused kernels on the same range check.
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.
Summary
TorchLinear.dequantize_weight()takes an eval-only fast path (_dequantize_weight_cached_248) that multiplied the packed codes by the stored FP16 scale before the caller could widen. A finite decoded weight of 122880 overflows FP16 toinf, so a BF16 linear returned NaN (0 * inf) andTorchQuantEmbeddingsreturnedinf.decode_dtype_for_scaleshelper, matching the base decoder.linear_wide_bias) only when the decoded weight does not fit the activation dtype, so the common finite path is unchanged.clear_weight_cache()so a traceddequantize_weightreads Python constants instead of running a host reduction.Tests
tests/test_gptq_torch_eval_decode_nan_5606.py: 3 passed (BF16/FP16 linear eval+train vs an FP64 oracle; embedding whole-table and row-gather routes).tests/test_torch.py tests/test_inference_fp16_overflow.py tests/test_torch_kernel_accuracy.py: 129 passed, 1 skipped.tests/test_torch_safety_gate.py tests/test_torch_weight_storage.py tests/test_torch_compile_fallback.py tests/test_q4_torch.py tests/test_torch_int8_tail_padding_4483.py tests/test_torch_aten_kernel_import_guard.py: 261 passed.tests/test_quantized_embeddings.py tests/test_embed_output_dtype_5394.py tests/test_requant_embed_endpoint_5116.py tests/kernels/test_torch_wide_bias_fallback.py tests/kernels/test_inference_numeric_range.py: 580 passed.uvx [email protected] check gptqmodel tests: All checks passed!git merge-tree --write-tree upstream/main HEAD: clean (exit 0).Fixes #5606.