Skip to content

build(docker): bump Megatron-LM 0.12.1 -> 0.13.1 to fix count_zeros wasted work - #375

Merged
shijieliu merged 2 commits into
NVIDIA:mainfrom
JacoCheung:junzhang/mcore-version-bump
May 12, 2026
Merged

shijieliu merged 2 commits into
NVIDIA:mainfrom
JacoCheung:junzhang/mcore-version-bump

Conversation

@JacoCheung

@JacoCheung JacoCheung commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Bumps Megatron-LM in docker/Dockerfile from core_v0.12.1 to core_v0.13.1.
  • 0.12.x line ships a ChainedOptimizer.step() that calls self.count_zeros() unconditionally; on HSTU bf16 (single inner Float16Optimizer) this triggers count_zeros_fp32's Python-per-param loop every step (~360 CUDA kernel launches, ~4 ms wall) even though log_num_zeros_in_grad=False and the result is discarded.
  • Megatron commit d9608004f ("Add an option to skip counting zeros in grad of ChainedOptimizer") gates the call. First release tag containing it is core_v0.13.0; this PR pins core_v0.13.1 (latest 0.13.x patch).

The fix is bit-exact (no parameter math change; log_num_zeros_in_grad=False means the count was already going into a return slot nobody reads).

Test plan

  • /build devel to build new devel_latest with bumped Megatron pin
  • Submit 2-node nsys profile on EOS with the new image, confirm count_zeros_fp32 is gone from ## optimizer step ## NVTX
  • Confirm step time / MFU regression-free vs 0.12.1 baseline outside the optimizer phase
  • CI green

🤖 Generated with Claude Code

@JacoCheung

Copy link
Copy Markdown
Collaborator Author

/build devel

@greptile-apps

greptile-apps Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Bumps the Megatron-LM clone tag in docker/Dockerfile from core_v0.12.1 to core_v0.13.1 to pick up upstream commit d9608004f, which gates ChainedOptimizer.count_zeros behind log_num_zeros_in_grad. No source files in this repo change.

  • Performance fix: the 0.12.x ChainedOptimizer.step() called count_zeros_fp32 unconditionally, launching ~360 CUDA kernels (~4 ms) every optimizer step on HSTU bf16 even when the statistic was discarded; 0.13.1 eliminates that overhead when the flag is False.
  • Bit-exact training: the fix only gates a diagnostic counter — no parameter math, loss scaling, or optimizer state changes.

Confidence Score: 5/5

Safe to merge — the change is a single-tag bump in the Dockerfile with no source code modifications in this repository.

The diff touches exactly one line: the Megatron-LM git tag. Megatron is installed with --no-deps -e, so its transitive dependencies do not interfere with the rest of the layer stack. The upstream fix is a diagnostic gate only — no optimizer math, no weight or state changes — so training results remain bit-exact. Inline comments accurately document the commit and rationale.

No files require special attention.

Important Files Changed

Filename Overview
docker/Dockerfile Single-line bump of Megatron-LM git tag from core_v0.12.1 to core_v0.13.1, with detailed inline comments explaining the performance motivation; no other dependencies or build steps are affected.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["FROM nvcr.io/nvidia/pytorch:26.02-py3\n(BASE_IMAGE)"] --> B["Layer 1: System setup\napt deps, arch symlinks"]
    B --> C["Layer 2: pip deps + Megatron-LM\ngit clone -b core_v0.13.1 ← bumped\npip install --no-deps -e megatron-lm"]
    C --> D["Layer 3: FBGEMM v1.5.0\n(long build, own layer)"]
    D --> E["Layer 4: TorchRec V1.5.0"]
    E --> F["flash-attention arbitrary_mask"]
    F --> G["fbgemm_gpu_hstu (from submodule)"]
    G --> H["FROM devel AS build\nCopy repo + compile corelib/dynamicemb"]
    style C fill:#d4edda,stroke:#28a745
Loading

Reviews (3): Last reviewed commit: "Merge branch 'main' into junzhang/mcore-..." | Re-trigger Greptile

Comment thread docker/Dockerfile Resolved
@JacoCheung

JacoCheung commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

❌ Pipeline #49886692 -- failed

Job Status Log
build_inference_devel ❌ failed view
build_tritonserver_devel ❌ failed view
pre_check ❌ failed view
train_build ✅ success view
inference_build ✅ success view
tritonserver_build ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ❌ failed view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_h100 ❌ failed view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ❌ failed view
build_devel ✅ success view
unit_test_1gpu_a100 ❌ failed view

Result: 8/17 jobs passed

View full pipeline

@JacoCheung

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

❌ Pipeline #49911823 -- failed

Job Status Log
build_devel ❌ failed view
build_inference_devel ❌ failed view
build_tritonserver_devel ❌ failed view
pre_check ❌ failed view
train_build ❌ failed view
inference_build ✅ success view
tritonserver_build ✅ success view
build_whl ❌ failed view
dynamicemb_test_fwd_bwd_8gpus ❌ failed view
dynamicemb_test_load_dump_8gpus ❌ failed view
unit_test_1gpu_a100 ❌ failed view
unit_test_1gpu_h100 ❌ failed view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ❌ failed view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ❌ failed view

Result: 3/17 jobs passed

View full pipeline

@JacoCheung

Copy link
Copy Markdown
Collaborator Author

/build

@JacoCheung

JacoCheung commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

❌ Pipeline #50621233 -- failed

Job Status Log
build_devel ❌ failed view
build_inference_devel ❌ failed view
build_tritonserver_devel ❌ failed view
pre_check ❌ failed view
train_build ❌ failed view
inference_build ✅ success view
tritonserver_build ✅ success view
build_whl ❌ failed view
dynamicemb_test_fwd_bwd_8gpus ❌ failed view
dynamicemb_test_load_dump_8gpus ❌ failed view
unit_test_1gpu_a100 ❌ failed view
unit_test_1gpu_h100 ❌ failed view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ❌ failed view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ❌ failed view

Result: 3/17 jobs passed

View full pipeline

@JacoCheung

Copy link
Copy Markdown
Collaborator Author

/build devel

@JacoCheung

JacoCheung commented May 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

❌ Pipeline #50631678 -- failed

Job Status Log
build_devel ✅ success view
build_inference_devel ❌ failed view
build_tritonserver_devel ❌ failed view
pre_check ❌ failed view
train_build ❌ failed view
inference_build ❌ failed view
tritonserver_build ❌ failed view
build_whl ❌ failed view
dynamicemb_test_fwd_bwd_8gpus ❌ failed view
dynamicemb_test_load_dump_8gpus ❌ failed view
unit_test_1gpu_a100 ❌ failed view
unit_test_1gpu_h100 ❌ failed view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ❌ failed view
inference_unit_test_1gpu ❌ failed view
inference_test_1gpu ❌ failed view

Result: 1/17 jobs passed

View full pipeline

core_v0.12.1 ships a ChainedOptimizer.step() that calls
self.count_zeros() unconditionally. count_zeros_fp32 then Python-loops
over every dense parameter doing grad.numel() - torch.count_nonzero(grad)
(5 CUDA kernels per param, ~360 launches per step on HSTU bf16) even
when log_num_zeros_in_grad is False and the result is discarded.

Megatron-LM commit d9608004f ("Add an option to skip counting zeros
in grad of ChainedOptimizer", 2025-06-04) added the missing
log_num_zeros_in_grad gate at the call site. Earliest tag containing
the fix is core_v0.13.0; using core_v0.13.1 (latest 0.13.x patch) for
stability.

Expected effect after the bump (no source changes in this repo): the
~4 ms / step count_zeros loop in ## optimizer step ## NVTX disappears
because HSTU never sets log_num_zeros_in_grad, so step() short-circuits
to None.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@JacoCheung
JacoCheung force-pushed the junzhang/mcore-version-bump branch from 2415d20 to e3302f4 Compare May 11, 2026 05:44
@JacoCheung

Copy link
Copy Markdown
Collaborator Author

/build devel

@JacoCheung

JacoCheung commented May 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

❌ Pipeline #50985229 -- failed

Job Status Log
build_devel ❌ failed view
build_inference_devel ❌ failed view
build_tritonserver_devel ❌ failed view
pre_check ❌ failed view
train_build ❌ failed view
inference_build ❌ failed view
tritonserver_build ❌ failed view
build_whl ❌ failed view
dynamicemb_test_fwd_bwd_8gpus ❌ failed view
dynamicemb_test_load_dump_8gpus ❌ failed view
unit_test_1gpu_a100 ❌ failed view
unit_test_1gpu_h100 ❌ failed view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ❌ failed view
inference_unit_test_1gpu ❌ failed view
inference_test_1gpu ❌ failed view

Result: 0/17 jobs passed

View full pipeline

@JacoCheung
JacoCheung requested a review from shijieliu May 12, 2026 01:51
@shijieliu
shijieliu merged commit 1782d6d into NVIDIA:main May 12, 2026
@JacoCheung
JacoCheung deleted the junzhang/mcore-version-bump branch May 22, 2026 05:06
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