Fix nnUNet runner store_true flag command construction (#8941) by aymuos15 · Pull Request #8944 · Project-MONAI/MONAI · GitHub
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

@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

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