Skip to content

test(converters): add CLI entry-point coverage for all three converte…#2666

Open
SakethKoona wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
SakethKoona:test/converter-cli-entry-points
Open

test(converters): add CLI entry-point coverage for all three converte…#2666
SakethKoona wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
SakethKoona:test/converter-cli-entry-points

Conversation

@SakethKoona

@SakethKoona SakethKoona commented Jun 2, 2026

Copy link
Copy Markdown

What does this PR do?

test_converter_roundtrip.py previously tested the converter library functions directly but never exercised the parse_args() + main() entry points of the three scripts in examples/converters/. This PR adds shell-driven CLI tests that invoke each script as a subprocess (exactly as a user would), covering logic branches that were entirely untested: config.yaml reading, tokenizer path fallback, --hf-model-name override, --adapter-only dispatch, and hf_overrides extraction.

Issues

Addresses #2259

Changes

  • Extract eight shared helper functions from test_converter_roundtrip.py into a new converter_test_utils.py module, plus one new write_config_yaml helper. This avoids duplicating
    checkpoint-creation and assertion logic between the existing roundtrip test and the new CLI tests.
  • Add four new scripts:
    • _cli_test_setup.py — creates DCP, Megatron, and LoRA checkpoints and writes paths to a shell-sourceable paths.env file
    • _cli_test_verify_dcp.py — verifies convert_dcp_to_hf.py CLI output matches original HF weights
    • _cli_test_verify_meg.py — verifies convert_megatron_to_hf.py CLI output matches original HF weights
    • _cli_test_verify_lora_merge.py — verifies convert_lora_to_hf.py merge output has correct structure and that LoRA weights were applied
  • Expand test_converters.sh with a second block that drives all five CLI invocations and calls the verify scripts. Block 1 (existing roundtrip test) is untouched.

Pre checks

  • Read and followed contributor guidelines
  • New tests written — this PR is the tests
  • Unit and functional tests run locally (requires GPU; covered by CI)
  • No documentation changes needed — this is a test-only change

Additional Information

test_converters.sh now runs two blocks back-to-back. Block 1 is the existing library-level roundtrip test; Block 2 is the new CLI entry-point tests. Both require at least one GPU. The two
blocks create independent checkpoints in separate temp directories and clean up after themselves via trap cleanup EXIT.

…r scripts

Extract shared helpers from test_converter_roundtrip.py into
converter_test_utils.py so the setup and verify scripts used by the
shell-driven CLI tests can reuse checkpoint creation and assertion
logic without duplication.

Add _cli_test_setup.py, _cli_test_verify_dcp.py,
_cli_test_verify_meg.py, and _cli_test_verify_lora_merge.py to drive
and verify each converter CLI end-to-end.

Expand test_converters.sh with a second block that invokes all three
converter scripts (five invocations total) via subprocess, covering
parse_args()+main() paths that were previously untested: config.yaml
reading, tokenizer fallback branch, --hf-model-name override,
--adapter-only dispatch, and hf_overrides extraction.

Signed-off-by: Saketh <koona.saketh@gmail.com>
@SakethKoona SakethKoona requested a review from a team as a code owner June 2, 2026 03:13
@copy-pr-bot

copy-pr-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Jun 4, 2026

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

@SakethKoona thanks so much for supporting this! overall LGTM and left some minor comments.

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.

maybe rename to _converter_test_setup to make it clear?

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.

do you mind merging the three verify files to one _converter_test_verify.py, and use input args to control what to verify?

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.

nit: what about rename to _converter_test_utils.py?

write_config_yaml,
)

tmp, model = sys.argv[1], sys.argv[2]

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.

nit:

Suggested change
tmp, model = sys.argv[1], sys.argv[2]
tmp_path, model = sys.argv[1], sys.argv[2]


# create_megatron_checkpoint returns the iter_0000000 subdirectory path,
# which is what --megatron-ckpt-path and --base-ckpt both expect.
meg_path = create_megatron_checkpoint(model, tmp)

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.

nit: wdyt changing all the meg to megatron?

Suggested change
meg_path = create_megatron_checkpoint(model, tmp)
megatron_path = create_megatron_checkpoint(model, tmp)


tmp, model = sys.argv[1], sys.argv[2]

config = create_test_config()

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.

we've hardcode model_name in create_test_config, could you make it a input args instead of hardcode?
so that the script is still fine if we change test model in tests/functional/test_converters.sh.

Suggested change
config = create_test_config()
config = create_test_config(model)

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants