Skip to content

Fix elastification unwrap_model import - #4972

Merged
ko3n1g merged 1 commit into
NVIDIA:mainfrom
Devil1716:codex/fix-elastification-unwrap-model-import
May 25, 2026
Merged

Fix elastification unwrap_model import#4972
ko3n1g merged 1 commit into
NVIDIA:mainfrom
Devil1716:codex/fix-elastification-unwrap-model-import

Conversation

@Devil1716

@Devil1716 Devil1716 commented May 25, 2026

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do ?

Fixes the elastification loss function import so tests/unit_tests/elastification/test_loss_func.py can be collected again after unwrap_model stopped being exported from megatron.training.utils.

Issue tracking

Linked issue: Fixes #4971

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Notes

This is a focused import-path fix plus the related test cleanup requested in review. Existing unit coverage already imports megatron.elastification.loss_func in tests/unit_tests/elastification/test_loss_func.py, which is the collection path reported in #4971.

Root cause: megatron.elastification.loss_func imported unwrap_model from megatron.training.utils, but megatron/training/utils/__init__.py no longer exports that symbol. The function is defined in megatron.core.utils, and current callers throughout the repository already import it from there.

The import guard in tests/unit_tests/elastification/test_loss_func.py has also been removed so future import regressions fail during collection instead of being hidden by a module-level skip.

Validation performed locally:

  • python -m py_compile megatron\elastification\loss_func.py tests\unit_tests\elastification\test_loss_func.py
  • rg "pytest\.skip\(|try:|except ImportError|importorskip" tests\unit_tests\elastification\test_loss_func.py -n returned no matches
  • git diff --check

I could not run pytest tests/unit_tests/elastification/test_loss_func.py in this local checkout because the local Python environment is missing pytest and torch. CI should exercise the exact failing collection path.

@copy-pr-bot

copy-pr-bot Bot commented May 25, 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.

@ko3n1g

ko3n1g commented May 25, 2026

Copy link
Copy Markdown
Contributor

/ok to test ea9ee79

@ko3n1g

ko3n1g commented May 25, 2026

Copy link
Copy Markdown
Contributor

/ok to test ea9ee79

@ko3n1g
ko3n1g marked this pull request as ready for review May 25, 2026 14:07
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team May 25, 2026 14:07
@ko3n1g

ko3n1g commented May 25, 2026

Copy link
Copy Markdown
Contributor

@Devil1716 thanks for the contribution! could you remove the import guard with this PR as well? https://github.com/NVIDIA/Megatron-LM/blob/main/tests/unit_tests/elastification/test_loss_func.py#L23

@Devil1716
Devil1716 force-pushed the codex/fix-elastification-unwrap-model-import branch from ea9ee79 to f2d1c07 Compare May 25, 2026 14:54
@Devil1716

Devil1716 commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, done. I removed the module-level import guard from tests/unit_tests/elastification/test_loss_func.py so this path now fails loudly on import regressions instead of being skipped, and force-pushed the updated single-commit branch (f2d1c07).

@ko3n1g

ko3n1g commented May 25, 2026

Copy link
Copy Markdown
Contributor

/ok to test f2d1c07

@ko3n1g
ko3n1g added this pull request to the merge queue May 25, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/26416242210

Merged via the queue into NVIDIA:main with commit 4415119 May 25, 2026
72 of 73 checks passed
santhnm2 pushed a commit to santhnm2/Megatron-LM that referenced this pull request May 26, 2026
Victarry pushed a commit to yanring/Megatron-LM that referenced this pull request May 27, 2026
* origin/main: (50 commits)
  Drain predecessor reduce-scatter at dispatch time (NVIDIA#4940)
  ci: Add allow_failure flag to gpt and moe recipes that are failing in nightlies (NVIDIA#4905)
  fix(tests): initialize num_microbatches calculator in vision cudagraph tests (NVIDIA#4986)
  test: re-enable test_pp2_create_cudagraphs_first_stage on TE 2.15+ (NVIDIA#4985)
  ci: Add support for MBridge job gating based on PR labels  (NVIDIA#4926)
  test(ci): re-enable 8experts2parallel_multi_dist_optimizer_instances_1node (NVIDIA#4984)
  test: re-enable paged stashing MoE tests (NVIDIA#4978)
  Fix elastification unwrap_model import (NVIDIA#4972)
  Avoid offsetting functional test master port (NVIDIA#4973)
  test: enable NVTE_CUTEDSL_FUSED_GROUPED_MLP via pytest fixture (NVIDIA#4931)
  chore(beep boop 🤖): Bump  (main) (2026-05-25)
  test(release): add release goldens for deepseekv3/nemotron3 and set tp2pp2 exit-interval (NVIDIA#4932)
  Fix `get_batch` return order to ignore BlendedDataset provenance fields (NVIDIA#4952)
  ci: restore perf test torchrun logs (NVIDIA#4951)
  Various training utils (NVIDIA#4872)
  ci: Update training script paths in BERT and T5 (NVIDIA#4939)
  [MXFP8/FP4-param-gather] Post processing after forced param AG in eval (NVIDIA#4562)
  Fix mxfp8 param gather numerical issue when DP overlap is off (NVIDIA#4800)
  Add TEFusedDenseMLP for Dense+Grouped GEMM fusion on SM100+ (NVIDIA#4318) (NVIDIA#4786)
  Fix paged stashing test submodules lookup (NVIDIA#4925)
  ...

# Conflicts:
#	megatron/training/training.py
janEbert pushed a commit to janEbert/Megatron-LM that referenced this pull request Jun 2, 2026
mathemakitten pushed a commit to mathemakitten/Megatron-LM that referenced this pull request Jun 12, 2026
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
svcnvidia-nemo-ci pushed a commit to dimapihtar/Megatron-LM that referenced this pull request Aug 4, 2026
Signed-off-by: Dmytro Pykhtar <dpykhtar@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 CI failure: tests/unit_tests/elastification/test_loss_func.py — ImportError on unwrap_model

3 participants