mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #201] [MERGED] [Perf][Ascend] Avoid activation pack/unpack in ConvRot W4A4 #218
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-kitchen#218
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-kitchen/pull/201
Author: @Big2Wheel
Created: 9/25/2026
Status: ✅ Merged
Merged: 10/2/2026
Merged by: @comfyanonymous
Base:
main← Head:perf/ascend-w4a4-unpacked-activations📝 Commits (4)
84f29d0fix(ascend): sort backend imports to unblock CIa40a0dbperf(ascend): avoid W4A4 activation pack and unpacke72ec8bFix import order.59ed9c0Fix📊 Changes
6 files changed (+227 additions, -10 deletions)
View changed files
📝
README.md(+3 -2)📝
comfy_kitchen/backends/ascend/__init__.py(+9 -6)📝
comfy_kitchen/backends/eager/convrot_w4a4.py(+11 -2)➕
samples/benchmark_ascend_w4a4_unpacked.py(+92 -0)📝
tests/test_ascend_backend.py(+15 -0)➕
tests/test_convrot_unpacked_quantization.py(+97 -0)📄 Description
Summary
Avoid packing signed INT4 activation codes into nibbles only to immediately unpack them before Ascend ConvRot W4A4 integer matmul. Keep the same codes in INT8 storage instead.
Relationship to #198 and #199
npu_quant_matmul; the baseline is not eager/CPU GEMM or the earlier withdrawn lower-precision implementation.maindirectly, not #199. To avoid the existing main-branch Ruff I001 failure, its first commit cherry-picks only #199's import-order fix (28b7f850cbc4edc0e3e0605e026252c5bd3a53c1, with provenance). No other #199 changes are included. The second commit is the performance change. Prefer merging #199 first; this shared import-only prerequisite can then be dropped when rebasing. The runtime optimization has no dependency on #199's test/documentation changes.Correctness and tests
rtol=0, atol=0.ruff check .andgit diff --checkpass.NPU regression command (run in the source checkout):
Operator performance and profiling
Environment: one Ascend 910B3 (physical device 4), torch 2.10.0+cpu, torch-npu 2.10.0.post4, CANN 9.1.0, Python 3.12.13, vLLM-Omni v0.28.0 container. Runs were isolated from other test jobs on this card.
FP32 full Linear timings include rotation, activation preparation, weight unpacking, matmul, and postprocessing. Random full-shape inputs; 10 warmups and 30 measurements per arm, alternating order, with NPU synchronization at timing boundaries. Real captured inputs were checked separately for exact correctness.
Quantization/preparation alone (10 warmups, 50 measurements per arm) was 224.920 → 0.957 ms for [4135,6144], and 549.891 → 3.189 ms for [4135,16384].
Separate profiling confirms removal of activation
aten::__lshift__/aten::bitwise_or; weight unpacking and onenpu::npu_quant_matmulremain. A scheduled full-shape diagnostic profile for [4135,6144] measured the pack region at 218.555 ms, dominated by theaclnnLeftShifts_LeftShift_LeftShiftevent at 210.135 ms. These single-profile numbers explain the hotspot; they are not the steady-state benchmark. Device events alone are not evidence of host CPU fallback or a specific accelerator core type.Reproduce the full Linear comparison in a standalone process:
The script checks exact output equality and prints raw samples and medians. Its legacy arm restores only activation pack/unpack through a temporary private-helper replacement.
Real Krea workflow A/B
45b3121ccff27bc6020985738ad999b96b4b9a02.krea2_turbo_int4_mixed.safetensors; text encoder:qwen3vl_4b_bf16.safetensors; VAE:qwen_image_vae.safetensors.--cache-none --disable-pinned-memory,OMP_NUM_THREADS=4; same service, same instrumentation in both arms, only the activation quantization helper changes.Workflow mean ± sample standard deviation: 330.193 ± 0.572 s → 36.021 ± 0.104 s. Median latency reduction: 89.09% (9.17× speedup) in this specific environment/workflow. This is not a universal model/hardware speedup claim; only three formal runs per arm were measured.
Warmups: 330.760 / 35.997 s (excluded from statistics). Additional seed: 330.784 / 35.982 s (also excluded). All 10 requests succeeded; decoded output images were pixel-identical across arms for each seed. No CPU-fallback warnings or execution errors were observed in the workflow log; that is not an exhaustive per-operator device audit.
Peak allocated memory during formal runs: baseline 11247.688 MiB, new 11247.346 MiB. No significant peak-memory reduction is claimed. Z-Image/Wan results from #199 are separate validation of #198 and are not presented as measurements of this change.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.