Skip to content

Add global MONAI_LABEL_SKIP_SAM flag to skip SAM model loading - #1914

Open
habib-analyst wants to merge 2 commits into
Project-MONAI:mainfrom
habib-analyst:feat-skip-sam-1898
Open

habib-analyst wants to merge 2 commits into
Project-MONAI:mainfrom
habib-analyst:feat-skip-sam-1898

Conversation

@habib-analyst

@habib-analyst habib-analyst commented Oct 7, 2026 •

Copy link
Copy Markdown

Fixes #1898.

The per-app -c sam2 false workaround exists, but there is no server-wide way
to skip SAM/SAM2 download and initialization. This PR adds a global setting:

  • New MONAI_LABEL_SKIP_SAM setting in monailabel/config.py
    (env var MONAI_LABEL_SKIP_SAM, also settable via .env), default False.
  • is_sam2_module_available() in monailabel/sam2/utils.py now returns
    False when the flag is on, so no SAM weights are downloaded or initialized.

Since every sample app already gates SAM loading on
is_sam2_module_available(), this one change covers radiology, pathology,
endoscopy, and monaibundle with no per-app edits, and the existing per-app
-c sam2 false keeps working.

Usage: MONAI_LABEL_SKIP_SAM=True monailabel start_server --app apps/radiology ...

Default behavior is unchanged (False).

Summary by CodeRabbit

  • New Features
    • Added the MONAI_LABEL_SKIP_SAM setting, configurable through an environment variable and disabled by default. When enabled, MONAI Label reports SAM2 as unavailable without checking for its optional dependency. Existing dependency checks remain unchanged when the setting is disabled.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 03796379-d54f-4508-922c-57cbab99161f
📥 Commits

Reviewing files that changed from the base of the PR and between 0b1ee41 and 305e808.

📒 Files selected for processing (2)
  • monailabel/config.py
  • monailabel/sam2/utils.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

Adds the MONAI_LABEL_SKIP_SAM setting. When enabled, the SAM2 availability check returns False before checking for the optional sam2 import.

Changes

SAM/SAM2 opt-out

Layer / File(s) Summary
Configure and apply the SAM2 opt-out
monailabel/config.py, monailabel/sam2/utils.py
Settings reads MONAI_LABEL_SKIP_SAM from the environment and defaults it to false. When enabled, is_sam2_module_available returns False before checking for the sam2 import.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 305e8

The opt-out disables SAM registration without blocking DeepEdit or other configured interactive models. No current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a global MONAI_LABEL_SKIP_SAM flag to skip SAM model loading.
Linked Issues check ✅ Passed Issue #1898 requires a server-side way to skip SAM startup loading. Settings adds MONAI_LABEL_SKIP_SAM with a default of False and environment/.env configuration. is_sam2_module_available() …
Out of Scope Changes check ✅ Passed The reviewed changes are limited to the new SAM skip setting in monailabel/config.py and the SAM availability check in monailabel/sam2/utils.py. Both changes directly implement issue #1898. No unr…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SachidanandAlle

SachidanandAlle commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

please take look into new version of monailabel: https://github.com/Project-MONAI/MONAILabel/tree/1.0

LinkedIn Post: https://lnkd.in/p/esPWFJjh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to turn-off SAM model loading

2 participants