SAM2Model (down)Loader
The 'DownLoad' Typo Node That Fetches SAM2 For You
- sam2_model
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 correspondingsam2.1_hiera_*versions.base_plusis the usual sweet spot;tiny/smallare the VRAM-savers,largeis the quality pick.segmentor-single_image,video, orautomaskgenerator. This choice gets baked into the model and changes what Sam2 Segment can do with it.single_imagecovers 95% of use.device-cuda,cpu, ormps. Straightforward, with one gotcha below.precision-fp16(default),bf16, orfp32. 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.
automaskgeneratortrap - 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_imageis the one to choose.- Video quirks - with the
videosegmentor, 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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | COMBO | 8 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 | |
| segmentor | COMBO | 3 options: single_image, video, automaskgenerator | |
| device | COMBO | 3 options: cuda, cpu, mps | |
| precision | COMBO | fp16 | 3 options: fp16, bf16, fp32 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| sam2_model | SAM2MODEL | — |