[Quantization] Add support for Comfy-Kitchen / Comfy-Quants - #14747
PrakshaaleJain wants to merge 16 commits into
Conversation
a99b253 to
e9bca91
Compare
|
Hi @DN6, please have a review for the PR. |
| **kwargs, | ||
| ): | ||
| self.quant_method = QuantizationMethod.COMFY_QUANT | ||
| self.quant_format = quant_format |
There was a problem hiding this comment.
We need to raise when an unsupported format is passed here.
| ): | ||
| module, tensor_name = get_module_from_name(model, param_name) | ||
|
|
||
| import comfy_kitchen.tensor as ck_tensor |
There was a problem hiding this comment.
Can run a is_comfy_kitchen_available check and import at top level.
|
|
||
| @require_torch | ||
| @pytest.mark.skipif(not is_comfy_kitchen_available(), reason="comfy-kitchen is not available") | ||
| class TestComfyQuantizer: |
There was a problem hiding this comment.
Let's setup testing in a similar manner to GGUF:
| if isinstance(param_value, ck_tensor.QuantizedTensor): | ||
| quantized_weight = param_value | ||
| else: | ||
| layout = layout_map.get(self.quant_format.lower()) |
There was a problem hiding this comment.
Isn't this is a constant for a given quant format? Can't we set it once on init?
|
|
||
| import comfy_kitchen.tensor as ck_tensor | ||
|
|
||
| layout_map = { |
There was a problem hiding this comment.
I think a few of these are not real layout objects. Please check.
| } | ||
|
|
||
| # Check if it's already a QuantizedTensor (e.g., if loaded directly from a custom loader) | ||
| if isinstance(param_value, ck_tensor.QuantizedTensor): |
There was a problem hiding this comment.
This wouldn't work since the state dict would contain just torch.Tensor objects. We would need to construct the QuantizedTensor manually from the state dict.
What does this PR do?
This PR adds support for the Comfy Quant quantization toolkit by integrating its inference engine, Comfy-Kitchen, directly into Diffusers library.
Key additions:
ComfyQuantConfigandComfyQuantizerto handle wrapping of tensors.create_quantized_paramand wraps them viaQuantizedTensor.from_floatto dispatch to Comfy-Kitchen's optimized GPU kernels.fp8,int8,mxfp8,nvfp4,int4_svd,int4_awq).tests/quantization/comfy_quant/.Fixes #14705
Before submitting
self-reviewskill on the diff?AI Agent Self-Review Notes
Agent: Antigravity (Google DeepMind)
Review Focus: Diffusers Quantization Standards & Guidelines
ComfyQuantizerrelies onis_comfy_kitchen_available(). If the backend is not installed, Diffusers will safely fall back to standard behavior or fail gracefully ifComfyQuantConfigis passed explicitly without the toolkit.make style && make fix-copies.utils/check_dummies.pysuccessfully generateddummy_comfy_kitchen_objects.pyand correctly registered the imports in `diffusers/__inittests/quantization/comfy_quant/test_comfy_quant.py. Tests cover both valid format wrapping (FP8mapping toTensorCoreFP8Layout) and error handling for unsupported formats. Tests ran locally and passed with 100% success.