Nodes/Tojioo Passthrough/Any SAM Model Switch
ComfyUI Node

Any SAM Model Switch

Swap SAM checkpoints by slot order

By Tojioo·Created 11 months ago·Updated 7 months ago· 13
Any SAM Model Switch
  • sam_model_1
  • sam_model

Any SAM Model Switch returns the first connected SAM_MODEL input by slot order and feeds it to the sam_model output. If you use SAM or SAM2 for segmentation, you know the shuffle: SAM checkpoints come in flavors - sam_vit_b, sam_vit_l, sam_vit_h, and SAM2 variants - and they're very much not interchangeable in size or speed. This node lets you keep two or three loaded and pick between them by mute instead of re-wiring the segmenter.

It's the fallback-switch pattern the community knows from rgthree's Any Switch, typed to SAM_MODEL so it only accepts SAM checkpoints. In a masking workflow it slots in right before the SAM loader's output meets your segmentation node - exactly the wire you'd otherwise re-drag when you swap from the fast model to the accurate one.

How it works

Start with sam_model_1; connect another SAM source and a sam_model_2 slot grows. On each run it collects the connected inputs that aren't None and returns the lowest-numbered one. Muted or bypassed upstream nodes deliver None - and those are skipped - so muting the loader feeding sam_model_1 hands the job to sam_model_2 automatically. With nothing connected, the node raises "no inputs connected" rather than returning an unloaded model.

Where you'd use it

  • Fast vs. accurate. The small ViT-B in sam_model_1 for drafts, the big ViT-H in sam_model_2 for finals, mute to flip.
  • SAM vs. SAM2. Two generations of segmenter, one segmentation node downstream.
  • Fallback routing. Preferred checkpoint first, fallback second.

Install

ComfyUI Manager → search "Tojioo Passthrough" → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Tojioo/tojioo_passthrough.git

Restart ComfyUI. No pip dependencies and no models bundled - the pack is lean Python plus a frontend, on the Comfy Registry under publisher tojioo. The SAM checkpoints themselves are a separate download from their usual sources.

Common issues

Slot order is the rule: a live sam_model_1 always beats sam_model_2, so a "wrong" checkpoint means the earlier slot's upstream is muted, bypassed, or unwired. This node selects a model; it doesn't compare or merge. And the real gotcha with SAM swapping isn't the switch at all - it's that SAM checkpoints expect specific backbone configs, so a mismatch shows up as a weird mask or an error from your SAM node, not from this one. Keep at least one slot wired or the node errors on the canvas.

CategoryTojioo Passthrough/Dynamic Nodes/Switch Nodes

Inputs (1)

NameTypeDefaultDescription
sam_model_1optSAM_MODEL

Outputs (1)

NameTypeDescription
sam_modelSAM_MODEL