comfyui-trtupscaler

comfyui-trtupscaler
★ 3

TensorRT加速切片拼接FP16/FP32批处理
基于TensorRT的ComfyUI图像放大节点,提供GPU加速、切片批处理、FP16/FP32精度与羽化融合,自动识别模型文件,提升放大速度与无缝性。
💡 用于对高分辨率图片进行快速无缝放大和批量处理。
🍴 2 Forks💻 Python🔄 2025-06-11
📦
网盘下载
复制链接后前往夸克网盘下载
https://pan.quark.cn/s/8b0992d318c3
📦 requirements.txt
#
TensorRT
Upscaler
ComfyUI
Node
Dependencies
#
Core
dependencies
torch>=2.0.0
torchvision>=0.15.0
numpy>=1.21.0
pillow>=8.0.0
#
Model
loading
and
conversion
spandrel>=0.3.0
spandrel-extra-arches>=0.1.0
onnx>=1.12.0
#
TensorRT
(must
be
installed
separately
from
NVIDIA)
#
tensorrt>=8.6.0
#
Uncomment
if
installing
via
pip
(not
recommended)
#
pycuda>=2021.1
#
Uncomment
if
installing
via
pip
#
Optional:
for
downloading
models
requests>=2.25.0
tqdm>=4.62.0
#
Development
dependencies
(for
testing)
#
pytest>=6.0.0
#
pytest-cov>=2.12.0
image
📄 README

ComfyUI TensorRT Upscaler

A high-performance image upscaling node for ComfyUI using TensorRT acceleration.

Features

  • TensorRT-accelerated inference for fast upscaling
  • Batch processing support
  • Tile-based processing for large images
  • Support for both FP16 and FP32 precision
  • Automatic model detection from file names
  • Feathered tile blending to reduce seams
  • Requirements

    System Requirements

  • NVIDIA GPU with Compute Capability 6.0+ (Pascal architecture or newer)
  • CUDA 11.8 or newer
  • Windows 10/11 or Linux
  • Software Dependencies

  • TensorRT 8.6.0 or newer
  • Python 3.8+
  • PyTorch 2.0+
  • CUDA-compatible GPU drivers
  • Installation

    1. Install TensorRT

    Download and install TensorRT from NVIDIA Developer:

    https://developer.nvidia.com/tensorrt

    Follow NVIDIA’s installation guide for your platform.

    2. Install Python Dependencies

    pip install -r requirements.txt

    3. Set up Models

    Run the setup script to download and convert models:

    Windows:

    setup_models.bat

    Linux/Manual:

    python convert_model.py <model_name> --models-dir ../../models/upscale_models

    Supported Models

    The node automatically detects upscaling models in the models/upscale_models directory. Currently supported:

  • 4x_foolhardy_Remacri
  • 4x-UltraSharp
  • Any compatible .pth model (requires conversion)
  • Usage

  • Add the “TRT Upscaler” node to your ComfyUI workflow
  • Connect an image input
  • Select your model from the dropdown
  • Adjust tile size and overlap as needed
  • Choose precision (FP16 recommended for speed)
  • Parameters

  • image: Input image tensor
  • model_name: TensorRT model to use for upscaling
  • tile_size: Size of processing tiles (64-2048, default: 512)
  • tile_overlap: Overlap between tiles (0-256, default: 32)
  • use_fp16: Use FP16 precision (faster, slightly lower quality)
  • Tile Settings Guidelines

  • Small GPU memory: Use smaller tile sizes (256-512)
  • Large GPU memory: Use larger tile sizes (1024-2048)
  • High overlap: Better blending but slower processing
  • Low overlap: Faster but may show tile seams
  • Model Conversion

    To convert your own .pth models:

  • Place the .pth file in models/upscale_models/
  • Run: python convert_model.py
  • The script will create both FP16 and FP32 TensorRT engines
  • Performance Tips

  • Use FP16: ~2x faster with minimal quality loss
  • Optimize tile size: Balance between speed and memory usage
  • Batch processing: Process multiple images together when possible
  • GPU memory: Monitor VRAM usage and adjust tile size accordingly
  • Troubleshooting

    “TensorRT not available”

  • Ensure TensorRT is properly installed
  • Check that CUDA is available: nvidia-smi
  • Verify Python can import tensorrt: python -c "import tensorrt"
  • “No TRT models found”

  • Run setup_models.bat to download and convert models
  • Check that .trt files exist in models/upscale_models/
  • Ensure model names include scale factor (e.g., “4x”, “2x”)
  • Out of memory errors

  • Reduce tile size
  • Use FP16 precision
  • Close other GPU-intensive applications
  • Consider upgrading GPU memory
  • Poor upscaling quality

  • Try FP32 precision
  • Increase tile overlap
  • Use a different model
  • Check input image quality
  • Development

    Running Tests

    python -m pytest test_trt_upscaler.py -v

    Adding New Models

  • Add model URL to setup_models.bat
  • Ensure model follows naming convention (include scale factor)
  • Test conversion with convert_model.py
  • File Structure

    comfyui-trtupscaler/
    ├── __init__.py              # Node registration
    ├── nodes.py                 # Main TRTUpscaler node
    ├── convert_model.py         # Model conversion utilities
    ├── setup_models.bat         # Windows setup script
    ├── requirements.txt         # Python dependencies
    ├── test_trt_upscaler.py     # Unit tests
    └── README.md               # This file

    License

    This project follows the same license as ComfyUI.

    Contributing

  • Fork the repository
  • Create a feature branch
  • Add tests for new functionality
  • Submit a pull request
  • Support

    For issues and questions:

  • Check the troubleshooting section
  • Review ComfyUI logs for detailed error messages
  • Open an issue with system info and error details