Skip to content

fix: emit nnUNet store_true flags as bare CLI args in nnUNetV2Runner - #8968

Merged
ericspod merged 4 commits into
Project-MONAI:devfrom
aymuos15:fix-8237-nnunet-continue-flag
Jul 1, 2026
Merged

ericspod merged 4 commits into
Project-MONAI:devfrom
aymuos15:fix-8237-nnunet-continue-flag

Conversation

@aymuos15

@aymuos15 aymuos15 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #8237 .

Description

The runner passed boolean flags like --c through as --c True, but nnU-Net treats these as store_true flags that take no value, so it errored out with unrecognized arguments: True. Now we emit just the bare flag when it's set, drop it when it isn't, and leave the other args alone.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).

Summary by CodeRabbit

  • Bug Fixes
    • Improved how command-line options are passed for training and validation, so boolean settings now behave as expected.
    • Validation now runs through the standard training workflow with validation enabled, helping ensure more consistent results.

…command

Boolean kwargs such as --c, --val, --use_compressed and
--disable_checkpointing were forwarded as "--c True", which
nnUNetv2_train rejects with "unrecognized arguments: True".
Emit the flag alone when the value is True and omit it when False,
leaving non-boolean args (e.g. -p) unchanged.

Fixes Project-MONAI#8237

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8889d8a5-fba7-4667-8f09-002ae4658796

📥 Commits

Reviewing files that changed from the base of the PR and between ea63acf and d3c93d3.

📒 Files selected for processing (1)
  • monai/apps/nnunet/nnunetv2_runner.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • monai/apps/nnunet/nnunetv2_runner.py

Walkthrough

The pull request updates nnUNetV2Runner so boolean kwargs become CLI flags only when True, are omitted when False, and validation now uses val=True when invoking training.

Changes

nnUNet runner argument handling

Layer / File(s) Summary
Flag emission and validation call
monai/apps/nnunet/nnunetv2_runner.py
Boolean kwargs now render as bare flags only when True, are skipped when False, and validation uses val=True.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: emitting nnUNet store_true flags as bare CLI args in nnUNetV2Runner.
Description check ✅ Passed The PR description matches the template's description and types-of-changes sections; only optional checklist items are left blank.
Linked Issues check ✅ Passed The code change addresses #8237 by emitting boolean flags as bare args, matching nnU-Net's store_true behavior.
Out of Scope Changes check ✅ Passed The validation-call adjustment stays within the same runner flag-handling fix and does not introduce unrelated scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@ericspod

ericspod commented Jul 1, 2026

Copy link
Copy Markdown
Member

Is this an alternative to #8944 or should we merge that one first?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
monai/apps/nnunet/nnunetv2_runner.py (1)

765-765: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use val=True here
validate_single_model() forwards only_run_validation=True, which becomes --only_run_validation on the nnUNetv2_train CLI. That command uses --val for validation-only mode, so this path still passes an unrecognized flag.

🐛 Proposed fix
-        self.train_single_model(config=config, fold=fold, only_run_validation=True, **kwargs)
+        self.train_single_model(config=config, fold=fold, val=True, **kwargs)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@monai/apps/nnunet/nnunetv2_runner.py` at line 765, The validation-only path
in validate_single_model is forwarding the wrong flag through
train_single_model, causing nnUNetv2_train to receive --only_run_validation
instead of the expected validation mode flag. Update the call in
validate_single_model to pass val=True rather than only_run_validation=True, and
ensure the train_single_model / CLI argument mapping uses the val parameter so
validation-only runs invoke the correct nnUNetv2_train option.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@monai/apps/nnunet/nnunetv2_runner.py`:
- Line 765: The validation-only path in validate_single_model is forwarding the
wrong flag through train_single_model, causing nnUNetv2_train to receive
--only_run_validation instead of the expected validation mode flag. Update the
call in validate_single_model to pass val=True rather than
only_run_validation=True, and ensure the train_single_model / CLI argument
mapping uses the val parameter so validation-only runs invoke the correct
nnUNetv2_train option.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 02927779-bfeb-4b26-b032-67292bec7c9f

📥 Commits

Reviewing files that changed from the base of the PR and between 482d1d9 and 559864f.

📒 Files selected for processing (1)
  • monai/apps/nnunet/nnunetv2_runner.py

@aymuos15
aymuos15 force-pushed the fix-8237-nnunet-continue-flag branch from ea63acf to 559864f Compare July 1, 2026 16:12
@aymuos15

aymuos15 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Is this an alternative to #8944 or should we merge that one first?

May you please merge that first? also happy to jsut add this commit onto that.

ericspod and others added 2 commits July 1, 2026 17:23
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
The generic boolean-flag handling supersedes the explicit allowlist
introduced by Project-MONAI#8944, leaving store_true_flags unused.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Comment thread monai/apps/nnunet/nnunetv2_runner.py Outdated
@ericspod
ericspod merged commit d43bf62 into Project-MONAI:dev Jul 1, 2026
21 checks passed
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.

--c Flag for Continuing Training Not Implemented in MONAI nnUNet Runner

2 participants