Diffusers documentation

Comfy Quantization

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Comfy Quantization

Comfy Quants exports prequantized checkpoints with per-layer quantization metadata. Diffusers reads each layer’s format and uses Comfy-Kitchen for inference. A checkpoint can mix quantization formats and floating-point layers.

Install the optional dependencies:

pip install "comfy-kitchen>=0.2.41" accelerate

Load a checkpoint

Pass ComfyQuantizationConfig to from_single_file. Set compute_dtype to BF16 or FP16; the checkpoint determines the quantization format of each layer.

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),
)
pipe = ZImagePipeline.from_pretrained(
    "Tongyi-MAI/Z-Image-Turbo", transformer=transformer, dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()
image = pipe(
    "A small orange cat sitting on a mossy stone wall in a mountain village",
    height=1024,
    width=1024,
    num_inference_steps=8,
    guidance_scale=0.0,
    generator=torch.Generator("cpu").manual_seed(0),
).images[0]

Validated formats

The quantizer reads each layer’s uint8 JSON comfy_quant marker and bundles the packed weight with its scales and other sidecar tensors before checkpoint conversion.

Marker formatStored weightsAssociated tensors
float8_e4m3fn, float8_e5m2FP8Weight scale, optional activation scale
int8_tensorwiseINT8Scalar or row scales, optional ConvRot metadata
mxfp8FP8E8M0 block scales
convrot_w4a4Packed INT4Row scales and rotation metadata
asym_w4a8_int8, w6a8_int8Packed INT4 or INT6Group and channel scales, optional codebook and correction

Checkpoint converters retain their usual weight splitting and concatenation. The quantized tensor keeps row and block scales aligned without dequantizing the stored weights. Concatenation requires compatible layouts and shared metadata. Input-feature splitting is unsupported.

One ComfyLinear dispatches through the weight’s Kitchen layout. Layers marked full_precision_matrix_mult use dequantized matrix multiplication. Unquantized layers use the compute dtype, and model FP32 exclusions receive dequantized FP32 weights.

Kitchen selects an available execution backend. Hardware requirements differ by format; loading a checkpoint does not guarantee native quantized acceleration on the current device.

INT8 ConvRot

ConvRot rotates weights offline and activations at inference time to spread activation outliers. Native int8_tensorwise checkpoints retain INT8 weights and FP32 scales. Rotated layers include convrot and convrot_groupsize metadata. Both rotated and unrotated INT8 layers are supported.

Update on GitHub