Skip to content

Fix CUDA GatherBlockQuantized block indexing - #32665

Merged
Tianlei Wu (tianleiwu) merged 6 commits into
mainfrom
copilot/fix-gatherblockquantized-cuda-kernel
Nov 10, 2026
Merged

Tianlei Wu (tianleiwu) merged 6 commits into
mainfrom
copilot/fix-gatherblockquantized-cuda-kernel

Conversation

Copilot AI commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Compute block IDs per quantized-axis row:
    block_id = row * blocks_per_row + column / block_size;
  • Add CUDA regression coverage for a 4-bit, non-block-aligned quantized axis.

Motivation and Context

CUDA previously derived the scale and zero-point block from the flat data index. Non-block-aligned quantized axes therefore crossed row boundaries and silently produced incorrect results.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Packed zero-point indexing remains incorrect for rows with a non-pack-aligned block count, and the CUDA test can silently run on CPU.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes CUDA block indexing for non-aligned quantized-axis rows and adds regression coverage.

Changes:

  • Computes scale block IDs per quantized-axis row.
  • Passes the unpacked quantized-axis dimension to the CUDA kernel.
  • Adds a 4-bit CUDA regression test.
File summaries
File Description
gather_block_quantized.cc Supplies the logical quantized-axis dimension.
gather_block_quantized.cu Corrects row-aware block indexing.
gather_block_quantized.cuh Updates CUDA kernel parameters.
gather_block_quantized_op_test.cc Adds non-aligned-axis coverage.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tianleiwu Tianlei Wu (tianleiwu) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the per-row scale indexing, the independently padded packed-zero-point indexing, and the CUDA-specific test setup. The earlier packing and CPU-fallback concerns are addressed; no additional actionable findings.

An independent host arithmetic check matches all 72 values in the odd-block regression and verifies padded byte indices for 2/4/8-bit packing. git diff --check passes. These are not CUDA runtime tests, and this head currently has no reported CI checks, so please obtain current-head CUDA validation before merging. No approval submitted.

Copilot AI and others added 2 commits November 5, 2026 21:14
Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Copilot AI and others added 3 commits November 5, 2026 21:14
Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
The row-aware packed zero-point indexing correctly subtracts the second row's zero point instead of reading the previous row's padding nibble. Update the stale 4-bit expected output and restore the no-zero-point regression coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…antized CUDA tests

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tianleiwu
Tianlei Wu (tianleiwu) force-pushed the copilot/fix-gatherblockquantized-cuda-kernel branch from 6186209 to 42e540b Compare November 5, 2026 21:15
Incorporate the diagnosed SentencePiece pin and valid owned CUDA stream fixes. Preserve the passing axis-zero and odd-zero-point-block Gather regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted source review at d43a594486cdec442fc4f9a739ca5a6fd299b018.

Traced packed input expansion, gather offsets, dense scale indexing, and separately row-padded packed zero points against the schema and CPU implementation. Also checked CUDA-only test selection and disabled CPU fallback. The prior packed-zero-point and fallback concerns are resolved at this head.

No new actionable findings in this pass. Independent host-side indexing probes covered supported 2/4/8-bit examples and reproduced the new odd-block expected values. Reported head checks are 100 successful and one neutral. No CUDA compilation, GPU execution, or local ORT suite was performed.

@tianleiwu
Tianlei Wu (tianleiwu) merged commit 8c14885 into main Nov 10, 2026
104 of 105 checks passed
@tianleiwu
Tianlei Wu (tianleiwu) deleted the copilot/fix-gatherblockquantized-cuda-kernel branch November 10, 2026 00:25
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.

GatherBlockQuantized CUDA kernel uses the flat index for the block id, giving wrong results when the quantized axis is not a multiple of block_size

5 participants