Skip to content

feat: support Q4 and Q5 weights in INT8 linear layers - #2452

Merged
leejet merged 1 commit into
masterfrom
feat/i8-requantize-q4-q5
Nov 28, 2026
Merged

leejet merged 1 commit into
masterfrom
feat/i8-requantize-q4-q5

Conversation

@leejet

@leejet leejet commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Extend --linear-type i8 to eligible Q4_0, Q4_1, Q5_0, and Q5_1 weights on CUDA, HIP, MUSA, and Vulkan.
  • Reuse the existing H256 rotation and INT8 GEMM. Layers that fail the eligibility checks fall back to their original execution path.

Related Issue / Discussion

N/A

Additional Information

N/A

Checklist

Summary by CodeRabbit

  • New Features
    • INT8 GEMM now supports Q4_0, Q4_1, Q5_0, Q5_1, and Q8_0 weights on CUDA, HIP, MUSA, and Vulkan.
    • Floating-point checkpoints can be quantized at load time using the --type option. Layers without supported INT8 requantization continue to use their original execution paths.
  • Documentation
    • Updated the runtime requantization guide with supported weight types and load-time quantization details.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

INT8 requantization now accepts Q4_0, Q4_1, Q5_0, Q5_1, and Q8_0 weights. Shared operation handling and CUDA and Vulkan implementations use the expanded type support. The guide documents the eligible types and the --type load-time quantization option.

Changes: INT8 requantization

Layer / File(s) Summary
Shared i8 contract and dispatch
src/core/ggml_extensions.h, src/core/ggml_extensions.cpp, src/core/ggml_extend.cpp, docs/guides/int8_convrot.md
The shared operation accepts supported Q4, Q5, and Q8 weight types. Linear dispatch uses the i8 operation, and the guide describes the expanded eligibility and load-time quantization option.
CUDA quantized decoding and execution
src/core/cuda/requantize.cu
The CUDA kernel decodes supported Q4, Q5, and Q8 blocks through a templated path. Execution dispatches by weight type and registers the i8 operation.
Vulkan shader and packing support
src/core/vulkan/CMakeLists.txt, src/core/vulkan/int8.cpp, src/core/vulkan/shaders/pack_i8_rows.comp
Vulkan adds Q4 and Q5 shader variants. Packing selects type-specific decoders for supported quantized inputs and registers the i8 operation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Linear as ggml_ext_linear
  participant Infer as requantize_i8_infer
  participant CUDA as CUDA backend
  participant Vulkan as Vulkan backend
  Linear->>Infer: validate supported weight type and operation inputs
  alt CUDA execution
    Linear->>CUDA: dispatch i8 requantization
  else Vulkan execution
    Linear->>Vulkan: dispatch i8 requantization
  end
Loading

Possibly related PRs

Merge Risk: Minimal · up to 50395

This change extends INT8 linear layers to Q4_0, Q4_1, Q5_0, Q5_1 and Q8_0 weights, and layers that fail the eligibility checks keep their original execution path. The CUDA and Vulkan weight decoders were checked against GGML's block formats and match, so no concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: adding Q4 and Q5 weight support to the INT8 linear layer path. The changeset extends eligibility beyond Q8_0 to Q4_0, Q4_1, Q5_0, and Q5_1 weights, adds matching Vulk…
Description check Passed The description follows the repository template. It has Summary, Related Issue / Discussion, Additional Information, and Checklist sections. The Summary explains what changed and why, including the re…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: adding Q4 and Q5 weight support to the INT8 linear layer path. The changeset extends eligibility beyond Q8_0 to Q4_0, Q4_1, Q5_0, and Q5_1 weights, adds matching Vulkan shaders, and renames the requantization op to requantize_i8. The title is concise and specific, and a teammate scanning history would understand the primary change.

Full details: Description check

Explanation

The description follows the repository template. It has Summary, Related Issue / Discussion, Additional Information, and Checklist sections. The Summary explains what changed and why, including the reuse of the H256 rotation and INT8 GEMM and the fallback for ineligible layers. Related Issue is marked N/A, and Additional Information is marked N/A, although no validation results are reported. The checklist is ticked. The description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5a695817-3c5b-4aa7-8291-c73fc07d1d87
Commits

Reviewing files that changed from the base of the PR and between 3771ef2 and 5039583.

Files selected for processing: 8

  • docs/guides/int8_convrot.md
  • src/core/cuda/requantize.cu
  • src/core/ggml_extend.cpp
  • src/core/ggml_extensions.cpp
  • src/core/ggml_extensions.h
  • src/core/vulkan/CMakeLists.txt
  • src/core/vulkan/int8.cpp
  • src/core/vulkan/shaders/pack_i8_rows.comp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@leejet
leejet merged commit d68f288 into master Nov 28, 2026
11 checks passed
@leejet
leejet deleted the feat/i8-requantize-q4-q5 branch November 28, 2026 14:00
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.

1 participant