Skip to content

fix: verify complete Megatron patches before updating installations - #208

Merged
hjh0119 merged 1 commit into
modelscope:mainfrom
FunJim:fix/glm53-patch-installer
Sep 23, 2026
Merged

hjh0119 merged 1 commit into
modelscope:mainfrom
FunJim:fix/glm53-patch-installer

Conversation

@FunJim

@FunJim FunJim commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Problem

The GLM patch installer treats the presence of kda_two_stage_gates in one file as proof that the whole patch is installed. A partially applied or outdated patch can therefore be reported as complete. The bundled diff also contains a Megatron unit-test file that is absent from installed wheels, and a failed application can leave earlier files modified.

Change

  • Verify all selected patch hunks instead of a single marker; add --check and --root.
  • Apply runtime hunks to installed wheels and retain test hunks for Megatron source checkouts. The bundled patch itself is unchanged.
  • Prepare changes in a temporary directory before writing the target. Reject partial installations, missing/symlinked targets and conflicts; restore original contents if publishing fails.
  • Preserve Git three-way merging for source drift using a temporary repository and index. The user's staged changes remain untouched. This intentionally does not impose full-file hashes tied to one commit.
  • Locate Megatron without importing megatron.core.

This remains an environment-preparation tool: run it once in an unused environment, not from training ranks or while another process is editing the installation.

Validation

20 CPU tests passed, using real git and patch executables. Coverage includes partial files/hunks, conflicts, failed application/writeback, symlinks, repeated application, unrelated source edits, three-way merges, index preservation, and wheels nested inside another Git repository.

Two optional integration tests exercised the complete bundled patch against Megatron ee743d3ef228f546287dc3835c2cf56011d5136b: its built wheel and baseline source files in a temporary Git repository. All 11 runtime files / 12 source files matched the patch's expected post-application blob hashes. Set MEGATRON_PATCH_BASE_WHEEL and MEGATRON_PATCH_BASE_SOURCE to enable these tests:

python -m unittest discover -s tests -p test_apply_megatron_patch.py -v

Also built and non-editably installed the bridge wheel with --no-deps, then verified apply/check/repeat against the installed Megatron wheel without importing its native modules. Flake8, isort, YAPF and git diff --check passed for the changed files. No model execution or GPU training was needed; runtime model/optimizer patches are unchanged.

@hjh0119
hjh0119 merged commit cef925c into modelscope:main Sep 23, 2026
1 check passed
FunJim added a commit to FunJim/mcore-bridge that referenced this pull request Sep 23, 2026
Include upstream main through cef925c (PR modelscope#208). Retain the fork's full-file hash installer and matching tests because this branch pins the exact Megatron baseline; upstream intentionally supports source drift and three-way merges. Runtime and tests are identical to GPU-validated b567996. Record the completed single-GPU and initialized CP8 regressions.

Signed-off-by: FunJim <[email protected]>
FunJim added a commit to FunJim/mcore-bridge that referenced this pull request Sep 23, 2026
Use the installer and safety tests merged in ModelScope PR modelscope#208. Keep only the test assertion for the fork's runtime-only patch bundle. Retain all GLM runtime fixes without changes and document hunk verification, source three-way merging, and single-process environment preparation.

Validation: 20 CPU tests passed without skips, including the baseline Megatron wheel and source. Built and non-editably installed the bridge wheel; apply/check/repeat and package discovery passed. All 14 patched file blob hashes match for wheel and source. Flake8, isort, YAPF and diff checks passed.
Signed-off-by: FunJim <[email protected]>
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.

2 participants