Skip to content

Add TINT4 — INT4 Weight-Only Quantization via torchao#3074

Closed
JWLHS wants to merge 4 commits into
Comfy-Org:mainfrom
JWLHS:add-tint4
Closed

Add TINT4 — INT4 Weight-Only Quantization via torchao#3074
JWLHS wants to merge 4 commits into
Comfy-Org:mainfrom
JWLHS:add-tint4

Conversation

@JWLHS

@JWLHS JWLHS commented Jul 10, 2026

Copy link
Copy Markdown

TINT4 — torchao INT4 Weight-Only Quantization for ComfyUI

Repository: https://github.com/JWLHS/ComfyUI-TINT4

What it does

INT4 weight-only quantization (W4A16) for diffusion models via torchao. Activations remain FP16 — zero quantization quality loss.

Nodes

Node Function
TINT4 Model Quantizer Quantize FP16/BF16 models to INT4 safetensors
TINT4 Model Loader Load quantized models
TINT4 LoRA Loader Single LoRA injection (standard + LoKr, QKV fused/independent)
TINT4 LoRA Stack Multi-LoRA stack (≤5)

Key features

  • Full LoRA support — forward-time injection, no kernel modification
  • 3-layer acceleration — IS_CHANGED fingerprint skip (0s repeat), SHA256 JSON cache (<1s hit), GPU pre-hook bake-in
  • Multi-backend — Intel Arc XPU, NVIDIA CUDA, AMD ROCm
  • 12+ model exclusion lists — Krea2 Turbo, Flux2 Klein 9B, Z-Image, Boogu, WAN, LTX2, Qwen, Ernie, HiDream, Chroma, Ideogram4

Performance (Arc A770, Krea2 Turbo)

LoRA Layers First load Cache hit IS_CHANGED
BreastSlider 104 0.05s 0.04s 0s
YFG GPT 256 0.63s 0.49s 0s
Onyx_V1 264 4.78s <1s 0s

Requirements

# NVIDIA CUDA / AMD ROCm / CPU
pip install torchao>=0.17.0
# Intel XPU (Arc GPU)
pip install torchao --index-url https://download.pytorch.org/whl/xpu
Intel XPU users: after installing torchao, run fix_torchao_xpu.bat (included in the plugin) to patch missing submodules in the XPU fork.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • custom-node-list.json
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 41d15c7e-bea1-4efa-a764-6bddc0083a85

📥 Commits

Reviewing files that changed from the base of the PR and between 241d909 and f44cb8c.

📒 Files selected for processing (1)
  • custom-node-list.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

A new tint4_xpu node entry was added to custom-node-list.json, documenting torchao-based INT4 weight-only quantization, supported hardware, installation details, references, and requirements.

Changes

TINT4 Node Registration

Layer / File(s) Summary
Add TINT4 catalog entry
custom-node-list.json
Registers the TINT4 node with attribution, references, git-clone installation, W4A16/FP16 details, LoRA and caching behavior, supported backends, verification targets, and the torchao>=0.17.0 requirement.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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.

@ltdrdata

Copy link
Copy Markdown
Member

The repository at https://github.com/JWLHS/ComfyUI-TINT4-XPU is currently not accessible (404). If the repository was made private by mistake or moved to a different URL, please make it public again or update the PR with the correct reference. I'll re-evaluate once the repository is reachable.

@JWLHS

JWLHS commented Jul 11, 2026

Copy link
Copy Markdown
Author

目前该仓库https://github.com/JWLHS/ComfyUI-TINT4-XPU无法访问(404错误)。如果仓库被误设为私有或已迁移到其他URL,请将其重新设为公开,或更新PR并提供正确的URL。仓库恢复访问后,我会重新评估。

Sorry, I modified the library name earlier, but I forgot it.
https://github.com/JWLHS/ComfyUI-TINT4

@ltdrdata

Copy link
Copy Markdown
Member

Thanks — the repository is now reachable at https://github.com/JWLHS/ComfyUI-TINT4. Two things before this can be merged:

  1. The PR still references the old URL https://github.com/JWLHS/ComfyUI-TINT4-XPU (which 404s). Please update the reference/files in the PR to the new URL.

  2. Write-side path traversal — the output_filename STRING input (tint4_quantizer.py:174) is joined into the save path with no containment:

    • tint4_quantizer.py:195: os.path.join(folder_paths.get_output_directory(), f"{output_filename}.safetensors")
    • tint4_quantizer.py:198 os.makedirs(dst_dir) then :344 comfy.utils.save_torch_file(sd, dst_path)

    A value like ../../../../home/<user>/.config/foo or an absolute path writes the safetensors file outside the ComfyUI output directory. Please reduce output_filename to a basename (os.path.basename) and reject ../absolute paths, or validate the resolved path with os.path.realpath + os.path.commonpath against get_output_directory() before writing.

I'll re-evaluate once the URL is updated and the output path is contained.

@JWLHS

JWLHS commented Jul 15, 2026

Copy link
Copy Markdown
Author

Thanks — the repository is now reachable at https://github.com/JWLHS/ComfyUI-TINT4. Two things before this can be merged:

  1. The PR still references the old URL https://github.com/JWLHS/ComfyUI-TINT4-XPU (which 404s). Please update the reference/files in the PR to the new URL.

  2. Write-side path traversal — the output_filename STRING input (tint4_quantizer.py:174) is joined into the save path with no containment:

    • tint4_quantizer.py:195: os.path.join(folder_paths.get_output_directory(), f"{output_filename}.safetensors")
    • tint4_quantizer.py:198 os.makedirs(dst_dir) then :344 comfy.utils.save_torch_file(sd, dst_path)

    A value like ../../../../home/<user>/.config/foo or an absolute path writes the safetensors file outside the ComfyUI output directory. Please reduce output_filename to a basename (os.path.basename) and reject ../absolute paths, or validate the resolved path with os.path.realpath + os.path.commonpath against get_output_directory() before writing.

I'll re-evaluate once the URL is updated and the output path is contained.

Repository URL has been updated to https://github.com/JWLHS/ComfyUI-TINT4.
Path traversal fix applied — output_filename is now sanitized via os.path.basename before path joining.

@JWLHS

JWLHS commented Jul 16, 2026

Copy link
Copy Markdown
Author

Thanks — the repository is now reachable at https://github.com/JWLHS/ComfyUI-TINT4. Two things before this can be merged:

  1. The PR still references the old URL https://github.com/JWLHS/ComfyUI-TINT4-XPU (which 404s). Please update the reference/files in the PR to the new URL.

  2. Write-side path traversal — the output_filename STRING input (tint4_quantizer.py:174) is joined into the save path with no containment:

    • tint4_quantizer.py:195: os.path.join(folder_paths.get_output_directory(), f"{output_filename}.safetensors")
    • tint4_quantizer.py:198 os.makedirs(dst_dir) then :344 comfy.utils.save_torch_file(sd, dst_path)

    A value like ../../../../home/<user>/.config/foo or an absolute path writes the safetensors file outside the ComfyUI output directory. Please reduce output_filename to a basename (os.path.basename) and reject ../absolute paths, or validate the resolved path with os.path.realpath + os.path.commonpath against get_output_directory() before writing.

I'll re-evaluate once the URL is updated and the output path is contained.

The URL has been modified in my second submission.

@JWLHS

JWLHS commented Jul 20, 2026

Copy link
Copy Markdown
Author

Thanks — the repository is now reachable at https://github.com/JWLHS/ComfyUI-TINT4. Two things before this can be merged:

  1. The PR still references the old URL https://github.com/JWLHS/ComfyUI-TINT4-XPU (which 404s). Please update the reference/files in the PR to the new URL.

  2. Write-side path traversal — the output_filename STRING input (tint4_quantizer.py:174) is joined into the save path with no containment:

    • tint4_quantizer.py:195: os.path.join(folder_paths.get_output_directory(), f"{output_filename}.safetensors")
    • tint4_quantizer.py:198 os.makedirs(dst_dir) then :344 comfy.utils.save_torch_file(sd, dst_path)

    A value like ../../../../home/<user>/.config/foo or an absolute path writes the safetensors file outside the ComfyUI output directory. Please reduce output_filename to a basename (os.path.basename) and reject ../absolute paths, or validate the resolved path with os.path.realpath + os.path.commonpath against get_output_directory() before writing.

I'll re-evaluate once the URL is updated and the output path is contained.

Path traversal fix already applied in the plugin repo:
https://github.com/JWLHS/ComfyUI-TINT4/blob/557737d/tint4_quantizer.py#L332

output_filename = os.path.basename(output_filename) strips all directory components — ../ sequences, absolute paths, and any path separators are all dropped before joining with the output directory.

The old repository URL is also fully removed from custom-node-list.jsonfindstr "TINT4-XPU" returns zero matches in the PR branch.

Please re-evaluate when you have a moment.

@ltdrdata

Copy link
Copy Markdown
Member

Due to merge conflicts, I've registered ComfyUI-TINT4 in custom-node-list.json directly, using the title and description from this PR. The write-side path traversal I flagged earlier (output_filename) is confirmed fixed at head (os.path.basename containment).

Closing this PR — the nodepack is now registered. Thanks!

@ltdrdata ltdrdata closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants