Skip to content

MegatronRun: support "true"/"false" string convention for bare CLI flags#967

Open
saivishal1999 wants to merge 6 commits into
NVIDIA:mainfrom
saivishal1999:spothula/megatron-run-bool-flag
Open

MegatronRun: support "true"/"false" string convention for bare CLI flags#967
saivishal1999 wants to merge 6 commits into
NVIDIA:mainfrom
saivishal1999:spothula/megatron-run-bool-flag

Conversation

@saivishal1999

@saivishal1999 saivishal1999 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Currently the only way to emit a bare CLI flag in MegatronRun is to set
the parameter to "". This makes it impossible for a DSE search space
to ever disable a boolean flag — there is no value that means "skip this flag."

This PR adds a string convention to MegatronRunCmdArgs.cmd_args:

  • "true" → emits the bare flag (e.g. --mock-data)
  • "false" → skips the flag entirely
  • "" → emits the bare flag (backward compatible, existing TOMLs unchanged)

This allows DSE configs to use ["true", "false"] as a search space to
toggle boolean flags on/off across trials.

Existing TOMLs using = "" continue to work without modification.

…boolean flags

Extend cmd_args property to treat "true" the same as "" (append bare flag)
and skip "false" values entirely. Enables DSE to sweep boolean flags via
["true", "false"] parameter lists in TOML configs.
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

Megatron CLI flags

Layer / File(s) Summary
Encode CLI flag values
src/cloudai/workloads/megatron_run/megatron_run.py
MegatronRunCmdArgs.cmd_args recognizes boolean-style fields and extra keys, omits "false" values, emits "true" and empty values as presence-only flags, preserves other values, and broadens related return annotations.

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

Suggested reviewers: jeffnvidia, srivatsankrishnan, amaslenn, podkidyshev

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: supporting true/false string values for bare CLI flags.
Description check ✅ Passed The description matches the implemented change and explains the new true/false/empty-string behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@saivishal1999 saivishal1999 changed the title Megatron: support "true"/"false" string convention for bare CLI flags MegatronRun: support "true"/"false" string convention for bare CLI flags Jul 13, 2026

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

Actionable comments posted: 2

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

Inline comments:
In `@src/cloudai/workloads/megatron_run/megatron_run.py`:
- Around line 87-92: Restrict the "true"/"false"/empty-string sentinel
conversion in the argument-dumping logic to recognized boolean flags only. For
non-boolean fields such as tensorboard_dir and arbitrary extra arguments,
preserve the literal value unchanged; retain bare-flag behavior for boolean
"true" or empty values and omission for boolean "false".
- Around line 84-92: Add parameterized regression coverage for the
argument-conversion logic that builds flags from args, covering string sentinels
"true" (emits a presence-only flag) and "false" (omits the flag), while also
verifying ordinary values remain unchanged and the existing empty-string
behavior is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 6d23fce5-4452-4e52-935f-30b4d22881d7

📥 Commits

Reviewing files that changed from the base of the PR and between 0de6ca8 and 99d8b28.

📒 Files selected for processing (1)
  • src/cloudai/workloads/megatron_run/megatron_run.py

Comment thread src/cloudai/workloads/megatron_run/megatron_run.py Outdated
Comment thread src/cloudai/workloads/megatron_run/megatron_run.py Outdated

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

Actionable comments posted: 2

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

Inline comments:
In `@src/cloudai/workloads/megatron_run/megatron_run.py`:
- Around line 86-87: Broaden the result annotation in the model serialization
method containing model_dump to reflect preserved native values such as
integers, Path instances, and extra-field values, rather than restricting it to
str or list[str]. Keep the existing model_dump behavior unchanged and ensure the
declared return type covers every value placed into result.

In `@tests/workloads/megatron_run/test_megatron_run.py`:
- Line 28: Update the BASE_ARGS fixture definition to avoid a mutable
class-level dictionary warning: use a dictionary literal and annotate it as
ClassVar, or move the constant to module scope. Preserve the existing
docker_image_url and run_script values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: bb07c6d9-b7f2-4e43-b360-036b6a9c3f14

📥 Commits

Reviewing files that changed from the base of the PR and between 99d8b28 and e1bea1c.

📒 Files selected for processing (2)
  • src/cloudai/workloads/megatron_run/megatron_run.py
  • tests/workloads/megatron_run/test_megatron_run.py

Comment thread src/cloudai/workloads/megatron_run/megatron_run.py Outdated


class TestMegatronRunCmdArgs:
BASE_ARGS = dict(docker_image_url="http://url", run_script=Path(__file__))

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.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid a mutable class-level fixture dictionary.

Ruff flags BASE_ARGS with RUF012, and dict(...) also triggers C408. Use a dictionary literal and annotate it as ClassVar, or move it to module scope.

🧰 Tools
🪛 GitHub Actions: CI / 3_Linting.txt

[error] 28-28: ruff check (pre-commit hook id: ruff-check) failed: RUF012 Mutable class attributes should be annotated with typing.ClassVar.

🪛 GitHub Actions: CI / Linting

[error] 28-28: ruff check failed (RUF012): Mutable class attributes should be annotated with typing.ClassVar. Offending code: BASE_ARGS = dict(...).

🪛 Ruff (0.15.21)

[warning] 28-28: Unnecessary dict() call (rewrite as a literal)

Rewrite as a literal

(C408)


[warning] 28-28: Mutable default value for class attribute

(RUF012)

🤖 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/workloads/megatron_run/test_megatron_run.py` at line 28, Update the
BASE_ARGS fixture definition to avoid a mutable class-level dictionary warning:
use a dictionary literal and annotate it as ClassVar, or move the constant to
module scope. Preserve the existing docker_image_url and run_script values.

Source: Linters/SAST tools

@saivishal1999 saivishal1999 force-pushed the spothula/megatron-run-bool-flag branch from e1bea1c to ed881a8 Compare July 13, 2026 20:41

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

♻️ Duplicate comments (2)
src/cloudai/workloads/megatron_run/megatron_run.py (2)

87-87: ⚠️ Potential issue | 🟡 Minor

Keep the return annotation consistent with preserved native values.

Line [87] restricts result to strings and string lists, but the loop preserves model_dump() values unchanged. Fields such as global_batch_size and log_interval are integers, while path fields return Path objects; extra fields are unconstrained. Broaden the annotation (for example, to dict[str, Any]) or normalize values before returning. This is the same unresolved issue noted in the prior review.

#!/bin/bash
python - <<'PY'
from pathlib import Path
from pydantic import BaseModel

class Sample(BaseModel):
    count: int = 1
    path: Path = Path("/tmp")

dumped = Sample().model_dump()
assert isinstance(dumped["count"], int)
assert isinstance(dumped["path"], Path)
PY
🤖 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 `@src/cloudai/workloads/megatron_run/megatron_run.py` at line 87, Broaden the
return/result annotation in the megatron run flow around the result dictionary
to reflect that model_dump() values are preserved unchanged, including integers,
Path objects, and unconstrained extra fields; use dict[str, Any] or normalize
every value before returning, while keeping the existing native-value behavior.

90-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the unnecessary elif after continue.

Ruff RET507 flags Line [93]. Since Line [92] exits the iteration, use a standalone if:

Proposed change
             if k in bool_flags or k in extra_keys:
                 if v == "false":
                     continue
-                elif v in ("true", ""):
+                if v in ("true", ""):
                     result[flag] = ""
                 else:
                     result[flag] = v
🤖 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 `@src/cloudai/workloads/megatron_run/megatron_run.py` around lines 90 - 96,
Update the flag-processing logic in the visible loop so the condition handling
"false" continues immediately, then evaluate the "true" or empty-value case with
a standalone if instead of an elif. Preserve the existing result[flag]
assignments and behavior for all other values.

Source: Linters/SAST tools

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

Duplicate comments:
In `@src/cloudai/workloads/megatron_run/megatron_run.py`:
- Line 87: Broaden the return/result annotation in the megatron run flow around
the result dictionary to reflect that model_dump() values are preserved
unchanged, including integers, Path objects, and unconstrained extra fields; use
dict[str, Any] or normalize every value before returning, while keeping the
existing native-value behavior.
- Around line 90-96: Update the flag-processing logic in the visible loop so the
condition handling "false" continues immediately, then evaluate the "true" or
empty-value case with a standalone if instead of an elif. Preserve the existing
result[flag] assignments and behavior for all other values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 9c3f6795-1d27-497a-9120-ed9ae3eb98f0

📥 Commits

Reviewing files that changed from the base of the PR and between e1bea1c and ed881a8.

📒 Files selected for processing (1)
  • src/cloudai/workloads/megatron_run/megatron_run.py

…ared return type

model_dump() returns native Python types (int, Path) for typed fields;
converting to str at insertion keeps the dict[str, Union[str, list[str]]]
annotation accurate without cascading changes to the base class.

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

Actionable comments posted: 1

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

Inline comments:
In `@src/cloudai/workloads/megatron_run/megatron_run.py`:
- Around line 96-98: Update the boolean-style flag detection near bool_flags in
the Megatron argument-building logic to explicitly include
recompute_activations, even though its default is None. Ensure the existing
result construction emits a bare --recompute-activations for true and omits the
flag for false, while preserving normal string-value handling for other flags.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: d435f5d8-da7c-4764-8f90-3fabdc2b8d52

📥 Commits

Reviewing files that changed from the base of the PR and between ed881a8 and 3175617.

📒 Files selected for processing (1)
  • src/cloudai/workloads/megatron_run/megatron_run.py

Comment thread src/cloudai/workloads/megatron_run/megatron_run.py Outdated
model_dump() preserves native Python types (int, Path); the prior
Union[str, list[str]] annotation was narrower than what was actually stored.
Existing test_tokenizer_model confirms Path values must be preserved.

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

Actionable comments posted: 1

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

Inline comments:
In `@src/cloudai/workloads/megatron_run/megatron_run.py`:
- Around line 82-85: Update MegatronRunCmdArgs.cmd_args boolean-style flag
detection to explicitly include recompute_activations alongside fields
identified by an empty-string default and model_extra keys. Ensure true emits
the bare --recompute-activations flag and false omits the flag, preserving
existing handling for other arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 2fda69c7-8cb6-4423-aa28-be1bce01f4a0

📥 Commits

Reviewing files that changed from the base of the PR and between 3175617 and defa8b8.

📒 Files selected for processing (1)
  • src/cloudai/workloads/megatron_run/megatron_run.py

Comment thread src/cloudai/workloads/megatron_run/megatron_run.py
default=None keeps it omittable; "true" now emits bare --recompute-activations
and "false" suppresses it, consistent with the bool flag convention.
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.

1 participant