From 2cecf779810795ef70cc6b59ff37fb2cf06486e6 Mon Sep 17 00:00:00 2001 From: William Gill Date: Sun, 19 Apr 2026 15:21:21 -0500 Subject: [PATCH] =?UTF-8?q?Pin=20transformers=20<5=20=E2=80=94=20comfyui?= =?UTF-8?q?=5Fsegment=5Fanything's=20GroundingDINO=20needs=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit transformers 5.0 removed BertModel.get_head_mask (it was on the legacy 4.x API). comfyui_segment_anything's GroundingDINO bertwarper.py still calls bert_model.get_head_mask in __init__, so first inpaint crashes with AttributeError. Pinned transformers>=4.40,<5 in two places: - Dockerfile: applied AFTER the custom node's requirements.txt install so it wins on a fresh image build. - install-custom-node-deps.sh entrypoint: re-applied at every container start so any future custom-node install (via ComfyUI-Manager or volume clone) that pulls a newer transformers transitively gets pinned back into the working range. Co-Authored-By: Claude Opus 4.7 (1M context) --- Dockerfile | 8 +++++++- install-custom-node-deps.sh | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2d321b3..ade182e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,9 +57,15 @@ RUN git clone --depth 1 https://github.com/ltdrdata/ComfyUI-Manager.git \ # mask_text parameter). Model weights auto-download on first use into # /opt/comfyui/models/{sams,grounding-dino}/ — first inpaint takes ~3 GB of # downloads, subsequent runs are instant. +# +# Transformers must stay <5: GroundingDINO inside this node calls +# BertModel.get_head_mask, which transformers 5.0 silently removed. The pin +# is applied AFTER the requirements install so it overrides anything the +# upstream requirements.txt would have pulled. RUN git clone --depth 1 https://github.com/storyicon/comfyui_segment_anything.git \ ${COMFYUI_HOME}/custom_nodes/comfyui_segment_anything && \ - pip install -q -r ${COMFYUI_HOME}/custom_nodes/comfyui_segment_anything/requirements.txt + pip install -q -r ${COMFYUI_HOME}/custom_nodes/comfyui_segment_anything/requirements.txt && \ + pip install -q "transformers>=4.40,<5" # Entrypoint wrapper — auto-installs requirements.txt for any custom_node # present at startup (covers Manager-installed nodes and nodes cloned diff --git a/install-custom-node-deps.sh b/install-custom-node-deps.sh index d0d28ab..ebdd1bf 100644 --- a/install-custom-node-deps.sh +++ b/install-custom-node-deps.sh @@ -18,4 +18,11 @@ if [ -d /opt/comfyui/custom_nodes ]; then done fi +# Force-pin known-incompatible packages back into a working range. Some +# custom nodes bring transformers >=5 transitively, which removes +# BertModel.get_head_mask and breaks comfyui_segment_anything's +# GroundingDINO. Run last so it wins over anything the loop above +# installed. +pip install -q "transformers>=4.40,<5" || echo "[entrypoint] transformers pin failed — continuing" + exec "$@"