Nodes/ComfyUI-CustomNodePacks/SAM Model Loader — SAM2.1 / SAM3
ComfyUI Node

SAM Model Loader — SAM2.1 / SAM3

Load 2.1 or 3, let it offload to save VRAM

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
SAM Model Loader — SAM2.1 / SAM3
    • sam_model
    model_name
    model_typeauto
    deviceauto
    offload_to_cpufalse
    dtypefloat16

    Before any SAM mask happens in this pack, a loader has to get the model into memory - and this is that node. SAM Model Loader (MEC) loads SAM 2.1 or SAM 3 checkpoints, auto-detects the architecture from the filename, and adds a VRAM offload toggle that matters more than you'd think on a card already hosting a diffusion model.

    What it loads

    The loading story: it scans ComfyUI/models/sams/ (for SAM 3) and ComfyUI/models/sam2/ (for SAM 2.1) and lists what's there in the model_name dropdown. Filenames drive detection - sam2.1_hiera_large.pt loads as SAM 2.1, sam3_hiera_large.pt as SAM 3 - but you can force it with model_type (auto / sam2.1 / sam3) if a filename is ambiguous. Models prefixed [download] in the list auto-download from HuggingFace Hub on first use, so you can get going without hunting for weights. Legacy SAM 1 and the original SAM 2.0 line are explicitly not supported anymore - only 2.1 and 3 - so old ViT-H/ViT-L checkpoints won't load.

    The settings that affect your machine

    The three settings that affect your machine: device (auto picks CUDA when present), dtype (float16 default, bfloat16 for newer GPUs, float32 if you're chasing max fidelity), and offload_to_cpu. That last one is the sleeper feature - with it on, the SAM model rests on CPU and only moves to the GPU for each inference, then returns. The tooltip's honest math: it saves roughly 2–4 GB of VRAM at the cost of slower inference. If you're running SAM next to a Wan or SDXL model on a 12 GB card, that trade is frequently the difference between "works" and "OOM."

    One output, many consumers

    One output: sam_model (a SAM_MODEL wrapper). It feeds every SAM consumer in the pack - SAMMaskGeneratorMEC, SamMultiMaskPickerMEC (as an optional override), and SAMViTMattePipelineMEC - and the wrapper carries the device/offload state, which the inference nodes honor via the pack's device-juggling helpers. That's worth knowing: load once with offload, and all the downstream nodes share the memory discipline instead of each re-loading.

    Mechanically, the model family is Meta's promptable segmenter - a heavy ViT image encoder with a light prompt encoder + mask decoder, which is why one load can serve many prompts cheaply (encode the image once, re-prompt freely). SAM 3 adds open-vocabulary concept segmentation on top of the SAM 2 infrastructure; the KB's SAM panel has the full history if you want the context.

    Install

    Install: clone Code2Collapse/ComfyUI-CustomNodePacks into ComfyUI/custom_nodes (or Manager → "CustomNodePacks"), then pip install git+https://github.com/facebookresearch/sam2.git for the SAM 2.1 runtime - SAM 3 is vendored in the pack. Weights go in models/sam2/ and models/sams/. The known community obstacle, per the KB: SAM 3's nodes want Triton, which is a real headache on Windows; SAM 2.1 sidesteps it entirely, and since this loader handles both, that's your escape hatch.

    CategoryC2C/SAM

    Inputs (5)

    NameTypeDefaultDescription
    model_nameCOMBOSAM checkpoint (.pth/.pt/.safetensors). Models prefixed with [download] will be auto-downloaded from HuggingFace Hub on first use.
    model_typeCOMBOautoModel architecture. 'auto' detects from filename. sam2.1: Segment Anything 2.1 (requires sam2 package) sam3: SAM3 (uses SAM2 infrastructure)
    deviceCOMBOautoDevice to load the model on. 'auto' picks CUDA when available.
    offload_to_cpuBOOLEANfalseKeep model on CPU between inferences. Saves ~2-4 GB VRAM at cost of slower inference.
    dtypeCOMBOfloat16Model precision. float16 saves VRAM, bfloat16 for newer GPUs.

    Outputs (1)

    NameTypeDescription
    sam_modelSAM_MODELLoaded SAM model wrapper for downstream SAM nodes.