ComfyUI-Falcon-Perception
An elegant, robust, and highly-optimized ComfyUI custom node package for the tiiuae/Falcon-Perception vision-language model for open-vocabulary grounding and instance…
ComfyUI Falcon Perception
An elegant, robust, and highly-optimized ComfyUI custom node package for the tiiuae/Falcon-Perception vision-language model.
Falcon Perception is a 0.6B parameter early-fusion model designed for open-vocabulary grounding and instance segmentation. Given an image and a natural language query (e.g., "a red car" or "girl"), it returns precise pixel-accurate masks.
This ComfyUI port has been completely refactored from the official HuggingFace implementation to provide a seamless, bug-free experience on Windows and all PyTorch versions (>=2.5.0).
🌟 Key Features & Improvements
- No HuggingFace Cache Hell: Bypasses
trust_remote_code=Truecompletely. The architecture is natively bundled infalcon_core/, ensuring you never run into remote code injection bugs or version mismatches. - Single File Weight Loading: No need to download a messy repository of
.pyand.jsonfiles. You only need one.safetensorsweight file. - OOM & VRAM Optimized: Fixed severe OOM issues present in the official upsampler mask generation ($O(N^2)$ footprint). It gracefully falls back to PyTorch's native
scaled_dot_product_attention(FlashAttention2) for massive memory savings. - Windows & Triton Friendly: Automatically detects your environment. If Triton is missing or PyTorch compilation fails (common on Windows), it gracefully falls back to Eager Mode without crashing.
- PyTorch 2.7.0+ Compatibility: Includes custom patches for the newly introduced
flex_attentionAPI changes and the removal ofAuxRequest/BlockMask.
🛠️ Installation
-
Clone or Download this repository into your ComfyUI's
custom_nodes/directory:cd ComfyUI/custom_nodes/ git clone https://github.com/your-username/ComfyUI-Falcon-Perception.git -
Install Dependencies: Navigate into the folder and install the requirements using your ComfyUI's Python environment. (Note: This model strictly requires PyTorch 2.5.0 or newer for the
flex_attentionmodule)cd ComfyUI-Falcon-Perception # If using ComfyUI portable: ..\..\..\python_embeded\python.exe -m pip install -r requirements.txt # Or standard venv: pip install -r requirements.txt
📦 Model Weights Setup
Unlike the official HuggingFace pipeline, this node only cares about the safetensors weight file.
- Download the
model.safetensorsfile from the official HuggingFace Repo. - Create a folder named
falcon_perceptioninside your ComfyUImodels/directory. - Place the downloaded
.safetensorsfile inside.
Your directory structure should look like this:
ComfyUI/
└── models/
└── falcon_perception/
└── model.safetensors
🖥️ Usage in ComfyUI
After restarting ComfyUI, you will find two new nodes under the FalconPerception category:
1. Load Falcon Perception Model
model_name_or_path: The path to your.safetensorsfile relative to themodels/folder. (Default:falcon_perception/model.safetensors)device: Selectauto,cuda, orcpu.
2. Falcon Perception Generate
Connect your image and the loaded model here.
query: Natural language text describing what you want to segment (e.g.,"cat","car window","girl").max_new_tokens: Decoding steps limit.min_dimension/max_dimension: Image resizing bounds before passing to the model.compile_model: Enabletorch.compile(Not recommended for Windows users without Triton).
Outputs:
combined_mask: A single flat mask containing all found instances merged together.individual_masks: A batch of masks, each isolating a single found instance.info: Textual data detailing the coordinatesxyand sizehwof every detected instance.
⚠️ Requirements
- PyTorch >= 2.5.0: The architecture uses the new
torch.nn.attention.flex_attentionAPI. If you encounter anImportError, you MUST upgrade your PyTorch environment. einops,pycocotools,transformers,pillow(Included inrequirements.txt).
📜 Acknowledgements
Based on the original tiiuae/Falcon-Perception model by the Technology Innovation Institute. Custom refactoring, PyTorch API patching, and VRAM optimizations by the ComfyUI community.