Skip to content

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

Open
aymuos15 wants to merge 5 commits into
Project-MONAI:devfrom
aymuos15:fix/8941-nnunet-store-true
Open

Fix nnUNet runner store_true flag command construction (#8941)#8944
aymuos15 wants to merge 5 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: db25b25b-ce1d-460e-a37c-98b70d7f2951

📥 Commits

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

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

📝 Walkthrough

Walkthrough

train_single_model_command in nnunetv2_runner.py now conditionally emits argparse store_true-style flags. Keys c, val, use_compressed, and disable_checkpointing render as bare --<flag> only when truthy and are omitted when falsy. p/pretrained_weights is similarly gated on truthiness. All other kwargs retain the existing --key value form. validate_single_model shifts from only_run_validation=True to val=True, leveraging the new pattern. Comprehensive tests verify both command-construction behaviors.

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 Title accurately describes the main fix: correcting store_true flag command construction in nnUNet runner.
Description check ✅ Passed Description covers the bug, solution, and includes issue reference; however, some non-critical checkboxes are unchecked (integration/quick tests, docstrings).
Linked Issues check ✅ Passed Changes directly address issue #8941: store_true flags now emit as bare flags when True and omit when False, pretrained_weights only included when truthy.
Out of Scope Changes check ✅ Passed All changes are scoped to the nnUNet runner command construction issue and supporting tests; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

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

1 participant