You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: add runtime INT8 execution for Q8_0 linear layers - #2445
Add opt-in runtime requantization of eligible Q8_0 linear weights to INT8, with one scale per output channel. Reuse the existing INT8 GEMM and activation fusions while preserving the checkpoint format.
Add conversion support for CUDA, HIP, MUSA, and Vulkan through sd.cpp extensions. Put the CUDA-family conversion kernels and registration in requantize.cu so future formats can add their own kernels there. Unsupported layers and row-split models fall back to the standard Q8_0 path.
Add --linear-type auto|i8|raw and the corresponding linear_type setting for the C API and DGL loaders. Resolve module overrides when loading each model. --linear-type dit=i8 enables conversion for diffusion while text encoders use their default path. auto currently behaves like raw.
If this PR adds or changes model support, I have added or updated its usage guide and relevant model index/README entries following the model documentation requirements.
Summary by CodeRabbit
New Features
Added a linear INT8 execution option, configurable globally or by module through the CLI, C API, and DGL model loaders.
Added runtime conversion for eligible layers on supported GPU backends; unsupported layers continue using the existing execution path.
Added linear INT8 configuration support for upscalers and detectors.
Documentation
Expanded configuration and backend guides with accepted values, override behavior, support requirements, and notes on memory use and numerical differences.
No actionable comments were generated in the recent review.
Walkthrough
The change adds a linear_type setting for contexts and resource loaders, then propagates the selected mode to model runners. When enabled and supported, linear execution can quantize activations and requantize Q8_0 weights through CUDA or Vulkan paths.
Changes: Runtime INT8 linear execution
Layer / File(s)
Summary
Configure linear type and route loader settings src/config.h, src/core/ggml_extend_backend.*, src/api/*, examples/common/*, examples/cli/main.cpp, src/dgl/bindings/*, src/dgl/context.*, src/dgl/registry.h, docs/dgl-builtins.md, docs/dgl.md, docs/guides/*
The API and CLI accept linear_type values, and DGL routes module-specific selections to resource loaders. Documentation describes the options and runtime behavior.
Propagate linear INT8 mode to runners src/dgl/models/*, src/dgl/bindings/*, src/conditioning/conditioner.hpp, src/model/diffusion/hidream_o1.hpp, src/core/ggml_runner.*
DGL model parameters and runner contexts carry the linear INT8 flag. Conditioner visitors apply settings to their runners. The row-split registration path disables linear INT8.
Add requantization to linear execution src/core/ggml_extensions.*, src/core/ggml_extend.cpp
The extension registers Q8_0 requantization. ggml_ext_linear attempts INT8 multiplication under the specified mode, tensor type, and backend conditions. Otherwise, it uses the existing matrix multiplication path.
Implement CUDA backend operations src/core/cuda/*
CUDA adds Q8_0 weight requantization and supports selected group-1 operations without rotation. It also shares INT8 helpers and registers a split-SwiGLU optimizer.
sequenceDiagram
participant SDContextParams
participant DGLContext
participant model_loader
participant ModelRuntime
participant GGMLRunner
participant ggml_ext_linear
participant CUDA_VulkanBackend
SDContextParams->>DGLContext: Set linear_type
DGLContext->>model_loader: Add selected module mode to args
model_loader->>ModelRuntime: Set linear_i8 in model parameters
ModelRuntime->>GGMLRunner: Set linear INT8 mode
GGMLRunner->>ggml_ext_linear: Pass requantize_to_i8 in runner context
ggml_ext_linear->>CUDA_VulkanBackend: Quantize activations and requantize Q8_0 weights
Loading
Merge Risk: Minimal · up to 02686
This change adds an opt-in runtime path that requantizes eligible Q8_0 linear weights to INT8 on CUDA, HIP, MUSA and Vulkan. The default behavior is unchanged, and unsupported layers and row-split models keep using the standard Q8_0 path. No actionable merge-blocking risk was identified in the reviewed change.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "feat: add runtime INT8 execution for Q8_0 linear layers" matches the main change: opt-in runtime requantization of Q8_0 linear weights to INT8, exposed via --linear-type and the linear_type…
Description check
The description follows the template's sections: Summary, Related Issue / Discussion, Additional Information, and Checklist. The Summary explains what changed and why, including opt-in behavior, backe…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "feat: add runtime INT8 execution for Q8_0 linear layers" matches the main change: opt-in runtime requantization of Q8_0 linear weights to INT8, exposed via --linear-type and the linear_type setting. It is concise and uses a conventional prefix. It does not mention the CUDA/HIP/MUSA/Vulkan scope or the module-override option, which is acceptable because the title need not cover every detail.
Full details: Description check
Explanation
The description follows the template's sections: Summary, Related Issue / Discussion, Additional Information, and Checklist. The Summary explains what changed and why, including opt-in behavior, backend support, fallback paths, and the --linear-type option. The Related Issue section is filled with N/A. Additional Information gives a hardware setup and benchmark table. Both checklist items are checked.
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 1c68dc46-8743-4f9a-9cfe-4711d55d8288
Commits
Reviewing files that changed from the base of the PR and between a6447a6 and 026867e.
Files selected for processing: 11
docs/guides/int8_convrot.md
src/core/cuda/convrot_kernel.h
src/core/cuda/requantize.cu
src/core/ggml_extend.cpp
src/core/ggml_extensions.cpp
src/core/ggml_runner.cpp
src/core/ggml_runner.h
src/core/vulkan/CMakeLists.txt
src/core/vulkan/int8.cpp
src/core/vulkan/shaders/pack_i8_rows.comp
src/dgl/context.cpp
Files skipped from review as they are similar to previous changes: 3
src/core/ggml_runner.cpp
src/core/ggml_runner.h
src/dgl/context.cpp
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
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
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
requantize.cuso future formats can add their own kernels there. Unsupported layers and row-split models fall back to the standard Q8_0 path.--linear-type auto|i8|rawand the correspondinglinear_typesetting for the C API and DGL loaders. Resolve module overrides when loading each model.--linear-type dit=i8enables conversion for diffusion while text encoders use their default path.autocurrently behaves likeraw.Related Issue / Discussion
N/A
Additional Information
Krea2 Turbo, CFG 1, CUDA, RTX 4090.
Checklist
Summary by CodeRabbit