Skip to content

Add Comfy Kitchen INT8 attention backend - #15448

Merged
sayakpaul merged 5 commits into
huggingface:mainfrom
asaiyume:feature/comfy-kitchen-attention
Dec 4, 2026
Merged

sayakpaul merged 5 commits into
huggingface:mainfrom
asaiyume:feature/comfy-kitchen-attention

Conversation

@asaiyume

@asaiyume asaiyume commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds comfy_kitchen_int8 as an attention backend, using int8_attention from Comfy Kitchen. It follows the Comfy quantization support added in #15209. This gives around 8-15% performance boost compared to native baseline.

Some Comfy-Org checkpoints already ask for it. In qwen_image_2.1_turbo_int8_convrot, 31 of 32 blocks carry {"attention": "comfy_kitchen_int8"}. Reading that config automatically is left for a follow-up.

  • Supports attention masks, grouped-query attention, cross-attention, and head dimensions up to 256.
  • Inference only. Causal attention and dropout raise an error.

Usage

pip install "comfy-kitchen>=0.2.41" accelerate
import torch
from diffusers import ComfyQuantizationConfig, ZImagePipeline, ZImageTransformer2DModel

transformer = ZImageTransformer2DModel.from_single_file(
    "https://huggingface.co/Comfy-Org/Z-Image-Turbo/blob/main/split_files/diffusion_models/z_image_turbo_int8_convrot.safetensors",
    config="Tongyi-MAI/Z-Image-Turbo",
    subfolder="transformer",
    quantization_config=ComfyQuantizationConfig(compute_dtype=torch.bfloat16),
)
transformer.set_attention_backend("comfy_kitchen_int8")

pipe = ZImagePipeline.from_pretrained(
    "Tongyi-MAI/Z-Image-Turbo", transformer=transformer, dtype=torch.bfloat16
).to("cuda")

image = pipe(
    "A small orange cat sitting on a mossy stone wall in a mountain village",
    height=2048,
    width=2048,
    num_inference_steps=8,
    guidance_scale=0.0,
    generator=torch.Generator("cpu").manual_seed(0),
).images[0]

Results

Z-Image-Turbo INT8 ConvRot, 2048x2048, 8 steps, torch 2.10.0, comfy-kitchen 0.2.41.

Backend Full pipeline Peak memory
native (left) 16.74s 23.03 GiB
comfy_kitchen_int8 (right) 15.30s (-8.6%) 23.03 GiB
zit2048_side_by_side_small

MiniMax-H3 fl2va INT8 ConvRot, 704x704, 124 frames, 50 steps, torch 2.10.0, comfy-kitchen 0.2.41.

Backend Full pipeline Denoising Per step Peak memory
native (left) 326.0s 287.6s 5.87s 35.2 GiB
comfy_kitchen_int8 (right) 280.0s (-14.1%) 241.5s (-16.0%) 4.93s (-16.0%) 35.2 GiB
h3_side_by_side.mp4

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or GitHub Discussions?
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

@DN6 @sayakpaul

@github-actions github-actions Bot added documentation Improvements or additions to documentation models tests utils size/M PR with diff < 200 LOC labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Hi @asaiyume, thanks for the PR! It does not appear to link an issue it fixes.

  • If this PR addresses an existing issue, please add a closing keyword (e.g. Fixes #1234) to the PR description so the issue is linked.
  • If you are the author of the model/pipeline this PR relates to, or part of the team we work with on it, tick the Are you the author (or part of the team we work with) of the model/pipeline this PR relates to? box in the PR description (if you removed the template, paste that line back, checked). This reminder then no longer applies.
  • Otherwise there is nothing you need to do: a maintainer will look at the PR and add the no-issue-needed label to silence this reminder if it should stay open without an issue.

See the contribution guide for more details.

Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice.

Once the PR links an existing issue, the author box is ticked, or the no-issue-needed label is added, you can ignore this message — it stays here as a comment, but it no longer applies.

@sayakpaul sayakpaul added no-issue-needed for PRs that do not require link to an issue performance Anything related to performance improvements, profiling and benchmarking labels Dec 3, 2026
@sayakpaul

Copy link
Copy Markdown
Member

Thanks for your PR @asaiyume. Do you think it's possible to package this as a kernel on the Hub and do it similar to flash_2_hub?

Comment thread tests/models/test_attention_dispatch.py Resolved

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The changes look good to me. But is it tied to the quant backend of Comfy? For example, can I load a regular checkpoint into a model and set its attention backend to this one?

@asaiyume

asaiyume commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Yes, it does work with normal models (official BF16s) and get the performance gains, similar to the sage backend. I will take a look at the implementation for hub kernels.

@asaiyume

asaiyume commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @sayakpaul! Is the procedure for packaging kernels opening a issue then a PR on the huggingface/kernels-community?

I think we should leave supporting of _hub variants in another PR, once the kernel gets published on the Hub. The current implementation works the same way how sage backend works with pip install sageattention, since comfy-kitchen serves prebuilt wheels.

@sayakpaul

Copy link
Copy Markdown
Member

Is the procedure for packaging kernels opening a issue then a PR on the huggingface/kernels-community?

Yes, we can do so.

I think we should leave supporting of _hub variants in another PR, once the kernel gets published on the Hub. The current implementation works the same way how sage backend works with pip install sageattention, since comfy-kitchen serves prebuilt wheels.

Okay no problem for me. But we should then do it right after this PR because we plan on depcrecating non Hub attention backends very soon.

@asaiyume

asaiyume commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Okay no problem for me. But we should then do it right after this PR because we plan on depcrecating non Hub attention backends very soon.

Will do! Should be able to complete it over the weekend.

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the tests using HF Jobs and they pass: https://huggingface.co/jobs/sayakpaul/6b12aa0adccc34da944d455e. Let's do the kernels implement ASAP if possible. Let me know your Hub username so that I can enable kernel publishing access.

@asaiyume

asaiyume commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

On HF, same as GH asaiyume.

@sayakpaul

Copy link
Copy Markdown
Member

Thanks. You should have kernel publishing access on the Hub now.

@sayakpaul
sayakpaul merged commit ebda33e into huggingface:main Dec 4, 2026
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation models no-issue-needed for PRs that do not require link to an issue performance Anything related to performance improvements, profiling and benchmarking size/M PR with diff < 200 LOC tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants