Repository navigation
Conversation
025d7a5 to
b8d1f17
Compare
…lkan W4A8: weight nibbles index a 16-entry codebook with per-group F8_E4M3 relative scales folded with per-channel scales; the codebook is requantized to int8 in-CTA so the group dot is pure dp4a/SDot. W4A4: symmetric int4 weights x int4 activations, integer-pure accumulation with a byte-sum zero-point correction. Both use a 32-row CTA tile (weight decode shared by two 16-row tiles) on CUDA/HIP dp4a and Vulkan SDot; a gfx12 WMMA variant for w4a8 is included (compile-verified, runtime-gated). The ggml-hip build guards the -mcumode;-mwavefrontsize64 per-file tuning behind !CMAKE_HIP_ARCHITECTURES MATCHES gfx10: ROCm 10.0 clang segfaults (LLVM BranchRelaxation) compiling the w4a4 kernel wave64 for gfx1030; gfx10 targets keep the compiler default (wave32) until the compiler bug is fixed and the win is re-benched on RDNA2. Includes the convrot group-size-64 quantize support (templated CUDA kernels, GROUP_SIZE Vulkan shader variant) so w4 exports with 64-k rotation groups run on GPU; that content overlaps the h64 PR identically. The quantize-region guard flip and the prealloc_qconvrot buffer likewise overlap the int8 HIP / f32-input PRs (identical lines, merge clean in any order). Standalone note: plain int8 tensorwise stays CUDA-only (the INT8 HIP/BLAS and RDNA2 PRs are separate); packed-w4 runs on HIP.
b8d1f17 to
fa49872
Compare
|
Closing as superseded - and first of all, thank you @leejet for porting this upstream and for the credit in #2276. It means a lot to see the format land in stable-diffusion.cpp, and the new backend extension API is a much better home for this work than a ggml-side patch ever was. The follow-up performance work is honestly impressive as well: CUTLASS S8xS4 for W4A4/W4A8 on SM80+ (#2278) and the Vulkan cooperative-matrix kernels (#2280) go well beyond anything this branch attempted. For the record, the checkpoint contract carried over unchanged: packed I8 weights (low nibble first), 16-entry F32 codebook for asym_w4a8_int8, F32 per-channel scales, F8_E4M3 relative scales per 16 input features, mixed INT4/INT8 checkpoints, H64 and H256 groups, logical input width divisible by 64. Since the convrot operator implementations have moved out of the ggml submodule into sd.cpp's src/core/{cpu,cuda,vulkan} behind the ggml-ext registry, this ggml-side diff no longer applies, so there is no point keeping the PR open. Thanks again for absorbing this so thoughtfully. The branch stays on the fork as a historical record. (Comment drafted with LLM assistance, reviewed by noctrex.) |
What and why
ComfyUI exports packed int4 convrot checkpoints in two formats,
convrot_w4a4(int4 weights, int4-class activations) andasym_w4a8_int8(int4 codebook weights, int8 activations). This PR adds direct loading and execution of these checkpoints to the ggml backends: packed nibbles stream to the backend unconverted (roughly half a byte per weight parameter, no load-time reblock, no sidecar cache). The sd.cpp-side loader/graph integration follows as a separate PR once this lands.The activation pipeline is reused verbatim from the existing int8 tensorwise convrot support: same
GGML_OP_QUANTIZE_I8_CONVROTop, same packed scales-in-tail layout, same graph cache. Only the weight side of the MUL_MAT and the epilogue differ per kind:convrot_w4a4): signed nibbles sign-extend exactly to int8, so the dot product stays on an exact integer grid. The XOR-8 bias trick moves the sign correction into a per-row activation byte sum (integer-pure, bitwise-identical results).asym_w4a8_int8): nibbles index a 16-entry per-module codebook with per-channel scales and per-group F8_E4M3 relative scales. The codebook is requantized to int8 at block start (amax/127, same expression order on all backends), so the group dot is pure dp4a/SDot with one FMA per group.No new ggml op and no new ggml type:
MUL_MATwithsrc0= packed I8 weights and a kind selector in op_params slot 3 (slot 3 is zero-initialized, so 0 keeps int8 tensorwise chains unchanged).Backends
ggml-cuda/mmq-w4-convrot.cu. 32-row CTA tiles (weight decode shared by two 16-row tiles), 64-k stages, hoisted shared decode in [slot][output] layout, 4 outputs/thread, double-buffered stages, one barrier per stage. A gfx12 WMMA w4a8 variant is included, compile-verified only, runtime-gated.-mcumode/-mwavefrontsize64per-file tuning is guarded off for gfx10 targets (ROCm 10.0 clang segfaults in LLVM BranchRelaxation compiling the w4a4 kernel wave64 for gfx1030; gfx10 runs wave32 until the compiler bug is fixed).The
QUANTIZE_I8_CONVROTsupports_op/compute_forward gates stay enabled on HIP: packed int4 chains require the activation quantize op on the GPU, and disabling it splits the graph so the mul_mat contract check loses the op marker. Only the plain-int8 mul_mat BLAS route remains CUDA-only here (that is the INT8 HIP/BLAS PR's scope, #6/#9).Relationship to #6, #7, #8, #9
Deliberate identical-line overlaps so merges are clean in any order: the quantize-region guard flip and the prealloc_qconvrot buffer (#6/#8 territory), and the group-size-64 quantize content (templated CUDA kernels + GROUP_SIZE Vulkan shader variant, #7 territory). No int8 tensorwise behavior changes; the plain-int8 HIP/BLAS enablement stays with #6/#9.
Verification (results; test code stays local)
LLM Disclose: YES, used GLM-5.3 for the grunt work