Skip to content

Support convrot int4 models. - #14859

Merged
comfyanonymous merged 1 commit into
masterfrom
convrot_int4
Jul 9, 2026
Merged

Support convrot int4 models.#14859
comfyanonymous merged 1 commit into
masterfrom
convrot_int4

Conversation

@comfyanonymous

Copy link
Copy Markdown
Member

linear_dtype in comfy_quant metadata can be used to set if the int4 op does the matrix multiplication in int8 or int4, the default is int4 on GPUs that support it with fallback to int8 for GPUs that don't.

Here's a test model file, this model will not be very high quality because 99% of the linears are quantized to int4 (with int4 matrix mult on supported gpus) but it is good for testing: https://huggingface.co/comfyanonymous/int4_tests/blob/main/split_files/diffusion_models/krea2_turbo_convrot_int4_fast.safetensors

A proper quant would have a mix of: pure convrot int4, convrot int4 with int8 matrix mult, convrot int8 and 16 bit precision linears to get the best speed/size/quality.

linear_dtype in comfy_quant metadata can be used to set if the int4 op does
the matrix multiplication in int8 or int4, the default is int4 on GPUs that
support it with fallback to int8 for GPUs that don't.
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedpypi/​comfy-kitchen@​0.2.16 ⏵ 0.2.17100 +110010010080

View full report

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 65c2534f-e64d-4f48-b783-8483b92841ed

📥 Commits

Reviewing files that changed from the base of the PR and between 1ea7243 and 8d82d3a.

📒 Files selected for processing (4)
  • comfy/ops.py
  • comfy/quant_ops.py
  • requirements.txt
  • tests-unit/comfy_quant/test_mixed_precision.py
📜 Recent review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: Run Pylint
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (windows-2022)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (windows-latest)
🧰 Additional context used
📓 Path-based instructions (3)
**

⚙️ CodeRabbit configuration file

**: ## Engineering Style

  • Keep changes small and direct. Most fixes should touch the narrowest code path
    that explains the bug, performance issue, dtype issue, model-format issue, or
    user-facing behavior.
  • Change the least amount of files possible. A change that touches many files is
    more likely to be a bad change than a good one unless the broader scope is
    directly required.
  • Prefer practical fixes over broad architecture work. Add abstractions only
    when they remove real repeated logic or match an existing ComfyUI pattern.
  • Prefer fewer dependencies. Do not add new dependencies to ComfyUI unless they
    are absolutely necessary.
  • Delete obsolete code aggressively when newer infrastructure makes it useless.
    Remove dead fallbacks, migration paths, unused options, debug prints, and
    compatibility branches that are no longer needed. Do not leave dead branches,
    unreachable code, or functions that are never called. If code is not
    necessary for the current behavior, remove it.
  • Revert or disable problematic behavior quickly when it breaks users. It is
    better to remove a broken feature path than keep a complicated partial fix.
  • Preserve existing APIs, node names, model-loading behavior, file layout, and
    workflow compatibility unless the change is explicitly about replacing them.
  • Code must look hand-written for this repository. Changes that read like
    generic AI-generated code will be rejected automatically: unnecessary helper
    layers, vague names, boilerplate comments, defensive branches without a real
    failure mode, broad rewrites, or code that ignores the local style.

Architecture Boundaries

  • Keep each layer focused on the concepts it owns. Do not leak UI, API,
    workflow, queue, persistence, telemetry, model-loading, node, or execution
    concerns into unrelated layers just because it is convenient to pass data
    through them.
  • Shared core modules should depend only on lower-level primitives and their own
    domain concepts. Highe...

Files:

  • requirements.txt
  • comfy/ops.py
  • tests-unit/comfy_quant/test_mixed_precision.py
  • comfy/quant_ops.py

⚙️ CodeRabbit configuration file

**: IMPORTANT: Only comment on issues directly introduced by this PR's code changes.
Treat AGENTS.md as mandatory repository policy, not optional style guidance.
Flag PR changes that violate AGENTS.md even when the code is otherwise functional.
In particular, enforce architecture boundaries, dtype/device/memory rules,
interface contracts, import style, no unnecessary try/except blocks, no inline
imports, no outbound internet paths in core ComfyUI, and narrow scoped fixes.
Prefer direct findings over suggestions when a rule is violated. Only ignore
AGENTS.md when it clearly conflicts with a newer explicit maintainer instruction
in the PR.
Do NOT flag pre-existing issues in code that was merely moved, re-indented,
de-indented, or reformatted without logic changes. If code appears in the diff
only due to whitespace or structural reformatting (e.g., removing a with: block),
treat it as unchanged. Contributors should not feel obligated to address
pre-existing issues outside the scope of their contribution.

Files:

  • requirements.txt
  • comfy/ops.py
  • tests-unit/comfy_quant/test_mixed_precision.py
  • comfy/quant_ops.py
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Keep imports at module scope; avoid inline imports unless they are already part of an established optional-backend probe or are needed to avoid an import cycle.
Do not add unnecessary try/except blocks; use them for optional dependency, platform, or backend capability detection only when the program has a useful fallback, and prefer specific exception types when changing new code.
If a library version is pinned in requirements.txt, do not add code to ComfyUI to handle older versions of that library.
Remove any workarounds for PyTorch versions that ComfyUI no longer officially supports; deprecated workarounds include catching an exception and rerunning the same op with the input cast to float unless the code comments name the exact supported PyTorch versions.
Let unsupported model formats, invalid quantization metadata, and bad states fail with clear errors instead of silently producing lower quality output.
Match the existing local style in the file you edit; long lines, simple helper functions, module-level state, and direct tensor operations are acceptable when they make the code easier to follow.
Keep comments sparse and useful; strip comments that restate the code or describe obvious behavior, and keep short TODOs only when they name the concrete missing follow-up.
Treat dtype, device placement, VRAM usage, and offloading behavior as core correctness concerns; check CPU, CUDA, ROCm, MPS, DirectML, XPU, NPU, and low-VRAM implications when touching shared execution or loading code.
Prefer native ComfyUI formats and existing quantization/offload helpers over adding parallel code paths; use comfy.quant_ops, comfy.model_management, comfy.memory_management, comfy.pinned_memory, comfy_aimdo, and comfy-kitchen helpers where they already solve the problem.
Use optimized comfy-kitchen ops in places where they improve performance without changing the expected dtype, device, memory, or interface behavior.
All models should use the optimized atte...

Files:

  • comfy/ops.py
  • tests-unit/comfy_quant/test_mixed_precision.py
  • comfy/quant_ops.py
comfy/**

⚙️ CodeRabbit configuration file

comfy/**: Core ML/diffusion engine. Focus on:

  • Backward compatibility (breaking changes affect all custom nodes)
  • Memory management and GPU resource handling
  • Performance implications in hot paths
  • Thread safety for concurrent execution

Files:

  • comfy/ops.py
  • comfy/quant_ops.py
🧠 Learnings (3)
📚 Learning: 2026-02-24T06:20:53.084Z
Learnt from: christian-byrne
Repo: Comfy-Org/ComfyUI PR: 12604
File: requirements.txt:0-0
Timestamp: 2026-02-24T06:20:53.084Z
Learning: When reviewing Python dependency files, do not flag or comment on whether a package version exists on PyPI. Treat versions in requirements.txt as valid and focus reviews on correctness of syntax, formatting, and usage rather than PyPI availability.

Applied to files:

  • requirements.txt
📚 Learning: 2026-02-21T14:01:41.482Z
Learnt from: pythongosssss
Repo: Comfy-Org/ComfyUI PR: 12555
File: comfy_extras/nodes_glsl.py:719-724
Timestamp: 2026-02-21T14:01:41.482Z
Learning: In PyOpenGL, bare Python scalars can be accepted for 1-element array parameters by NumberHandler. This means you can pass an int/float directly to OpenGL texture deletion (e.g., glDeleteTextures(tex)) without wrapping in a list. Verify function-specific expectations and ensure types match what the OpenGL call expects; use explicit lists only when the API requires an array.

Applied to files:

  • comfy/ops.py
  • tests-unit/comfy_quant/test_mixed_precision.py
  • comfy/quant_ops.py
📚 Learning: 2026-05-13T12:31:45.069Z
Learnt from: rattus128
Repo: Comfy-Org/ComfyUI PR: 13802
File: comfy/pinned_memory.py:19-30
Timestamp: 2026-05-13T12:31:45.069Z
Learning: When reviewing code that uses comfy/pinned_memory.py’s `HostBuffer.extend(size=..., reallocate=...)`: by default (`reallocate` is not True / False), `extend(size=...)` is a *relative increment* that grows the buffer by `size` bytes—so slicing like `[offset:offset+size]` after `hostbuf.extend(size=size)` is correct and the argument should not be rewritten to `offset + size`. Only in the single-segment reallocation mode (`reallocate=True`, e.g., as used by `resize_pin_buffer()` in `comfy/model_management.py`) should `size` be treated as an *absolute target* and the call/arguments should be checked accordingly.

Applied to files:

  • comfy/ops.py
  • comfy/quant_ops.py
🪛 ast-grep (0.44.1)
tests-unit/comfy_quant/test_mixed_precision.py

[info] 315-315: use jsonify instead of json.dumps for JSON output
Context: json.dumps({"layers": layer_quant_config})
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🔇 Additional comments (4)
requirements.txt (1)

25-25: LGTM!

comfy/quant_ops.py (1)

13-13: LGTM!

Also applies to: 55-57, 186-186, 198-198, 236-242, 255-255

comfy/ops.py (1)

1107-1121: LGTM!

Also applies to: 1168-1172, 1453-1458

tests-unit/comfy_quant/test_mixed_precision.py (1)

18-18: LGTM!

Also applies to: 287-338


📝 Walkthrough

Walkthrough

Adds ConvRot W4A4 quantization support through Comfy-Kitchen layout registration and algorithm configuration. Quantized weight loading now records ConvRot-specific metadata, state-dict serialization preserves selected parameters, and MoE expert reconstruction forwards the added layout values. The Comfy-Kitchen dependency is updated, and unit tests cover loading, layout parameters, forward computation, and metadata round-tripping.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding support for convrot int4 models.
Description check ✅ Passed The description is directly related to the PR and explains the new linear_dtype behavior and test model.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@comfyanonymous
comfyanonymous merged commit 73e84d5 into master Jul 9, 2026
22 checks passed
@comfyanonymous
comfyanonymous deleted the convrot_int4 branch July 9, 2026 22:57
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants