Skip to main content

Comfy Kitchen

Fast kernel library for Diffusion inference with multiple compute backends.

Backend Capabilities Matrix

Function eager cuda triton
quantize_per_tensor_fp8
dequantize_per_tensor_fp8
quantize_nvfp4
dequantize_nvfp4
scaled_mm_nvfp4
quantize_mxfp8
dequantize_mxfp8
scaled_mm_mxfp8
apply_rope
apply_rope1

Quantized Tensors

The library provides QuantizedTensor, a torch.Tensor subclass that transparently intercepts PyTorch operations and dispatches them to optimized quantized kernels when available.

Layout Format HW Requirement Description
TensorCoreFP8Layout FP8 E4M3 SM ≥ 8.9 (Ada) Per-tensor scaling, 1:1 element mapping
TensorCoreNVFP4Layout NVFP4 E2M1 SM ≥ 10.0 (Blackwell) Block quantization with 16-element blocks
TensorCoreMXFP8Layout MXFP8 E4M3 SM ≥ 10.0 (Blackwell) Block quantization with 32-element blocks, E8M0 scales
from comfy_kitchen.tensor import QuantizedTensor, TensorCoreFP8Layout, TensorCoreNVFP4Layout

# Quantize a tensor
x = torch.randn(128, 256, device="cuda", dtype=torch.bfloat16)
qt = QuantizedTensor.from_float(x, TensorCoreFP8Layout)

# Operations dispatch to optimized kernels automatically
output = torch.nn.functional.linear(qt, weight_qt)

# Dequantize back to float
dq = qt.dequantize()

Installation

From PyPI

# Install default (Linux/Windows/MacOS)
pip install comfy-kitchen

# Install with CUBLAS for NVFP4 (+Blackwell)
pip install comfy-kitchen[cublas]

Package Variants

  • CUDA wheels: Linux x86_64 and Windows x64
  • Pure Python wheel: Any platform, eager and triton backends only

Wheels are built for Python 3.10, 3.11, and 3.12+ (using Stable ABI for 3.12+).

From Source

# Standard installation with CUDA support
pip install .

# Development installation
pip install -e ".[dev]"

# For faster rebuilds during development (skip build isolation)
pip install -e . --no-build-isolation -v

Build Options

These options require using setup.py directly (not pip install):

Option Command Description Default
--no-cuda python setup.py bdist_wheel --no-cuda Build CPU-only wheel (py3-none-any) Enabled (build with CUDA)
--cuda-archs=... python setup.py build_ext --cuda-archs="80;89" CUDA architectures to build for 75-virtual;80;89;90a;100f;120f (Linux), 75-virtual;80;89;120f (Windows)
--debug-build python setup.py build_ext --debug-build Build in debug mode with symbols Disabled (Release)
--lineinfo python setup.py build_ext --lineinfo Enable NVCC line info for profiling Disabled
# Build CPU-only wheel (pure Python, no CUDA required)
python setup.py bdist_wheel --no-cuda

# Build with custom CUDA architectures
python setup.py build_ext --cuda-archs="80;89" bdist_wheel

# Debug build with line info for profiling
python setup.py build_ext --debug-build --lineinfo bdist_wheel

Requirements

  • Python: ≥3.10
  • PyTorch: ≥2.5.0
  • CUDA Runtime (for CUDA wheels): ≥13.0
    • Pre-built wheels require NVIDIA Driver r580+
    • Building from source requires CUDA Toolkit ≥12.8 and CUDA_HOME environment variable
  • nanobind: ≥2.0.0 (for building from source)
  • CMake: ≥3.18 (for building from source)

Quick Start

import comfy_kitchen as ck
import torch

# Automatic backend selection (triton -> cuda -> eager)
x = torch.randn(100, 100, device="cuda")
scale = torch.tensor([1.0], device="cuda")
result = ck.quantize_per_tensor_fp8(x, scale)

# Check which backends are available
print(ck.list_backends())

# Force a specific backend
result = ck.quantize_per_tensor_fp8(x, scale, backend="eager")

# Temporarily use a different backend
with ck.use_backend("triton"):
    result = ck.quantize_per_tensor_fp8(x, scale)

Backend System

The library supports multiple backends:

  • eager: Pure PyTorch implementation
  • cuda: Custom CUDA C kernels (CUDA only)
  • triton: Triton JIT-compiled kernels

Automatic Backend Selection

When you call a function, the registry selects the best backend by checking constraints in priority order (cudatritoneager):

# Backend is selected automatically based on input constraints
result = ck.quantize_per_tensor_fp8(x, scale)

# On CPU tensors → falls back to eager (only backend supporting CPU)
# On CUDA tensors → uses cuda or triton (higher priority)

Constraint System

Each backend declares constraints for its functions:

Constraint Description
Device Which device types are supported
Dtype Allowed input/output dtypes per parameter
Shape Shape requirements (e.g., 2D tensors, dimensions divisible by 16)
Compute Capability Minimum GPU architecture (e.g., SM 8.0 for FP8, SM 10.0 for NVFP4)

The registry validates inputs against these constraints before calling the backend—no try/except fallback patterns. If no backend can handle the inputs, a NoCapableBackendError is raised with details.

# Debug logging to see backend selection
import logging
logging.getLogger("comfy_kitchen.dispatch").setLevel(logging.DEBUG)

Testing

Run the test suite with pytest:

# Run all tests
pytest

# Run specific test file
pytest tests/test_backends.py

# Run with verbose output
pytest -v

# Run specific test
pytest tests/test_backends.py::TestBackendSystem::test_list_backends

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

comfy_kitchen-0.2.21-py3-none-any.whl (119.8 kB view details)

Uploaded Python 3

comfy_kitchen-0.2.21-cp312-abi3-win_amd64.whl (15.9 MB view details)

Uploaded CPython 3.12+Windows x86-64

comfy_kitchen-0.2.21-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (23.5 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

comfy_kitchen-0.2.21-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (23.4 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

comfy_kitchen-0.2.21-cp311-cp311-win_amd64.whl (15.9 MB view details)

Uploaded CPython 3.11Windows x86-64

comfy_kitchen-0.2.21-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (23.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

comfy_kitchen-0.2.21-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (23.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

comfy_kitchen-0.2.21-cp310-cp310-win_amd64.whl (15.9 MB view details)

Uploaded CPython 3.10Windows x86-64

comfy_kitchen-0.2.21-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (23.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

comfy_kitchen-0.2.21-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (23.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file comfy_kitchen-0.2.21-py3-none-any.whl.

File metadata

  • Download URL: comfy_kitchen-0.2.21-py3-none-any.whl
  • Upload date:
  • Size: 119.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for comfy_kitchen-0.2.21-py3-none-any.whl
Algorithm Hash digest
SHA256 949be770a47ffa88513c6ae1e42a2144c39bac308d2507141cdf763d32c81572
MD5 569310c0a953fff81cbff0ceb0b1d7a6
BLAKE2b-256 7942aeac4bc3795555d1f573356111820faf432cde1542ab0e64bcd4bbd95540

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b7dcfe4635a17db887f54ab31f1725aaf438efc65fcba7983547137068db8197
MD5 a89f8bd1869637575c1ccdfc34afcf12
BLAKE2b-256 e6a47ef94d38cad0ebbd69a3b2939d71d243417674da8fb197187c7eb85d4672

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp312-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 31117a0b39343b50f2ad6bb51b7ecdd73a4a23fa78a5c782a688a59b23f7eb73
MD5 0d158d5f4491e27b60ae941a682c5814
BLAKE2b-256 16de4898b2fc5ae1295185044920842c2e95aa1a908d468a000bdeac00aed9e6

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp312-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b63beea31d232bd639f69edcc9fd66fa0e0925546e51e8249cb3759ee70f736e
MD5 323ef97086e85eae8fa92b1938ccdb23
BLAKE2b-256 74f2a5722be74fc7ec8445e43adc9c983c05bad73da6f1438506ef869adc0d54

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c814c778ad39c6d3460b718593c3dea6056298deaa81605a12883f2d3b65f081
MD5 404247310e53e3d69dbc85d58979edfa
BLAKE2b-256 c7f887a81a2d1d6f097ea007ec23af7acc87e52f0c1efb47d0d86e4ecaf9505f

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e1d7332ab8df7dbb9cefd0ce539949984e043e4c46ace851947c17bb7c5a33c9
MD5 e55970dea5788ab84b23c2f04f3ba570
BLAKE2b-256 99d61482afeaa529084448419e12182c9df1d458956048eab508275d5ef23286

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e6f16bfcaced99c3577054f780657a48aed0fb3f61c1f06831621f5078b992ae
MD5 5d7b926ba080dd02305108d656400900
BLAKE2b-256 1c9452f224c126c539cd26a8038d66d3ea0ffa5ccad254e87bdeb605e32f19ac

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0d4ae02b78d1291c65b58b7aabc5a2fdcf16c43a8b5c2726a05a13f379d3c2c6
MD5 212a5700e69a3c448e7837d2bd47f14a
BLAKE2b-256 8ec0387cae5e86c42d2be75df6f9c327444d26c3f29a8be9b82aece1f9b4b175

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b383c38375c0080205211a30e816769f90de90fb399ac61c894f97a35ee5a83
MD5 84a7aa4d70970141b7763173239a20fa
BLAKE2b-256 c1047331c81a707653ccf2376b0d12354e006f1d2aae6b7a9bb9e0e88ca997fa

See more details on using hashes here.

File details

Details for the file comfy_kitchen-0.2.21-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for comfy_kitchen-0.2.21-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5210e98584cf72f9701df281aa4d4fecbaf5612cf33a9dba4cf21512ecad0ecf
MD5 430aae425f678ada17c6426f33d94951
BLAKE2b-256 2f9eb811d98c4dd583ea836f8f86f80d089fdf4fa192ece08b13ca5832c950f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page