Skip to content

fix(BACKEND-TENSTORRENT-KEEPQUANT): correct V-row offset and NaN comparison in keep-quant test - #3189

Merged
localai-org-maint-bot merged 1 commit into
mainfrom
row/BACKEND-TENSTORRENT-KEEPQUANT
Sep 14, 2026
Merged

localai-org-maint-bot merged 1 commit into
mainfrom
row/BACKEND-TENSTORRENT-KEEPQUANT

Conversation

@localai-org-maint-bot

Copy link
Copy Markdown
Collaborator

The test helper ReorderVRowsRef in tests/vllm/test_gguf_keep_quant.cpp had two bugs that prevented the packed V-row reorder test case from passing:

1. Wrong offset formula (heap-buffer-overflow)

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 (3+5)*1024 = 8192 floats past a 15*512 = 7680-float buffer, causing a heap-buffer-overflow that crashed build-test-cpu, build-test-cpu-arm64-full, 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.

2. NaN comparison failure

The test compared two float vectors with operator==, which fails on bitwise-identical NaN values (NaN != NaN under IEEE 754). The dequantized data contains NaN values from valid f16 scales. Replaced with memcmp so bitwise-identical buffers compare equal.

Red before: test_gguf_keep_quant crashes with SIGABRT (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.cpp

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:GLM5.2 [maki]

…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]
@localai-org-maint-bot
localai-org-maint-bot merged commit 0bd1881 into main Sep 14, 2026
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReorderVRowsRef test helper has wrong offset formula — heap-buffer-overflow in test_gguf_keep_quant

2 participants