fix(BACKEND-TENSTORRENT-KEEPQUANT): correct V-row offset and NaN comparison in keep-quant test - #3189
Merged
Conversation
…arison in keep-quant test The test helper ReorderVRowsRef used (row_off + g) * cs as the byte offset, where cs = head_rows * cols. This treats row_off and the V-unit index g as multiples of the head-group stride, but row_off is in individual rows and g counts V-units (each spanning head_rows rows). With the test params (K=512, row_off=3, num_k=2, rpk=3, head_rows=2) the buggy offset reached 8192 floats past a 7680-float buffer, causing a heap-buffer-overflow that crashed build-test-cpu, build-test-cpu-arm64, and sanitize-cpu. The correct formula is (row_off + g * head_rows) * cols, matching the production ReorderVRows at qwen3_5_gguf_weights.cpp:395 which uses base + t * head_stride where base = buf.data() + row_off * cols and head_stride = head_rows * cols. The test also compared two float vectors with operator==, which fails on bitwise-identical NaN values (NaN != NaN under IEEE 754). Replaced with memcmp so bitwise-identical buffers compare equal. Closes #3188 FOLLOWING_AGENTS_PROTOCOL Following-Agents-Protocol: true AI-Assisted: true Assisted-by: AGENT:GLM5.2 [maki]
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.
The test helper
ReorderVRowsRefintests/vllm/test_gguf_keep_quant.cpphad two bugs that prevented thepacked V-row reordertest case from passing:1. Wrong offset formula (heap-buffer-overflow)
ReorderVRowsRefused(row_off + g) * csas the byte offset, wherecs = head_rows * cols. This treatsrow_offand the V-unit indexgas multiples of the head-group stride, butrow_offis in individual rows andgcounts V-units (each spanninghead_rowsrows). With the test params (K=512, row_off=3, num_k=2, rpk=3, head_rows=2) the buggy offset reached(3+5)*1024 = 8192floats past a15*512 = 7680-float buffer, causing a heap-buffer-overflow that crashedbuild-test-cpu,build-test-cpu-arm64-full, andsanitize-cpu.The correct formula is
(row_off + g * head_rows) * cols, matching the productionReorderVRowsatqwen3_5_gguf_weights.cpp:395which usesbase + t * head_stridewherebase = buf.data() + row_off * colsandhead_stride = head_rows * cols.2. NaN comparison failure
The test compared two float vectors with
operator==, which fails on bitwise-identical NaN values (NaN != NaNunder IEEE 754). The dequantized data contains NaN values from valid f16 scales. Replaced withmemcmpso bitwise-identical buffers compare equal.Red before:
test_gguf_keep_quantcrashes withSIGABRT(malloc(): corrupted top size) at line 3214.Green after: all 61 test cases pass (12127 assertions).
Closes #3188
Test path:
tests/vllm/test_gguf_keep_quant.cppFOLLOWING_AGENTS_PROTOCOL
Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:GLM5.2 [maki]