Skip to content

feat: add runtime INT8 execution for Q8_0 linear layers - #2445

Merged
leejet merged 4 commits into
masterfrom
feat/runtime-q8-to-int8
Nov 27, 2026
Merged

leejet merged 4 commits into
masterfrom
feat/runtime-q8-to-int8

Conversation

@leejet

@leejet leejet commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • 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.

Related Issue / Discussion

N/A

Additional Information

Krea2 Turbo, CFG 1, CUDA, RTX 4090.

Q8 Q8→i8 i8
512×512 156.9 ms/it 106.5 ms/it 80.4 ms/it
1024×1024 590.6 ms/it 338.0 ms/it 315.5 ms/it

Checklist

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.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

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.
Implement Vulkan rowwise operations
src/core/vulkan/CMakeLists.txt, src/core/vulkan/int8.cpp, src/core/vulkan/shaders/*
Vulkan adds rowwise activation quantization and Q8_0 requantization. Group-1 quantization selects unrotated shader variants when support checks pass.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 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 "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.

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: 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.

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