# Repository Briefing: Comfy-Org/comfy-kitchen
> Source: https://repoforai.com/repo/Comfy-Org/comfy-kitchen (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/Comfy-Org/comfy-kitchen
- **Category**: LLMs & Inference (大模型与推理微调)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: A (85/100 · Maintenance 35/35 · Adoption 19/25 · Releases 11/20 · License 20/20)
- **Review Snapshot**: 2026-12-03
- **Deployment / Stack Signals**: Local AI, GPU
- **Momentum**: 265 ★ total (+0 24h / +2 7d) · 137 forks
- **When to Use**: Best for: ComfyUI or other PyTorch diffusion integrations that need a shared operator API and can validate quantized paths on their target GPUs or Ascend NPUs. Skip if: You need a complete model-serving stack, identical operator coverage across vendors, or already have a tested kernel for a single fixed target and do not need another dispatch layer.

## Overview
```text
### Architecture & Core Mechanics
Comfy Kitchen is an in-process Python/PyTorch operator library for diffusion inference, not a model server. Its registry checks device, dtype, shape, and compute capability before dispatching to a kernel. The documented default order is HIP → CUDA → Triton → eager; Ascend registers separately when `torch-npu` and a compatible device are present. If no backend accepts the call, dispatch raises `NoCapableBackendError` rather than trying kernels until one works.

Integration can happen through explicit operator calls or `QuantizedTensor`, a `torch.Tensor` subclass that intercepts supported PyTorch operations and dispatches quantized implementations where available. Eager is implemented in PyTorch, Triton kernels are JIT-compiled, and native CUDA and HIP extensions are built through `setup.py` using CMake and nanobind. The HIP backend compiles its own matmuls from `comfy_kitchen/backends/hip/` without linking hipBLAS or hipBLASLt.

### Key Capabilities & Differentiators
Operator coverage includes quantization, scaled matmul, AdaLN and RMS-AdaLN, RoPE and RMS-RoPE, 2D/3D neighborhood attention, and INT8 attention. Coverage varies by backend: INT8 attention has CUDA and HIP implementations but no eager entry; NVFP4 scaled matmul has CUDA and eager paths; MXFP8 dequantization and scaled matmul are eager-only. The listed Tensor Core layout floors are SM 8.9 for per-tensor E4M3 FP8 and SM 10.0 for 16-element NVFP4 and 32-element MXFP8 blocks, with E8M0 scales for MXFP8.

HIP uses WMMA GEMMs on RDNA3, RDNA3.5, and RDNA4. RDNA4 supports native FP8 WMMA; RDNA3/3.5 widen FP8 operands to BF16. RDNA2 runs non-WMMA operators such as RoPE, quantizers, and AWQ GEMV. HIP RoPE can act in place on strided Q/K views from packed QKV without first making contiguous copies. The optional Ascend backend uses `torch-npu` for selected INT8 operators and for interleaved and split-half RoPE.

### Trade-offs & Limitations
Compared with plain PyTorch eager or maintaining separate CUDA, HIP, and Triton calls, the registry reduces hardware-specific branching at the integration layer. It does not make quantized formats interchangeable or guarantee a fallback: unsupported shapes or dtypes can bypass the preferred kernel, and operators such as INT8 attention have no eager implementation. Test numerical agreement against an eager reference where one exists and log actual dispatch for the shapes used in production.

Low-precision storage is not proof of lower peak VRAM or faster inference. Ascend `convrot_w4a4_linear` preserves the caller's rotation and quantization precision but unpacks weights into INT8 for INT32 accumulation; that costs memory and time and retains eager's FP16 range limitations. In contrast, HIP can fold activation into the ConvRot quantizer load to avoid writing a separate activation result to GPU memory. Profile peak memory and end-to-end latency at representative model sizes and concurrency before standardizing on a backend.

### Hardware & Deployment Guide
Install `comfy-kitchen` into a local Python ≥3.10 and PyTorch ≥2.7 environment; no server or hosted inference endpoint is required. CUDA wheels target Linux x86_64 and Windows x64 and require CUDA runtime ≥13.0 and NVIDIA driver r580+. The pure Python wheel ships eager and Triton backends; that does not imply Triton will run on every host. CUDA source builds need Toolkit ≥12.8 and `CUDA_HOME`; native builds use nanobind ≥2.0, CMake ≥3.26, and Ninja.

On a ROCm-only host, `pip install .` selects HIP when `nvcc` is absent. Hosts with both toolchains default to CUDA-only unless `COMFY_KITCHEN_BUILD_HIP=1` is set. With build isolation, set `COMFY_HIP_ARCHS` to target a particular AMD GPU instead of building for the whole target list. Windows HIP builds also need the Windows SDK and the recommended VS 2022 v143 C++ toolset. The package manifest lists version `0.2.42`, but no GitHub release is listed, so release history does not establish when specific capabilities landed.
```

## Key Capabilities
```text
- Dispatch: Checks device, dtype, shape and compute capability before selecting a kernel; exposes backend overrides and dispatch logging.
- Quantized tensors: Wraps per-tensor E4M3 FP8, 16-element NVFP4 and 32-element MXFP8 layouts in a `torch.Tensor` subclass.
- Format coverage: Triton supports NVFP4 quantization and dequantization but not its scaled matmul; MXFP8 dequantization and scaled matmul are eager-only.
- AMD execution: Shared WMMA GEMM tiling uses architecture-specific MMA policies; RDNA4 handles FP8 natively, while RDNA3/3.5 widen to BF16.
- Fusion and strides: HIP RoPE can operate in place on strided packed-QKV views, and fused ConvRot INT8 quantization can consume activation without materializing it separately.
- Ascend integration: Optional `torch-npu` paths handle selected INT8 and rotary operators; W4A4 linear unpacks weights to INT8 for INT32 accumulation.
```

## Quick Start / Clone
```bash
pip install .
```
