GeezerVison is showing github.com — perf: accelerate packed INT4 CUDA inference with CUTLASS by leejet · Pull Request #2278 · leejet/stable-diffusion.cpp
Conversation
leejet
commented
Nov 5, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- Accelerate eligible W4A4 operations with CUTLASS mixed-input S8 × S4 GEMM, reusing the INT8 tile selection and scale epilogue without expanding the full weight tensor.
- Accelerate W4A8 with CUTLASS integer MMA and FP32 scale restoration for each 16-element group.
- Preserve existing fallback paths and HIP/MUSA implementations. Add
GGML_CUDA_W4_FORCE_DP4A=1 for comparison.
Related Issue / Discussion
N/A
Additional Information
Hardware: NVIDIA GeForce RTX 4090 24 GB, NVIDIA driver 596.36.
Build: Windows, CUDA 13.4, nvcc 13.4.92, Release, CUTLASS enabled.
DiT files:
| Model |
Format |
DiT file |
| Krea2 Turbo |
W4A4 |
krea2_turbo_int4_tensorwise_mixed.safetensors |
| Krea2 Turbo |
INT8 |
krea2_turbo_int8_convrot.safetensors |
| P-H3 Image |
W4A8 |
p-h3-image_w4a8.safetensors |
| P-H3 Image |
INT8 |
p-h3-image_int8_convrot.safetensors |
Sampling throughput in it/s; higher is better. Before/after uses the same INT4 weights:
| Model |
Resolution |
sd.cpp before |
sd.cpp after |
Improvement |
| Krea2 Turbo W4A4 |
512×512 |
2.438 |
10.167 |
+316.98% |
| P-H3 Image W4A8 |
2912×2912 |
0.124 |
0.342 |
+176.25% |
Percentages are calculated before rounding the reported throughput values.
INT8 reference using the same inference settings:
| Model |
Optimized INT4 |
INT8 |
| Krea2 Turbo |
10.167 |
11.269 |
| P-H3 Image |
0.342 |
0.289 |
Configuration and measurement:
- CUDA backend, batch 1, CFG 1, Euler, seed 42, CPU offloading enabled.
- Automatic flash attention selected CUDA MMA.
- Eight steps per run. Exclude steps 1–2 from the throughput calculation; all eight steps execute.
- Krea2 uses the discrete scheduler,
Qwen3-VL-4B-Instruct-Q4_K_M.gguf, and wan_2.1_vae.safetensors.
- P-H3 uses
--sigmas p-h3-image --rng cpu, qwen3vl_4b_bf16.safetensors, p-h3-image_text_connector.safetensors, and p-h3-image_vae_bf16.safetensors.
Checklist
Summary by CodeRabbit
- Performance
- Improved CUDA execution for packed INT4 operations on supported NVIDIA GPUs, with optimized paths for eligible workloads.
- Other shapes and configurations continue to use existing execution paths.
- Documentation
- Clarified which CUDA execution paths are used for packed INT4 operations and documented an option for comparing performance.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 5, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

Walkthrough
-
The CUDA W4 backend now supports CUTLASS execution paths for eligible operations. Packed-W4 I8 GEMM handles W4A4 cases, and a new MMA kernel handles W4A8. Other cases retain existing paths.
Changes: CUDA packed W4 execution
| Layer / File(s) |
Summary |
Packed-W4 I8 GEMM support src/core/cuda/i8_gemm.h, src/core/cuda/i8_gemm.cu |
The I8 GEMM API accepts an optional packed_w4 flag. Packed-W4 plans select the corresponding weight type, alignment, multiplication mode, and tile configuration. |
W4A8 MMA kernel and build support src/core/cuda/w4_mma.h, src/core/cuda/CMakeLists.txt |
The W4A8 kernel uses CUTLASS int8 MMA on SM80+ and a scalar fallback below SM80. CMake applies CUTLASS compile settings to the generated W4 CUDA source. |
W4 plan and runtime dispatch src/core/cuda/w4.cu, docs/int8_convrot.md |
The W4 plan selects eligible MMA execution, prepares optional W4A4 GEMM workspace, and retains fallback paths. The documentation describes the CUDA paths and comparison variable. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant W4Backend
participant I8GEMM
participant W4MMKernel
W4Backend->>I8GEMM: Prepare eligible W4A4 without bias
W4Backend->>W4Backend: Store execution plan and workspace
alt Prepared GEMM is available
W4Backend->>I8GEMM: Execute W4A4 GEMM
else MMA selected without prepared GEMM
W4Backend->>W4MMKernel: Launch W4 MMA kernel
end
Loading
Possibly related PRs
Merge Risk: Minimal · up to a85ad
-
No concrete issue remains that should block merging after normal build and numerical checks.
Pre-merge checks: 4 · 1
-
Failed checks: 1 warning
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
 |
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… |
Write docstrings for the functions missing them to satisfy the coverage threshold. |
Passed checks: 4 passed
-
| Check name |
Status |
Explanation |
| Title check |
 |
The title clearly and concisely describes the main change: accelerating packed INT4 CUDA inference with CUTLASS. |
| Description check |
 |
The description includes all required sections, explains the implementation and purpose, records related discussion status, provides detailed hardware and benchmark information, and confirms the contr… |
| 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: Description check
-
Explanation
The description includes all required sections, explains the implementation and purpose, records related discussion status, provides detailed hardware and benchmark information, and confirms the contribution checklist.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 4 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
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
-
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 6, 2026
danielhanchen
added a commit
to unslothai/stable-diffusion.cpp
that referenced
this pull request
Nov 9, 2026
… chunking, RelayVSR, SDXL ControlNet Union) (#54)
* feat: support packed INT4 convrot models (leejet#2276)
Co-authored-by: noctrex <[email protected]>
* perf: accelerate packed INT4 CUDA inference with CUTLASS (leejet#2278)
* perf(vulkan): accelerate packed INT4 with cooperative matrices (leejet#2280)
* feat: ControlNet Union support for SDXL (leejet#2284)
* fix: chunk MiniMax-H3 QKV projections within backend buffer limits (leejet#2286)
* feat: add RelayVSR video upscaling with CUDA window attention (leejet#2285)
* MiniMax-H3: log once when the QKV projection is chunked
* Vulkan: only fall back to the CPU for tensors Vulkan cannot bind, keep the in-place RMSNorm multiply
Upstream leejet#2286 moves a node to the CPU when it or an input is larger than the buffer type's max size. On Vulkan that is the 1 GiB suballocation block, not a device limit, so Flux attention at 1024x1024 ran on the CPU (leejet#2291). The threshold is now at least 4 GiB - 1 on Vulkan, the largest range a storage buffer binding can address. RMSNorm goes back to the in-place multiply: ggml patch 0013 already runs in-place ops on the backend that owns the output.
* Vulkan: let supports_op decide tensor size, keep the allocation gate for other backends
The runner gate from upstream leejet#2286 compares a node and its inputs with the
buffer type's max size. On Vulkan that is the suballocation block, and the
4 GiB floor added for leejet#2291 still overrode ggml-vulkan's own check, which
accepts tensors up to max_buffer_size and past maxStorageBufferRange with
64-bit indexing. Vulkan nodes now go by supports_op alone, as before leejet#2286;
the QKV chunking and the gate for other backends stay.
* Packed INT4: read convrot_groupsize / group_size from params as well as the top level
---------
Co-authored-by: leejet <[email protected]>
Co-authored-by: noctrex <[email protected]>
Co-authored-by: Daniele <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|