From 26aac1855bffe0ccd1bbd171272d268858c20dfc Mon Sep 17 00:00:00 2001 From: Habib Ur Rehman Date: Wed, 7 Oct 2026 21:44:27 +0500 Subject: [PATCH 1/2] Add global MONAI_LABEL_SKIP_SAM flag to skip SAM model loading --- monailabel/config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/monailabel/config.py b/monailabel/config.py index ea8d1c37e..6a31ad834 100644 --- a/monailabel/config.py +++ b/monailabel/config.py @@ -120,6 +120,11 @@ class Settings(BaseSettings): strtobool(os.environ.get("MONAI_LABEL_USE_ITK_FOR_DICOM_SEG", "True")) ) + # Skip SAM/SAM2 model download and initialization at server/app startup. + # Useful when running apps with their own interactive models (e.g. DeepEdit) + # where the generic SAM overhead (VRAM + startup latency) is not wanted. + MONAI_LABEL_SKIP_SAM: bool = bool(strtobool(os.environ.get("MONAI_LABEL_SKIP_SAM", "False"))) + model_config = SettingsConfigDict( env_file=".env", case_sensitive=True, From 305e80848e14036fd4dd8863ddba07585a39d53b Mon Sep 17 00:00:00 2001 From: Habib Ur Rehman Date: Wed, 7 Oct 2026 21:46:01 +0500 Subject: [PATCH 2/2] Add global MONAI_LABEL_SKIP_SAM flag to skip SAM model loading --- monailabel/sam2/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/monailabel/sam2/utils.py b/monailabel/sam2/utils.py index 8abaef244..7a371a91c 100644 --- a/monailabel/sam2/utils.py +++ b/monailabel/sam2/utils.py @@ -1,7 +1,13 @@ from monai.utils import optional_import +from monailabel.config import settings + def is_sam2_module_available(): + # Global opt-out: skip SAM entirely (no download, no init) when set, + # e.g. MONAI_LABEL_SKIP_SAM=True, instead of per-app `-c sam2 false`. + if settings.MONAI_LABEL_SKIP_SAM: + return False try: _, flag = optional_import("sam2") return flag