Skip to content

Fix nnUNet runner store_true flag command construction (#8941) - #8944

Merged
ericspod merged 9 commits into
Project-MONAI:devfrom
aymuos15:fix/8941-nnunet-store-true
Jul 1, 2026
Merged

ericspod merged 9 commits into
Project-MONAI:devfrom
aymuos15:fix/8941-nnunet-store-true

Conversation

@aymuos15

Copy link
Copy Markdown
Contributor

Description

nnUNetV2Runner.train_single_model_command builds the nnUNetv2_train argv by iterating kwargs and always appending str(_value), so documented store_true flags were emitted with a value instead of bare. Passing c=True produced --c True, val=True produced --val True, and likewise for use_compressed and disable_checkpointing. nnUNetv2_train declares these as store_true, so the trailing True is parsed as a positional argument and the command fails. A falsy pretrained_weights was similarly emitted as -pretrained_weights False instead of being omitted.

The builder now appends store_true flags only when their value is truthy and skips them otherwise, and includes pretrained_weights/-p only when given a real path. Regular value kwargs and the existing --npz handling are unchanged.

Fixes #8941, originally flagged in a review thread on #8887.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.

aymuos15 added 2 commits June 24, 2026 04:39
The kwargs loop in train_single_model always appended str(_value), so
documented boolean flags (c, val, use_compressed, disable_checkpointing)
were emitted as '--c True' / '--val True' instead of bare flags, and a
falsy pretrained_weights was passed as '-pretrained_weights False'. Emit
store_true flags only when truthy, and only include pretrained_weights
when a real path is given.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Cover that c/val/use_compressed/disable_checkpointing emit as bare flags
when True and are omitted when False, and that pretrained_weights is only
included for a real path. These fail against the pre-fix argv builder.

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

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f75a7188-2dae-41d8-b0c4-ca9201f865ee

📥 Commits

Reviewing files that changed from the base of the PR and between 189335b and 2031d41.

📒 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

Walkthrough

train_single_model_command now renders selected kwargs as bare flags only when truthy, gates pretrained_weights on truthiness, and leaves other kwargs as --key value. validate_single_model now invokes training with val=True. Tests were added for training and validation command strings, and a new test package init file was added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing nnUNet runner command construction for store_true flags.
Description check ✅ Passed The description covers the bug, the fix, and added tests, and it mostly matches the repository template.
Linked Issues check ✅ Passed The code and tests address #8941 by emitting bare store_true flags, omitting false pretrained_weights, and switching validation to --val.
Out of Scope Changes check ✅ Passed The added test file and nnUNet runner changes are all directly related to the stated fix; no unrelated scope is evident.
✨ 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.

@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.

🧹 Nitpick comments (1)
tests/apps/nnunet/test_nnunetv2_runner_command.py (1)

19-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding a docstring to the helper function.

Path instructions require docstrings for all definitions. While the function name is clear, a brief docstring would improve maintainability.

📝 Suggested docstring
 def _make_runner(export_validation_probabilities=False):
+    """Create a minimal nnUNetV2Runner instance for testing without full initialization."""
     runner = nnUNetV2Runner.__new__(nnUNetV2Runner)

As per path instructions: "Docstrings should be present for all definition which describe each variable, return value, and raised exception in the appropriate section of the Google-style of docstrings."

🤖 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 `@tests/apps/nnunet/test_nnunetv2_runner_command.py` around lines 19 - 24, The
_make_runner helper function is missing a docstring, which violates the
project's path instructions requiring Google-style docstrings for all
definitions. Add a docstring to the _make_runner function that describes what it
does (creates and returns a partially initialized nnUNetV2Runner instance),
documents the export_validation_probabilities parameter and its purpose, and
describes the return value as a nnUNetV2Runner instance with pre-configured
attributes.

Source: Path instructions

🤖 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.

Nitpick comments:
In `@tests/apps/nnunet/test_nnunetv2_runner_command.py`:
- Around line 19-24: The _make_runner helper function is missing a docstring,
which violates the project's path instructions requiring Google-style docstrings
for all definitions. Add a docstring to the _make_runner function that describes
what it does (creates and returns a partially initialized nnUNetV2Runner
instance), documents the export_validation_probabilities parameter and its
purpose, and describes the return value as a nnUNetV2Runner instance with
pre-configured attributes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ad1e0669-0849-4ebb-8ce3-89fd8f2df06b

📥 Commits

Reviewing files that changed from the base of the PR and between 03338b2 and cc51b20.

📒 Files selected for processing (3)
  • monai/apps/nnunet/nnunetv2_runner.py
  • tests/apps/nnunet/__init__.py
  • tests/apps/nnunet/test_nnunetv2_runner_command.py

aymuos15 added 2 commits June 24, 2026 04:57
validate_single_model passed only_run_validation=True, which the command
builder emitted as --only_run_validation True. nnUNetv2_train has no such
flag; the validation-only flag is the store_true --val. Pass val=True so it
routes through the store_true handling and emits a bare --val.

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

aymuos15 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Also fixed the same bug in the validate path: validate_single_model passed only_run_validation=True, which emitted the invalid --only_run_validation True (nnUNetv2_train's validation-only flag is the store_true --val). Now passes val=True, routing through the new handling. Added a regression test for this as well.

@ericspod ericspod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @aymuos15 I had minor comments to make but it looks fine otherwise.

Comment thread monai/apps/nnunet/nnunetv2_runner.py
Comment thread monai/apps/nnunet/nnunetv2_runner.py
aymuos15 added 3 commits June 30, 2026 17:06
The dedicated elif branch for -p/-pretrained_weights makes the prefix
variable redundant: it is only ever '-' in that branch and '--' otherwise.
Inline the literal prefixes for clarity, as suggested in review.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@ericspod
ericspod merged commit 946fd4f into Project-MONAI:dev Jul 1, 2026
21 checks passed
@aymuos15

aymuos15 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you very much!

aymuos15 added a commit to aymuos15/MONAI that referenced this pull request Jul 1, 2026
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>
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.

Flagged nnUNet Runner Command Construction Issue

2 participants