Skip to content

test(ckpt): isolate conversion launcher utility imports#5003

Merged
yaoyu-33 merged 1 commit into
mainfrom
yuya/fix-main-utils-import
Jul 22, 2026
Merged

test(ckpt): isolate conversion launcher utility imports#5003
yaoyu-33 merged 1 commit into
mainfrom
yuya/fix-main-utils-import

Conversation

@yaoyu-33

Copy link
Copy Markdown
Contributor

What does this PR do ?

Fix the main-branch core unit-test failure caused by the conversion launcher test leaking its top-level utils module into the shared pytest process.

Changelog

  • Save and remove any pre-existing utils module before dynamically loading scripts/conversion/run_conversion.py.
  • Restore the exact previous module state after the dynamic import completes.
  • Add a regression test proving a pre-existing same-name module is preserved.

Root Cause

PR #4909 added from utils import resolve_hf_commit_revision, resolve_hf_model_revision to scripts/conversion/run_conversion.py. The unit-test loader prepends scripts/conversion to sys.path, so that import caches scripts/conversion/utils.py as the top-level module utils. The loader restored its other temporary modules but not utils. Later, test_override_precedence.py imported utils.utils and utils.overrides from scripts/performance; Python reused the leaked plain module and raised ModuleNotFoundError: 'utils' is not a package for 15 tests.

Failing main run: https://github.com/NVIDIA-NeMo/Megatron-Bridge/actions/runs/29876906382/job/88790258314

GitHub Actions CI

Focused validation:

  • test_run_conversion.py: 9 passed in a lightweight isolated environment.
  • uvx pre-commit run --all-files: all hooks passed.
  • Ruff lint, Ruff format check, and git diff --check: passed.

uv run pre-commit run --all-files cannot resolve the complete project environment on macOS ARM because nvidia-resiliency-ext==0.6.0 only publishes Linux wheels; the same repository hooks were therefore run with uvx pre-commit.

Before your PR is "Ready for review"

Pre checks:

  • Read and followed the contributor guidelines.
  • Added a focused regression test.
  • Documentation is not required for this test-isolation fix.
  • Optional-install components are unaffected.

Additional Information

Signed-off-by: yaoyu-33 <yaoyu.094@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 22, 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.

@yaoyu-33 yaoyu-33 added bug Something isn't working area:ckpt Checkpoint conversion, loading, export, and save paths needs-review PR is ready for code review and waiting on a reviewer labels Jul 22, 2026
@claude

claude Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

LGTM

Test-only change hardening the _load_run_conversion_module loader and its coverage. The loader now tracks utils in previous_modules and pops any preexisting utils before loading run_conversion.py (which does a top-level import of utils), so the real scripts/conversion/utils.py loads fresh and any global utils module is restored afterward. The new test_loader_restores_preexisting_utils_module correctly exercises the restore path: it installs a sentinel utils, runs the loader, and asserts restoration. This would have failed before the fix since utils was not previously tracked.

No bugs, typos, or doc gaps found.

Suggested test cases:

  • test_loader_restores_preexisting_utils_module
  • test_cpu_import_dispatches_to_cpu_backend
  • test_gpu_import_dispatches_to_gpu_backend

Run the full test_run_conversion.py module to confirm the utils pop/restore does not regress the CPU/GPU dispatch tests.

No perf tests impacted.

@yaoyu-33
yaoyu-33 merged commit c0a200f into main Jul 22, 2026
7 checks passed
@yaoyu-33
yaoyu-33 deleted the yuya/fix-main-utils-import branch July 22, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ckpt Checkpoint conversion, loading, export, and save paths bug Something isn't working needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant