mirror of
https://github.com/Comfy-Org/comfy-kitchen.git
synced 2026-11-04 23:37:42 +00:00
[PR #145] Add a float-GEMM fallback for int8_linear on devices without aten::_int_mm #173
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#173
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/145
Author: @vqt123
Created: 8/30/2026
Status: 🔄 Open
Base:
main← Head:int8-mps-fallback📝 Commits (3)
71b99e9Add a float-GEMM fallback for int8_linear on devices without aten::_int_mmc754eb5Chunk the fallback's float32 output scaling; keep vector inputs rank-preserving668cad7Cast the fallback weight one output-channel slice at a time📊 Changes
2 files changed (+295 additions, -0 deletions)
View changed files
📝
comfy_kitchen/backends/eager/quantization.py(+81 -0)➕
tests/test_int8_fallback.py(+214 -0)📄 Description
Problem
A fresh Comfy Desktop install on a Mac crashes out of the box on the recommended template. Install the Desktop app on Apple Silicon, open the featured MiniMax H3 text-to-video template, download its ~43 GB of models, press Run — and the run dies at sampling step 0:
That first-run experience is this bug. H3's diffusion model ships INT8 weights (
int8_convrot), and the eagerint8_lineardispatches totorch._int_mm, which has no MPS kernel (pytorch/pytorch#141287) — so every INT8 checkpoint fails on every Mac, with the flagship template as the most visible case (#92; Comfy-Org/ComfyUI#15967 and Comfy-Org/ComfyUI#15133 are the same crash reported against ComfyUI). The kernel is reached through two doors and both crash: theQuantizedTensordispatch handlers (F.linear(x, qt)/mm/addmm) and direct calls with a fused input activation (ComfyUI'slinear_input_act, H3's MLP down-projection).Fix
A float-GEMM fallback inside the eager
int8_linear, engaged only when the device lacksaten::_int_mm— CUDA/CPU are trusted, other device types are probed once, so a torch that grows an MPS kernel is picked up with no code change.Weights stay INT8 in memory; the only weight-sized temporary is the per-call cast to the activation dtype. Activations are not quantized on this path, so the result is slightly more accurate than the INT8 path, not less.
Verification
tests/test_int8_fallback.py(12 tests): both doors withtorch._int_mmmonkey-patched to assert the fallback never touches it; convrot × swiglu combinations; a float32 test pinning the rotate-activations math to dequantize-then-GEMM within 1e-3; the CPU native path asserted untouched; MPS-device tests (skipped off-Mac).Relationship to #107
@ikeyan's #107 takes the same fallback approach and has been stalled on the CLA since Aug 13; @seungjulee verified that branch on two Apple Silicon generations. This PR is an independent implementation (that diff was deliberately not read) so the CLA can be signed cleanly. Credit to @namikazi25 for the exact diagnosis in #92, and to @ikeyan and @seungjulee for getting there first — happy to defer to #107 if it revives. A native Metal INT8 GEMM remains the right long-term fix; this makes INT8 checkpoints work today.
Fixes #92.
🤖 Generated with Claude Code
https://claude.ai/code/session_0112gckHYByJuzZb1teQtpKk
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.