Nodes/ComfyUI-Grounding/SAM2Model (down)Loader
ComfyUI Node

SAM2Model (down)Loader

The 'DownLoad' Typo Node That Fetches SAM2 For You

By PozzettiAndrea·Created 10 months ago·Updated about 18 hours ago· 47
SAM2Model (down)Loader
    • sam2_model
    model
    segmentor
    device
    precisionfp16

    Yes, the class is literally DownLoadSAM2Model - the camelCase typo is part of its charm. What it actually is: the loader that gets Meta's SAM2 segmentation model into memory for the Sam2 Segment node, downloading the weights automatically on first use so you never have to hunt for a checkpoint on Hugging Face yourself.

    SAM2 is the "precise mask" half of this pack's detect-then-segment pipeline, the same role SAM played in the classic GroundingDINO + SAM stacks the KB's background-removal essay describes - except SAM2 is the improved successor with better accuracy and actual video support. The loader is where you decide how much quality and how much VRAM you're willing to trade.

    The four inputs, all required

    • model - eight variants across two generations: sam2_hiera_tiny, _small, _base_plus, _large, and the corresponding sam2.1_hiera_* versions. base_plus is the usual sweet spot; tiny/small are the VRAM-savers, large is the quality pick.
    • segmentor - single_image, video, or automaskgenerator. This choice gets baked into the model and changes what Sam2 Segment can do with it. single_image covers 95% of use.
    • device - cuda, cpu, or mps. Straightforward, with one gotcha below.
    • precision - fp16 (default), bf16, or fp32. fp16 is fine for practically everyone; fp32 is the fallback when you hit fp16 artifacts or a CPU; bf16 is a decent middle ground on Ampere+.

    How it works

    Under the hood it downloads from kijai's Kijai/sam2-safetensors repo into ComfyUI/models/sam2 the first time you run a given model. For the 2.1 line in fp16/bf16 it fetches the pre-converted -fp16 safetensors files, and on Ampere-and-newer CUDA GPUs it flips on TF32 matmul for speed. Everything gets cached in memory, so the second run of a workflow is near-instant - same smart-cache pattern as the rest of the pack.

    Output is a single sam2_model wire, which goes into Sam2 Segment. That's the whole job.

    Installing it

    This node ships inside ComfyUI-Grounding, so it's the same one-time install:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/PozzettiAndrea/ComfyUI-Grounding
    cd ComfyUI-Grounding
    pip install -r requirements.txt
    

    Then restart ComfyUI, or install "ComfyUI-Grounding" from Manager. The weights aren't bundled - the first run downloads whatever variant you picked, from roughly 150MB for tiny up to a couple of GB for large. Subsequent loads come from disk plus the in-memory cache.

    Where people get burned

    • CPU + fp16 - the loader hard-refuses fp16/bf16 on CPU ("fp16 and bf16 are not supported on cpu"). Switch to fp32 if you're CPU-bound.
    • automaskgenerator trap - pick it in the loader and Sam2 Segment will reject it with a message telling you to use a separate auto-mask node. If you only have this pack, single_image is the one to choose.
    • Video quirks - with the video segmentor, SAM2 2.0 can't take bboxes at all (2.1 can), and the model resizes frames to its native input size before segmenting.
    • GIMM-VFI conflict - SAM2 and Florence-2 patch global CUDA/TF32 state, so this pack and kijai's GIMM-VFI frame-interpolation pack can't reliably coexist. If you run both and see random import errors, the README's advice is to uninstall GIMM-VFI.
    CategorySAM2

    Inputs (4)

    NameTypeDefaultDescription
    modelCOMBO8 options: sam2_hiera_base_plus.safetensors, sam2_hiera_large.safetensors, sam2_hiera_small.safetensors, sam2_hiera_tiny.safetensors, sam2.1_hiera_base_plus.safetensors, sam2.1_hiera_large.safetensors, +2
    segmentorCOMBO3 options: single_image, video, automaskgenerator
    deviceCOMBO3 options: cuda, cpu, mps
    precisionCOMBOfp163 options: fp16, bf16, fp32

    Outputs (1)

    NameTypeDescription
    sam2_modelSAM2MODEL