Skip to content

Add mcore-determinism-debug skill - #7262

Merged
balasaajay merged 2 commits into
NVIDIA:mainfrom
ZhiyuLi-Nvidia:zhiyul/determinism-debug-skills
Oct 30, 2026
Merged

balasaajay merged 2 commits into
NVIDIA:mainfrom
ZhiyuLi-Nvidia:zhiyul/determinism-debug-skills

Conversation

@ZhiyuLi-Nvidia

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Two runs of a deterministic recipe that disagree give one number to work from: the iteration where the loss curves split. That is where the difference grew large enough to print, not where it started. This skill documents the method that answers which op first diverged.

The method: run the job twice, fingerprint every op into a rank-local ordered stream, diff the two streams offline. The first record whose output differs while its inputs matched is the root cause -- everything before it matched byte for byte, so no hypothesis is needed, and forming one before that record is in hand is the most common way these investigations go wrong.

SKILL.md carries the method: the capture ladder (loss curve -> semantic boundaries -> ATen ops -> targeted probe -> below the dispatcher), the multi-arm repro harness, how to read a first divergence, and how to turn a site into a mechanism with a discriminator table.

references/tracing-setup.md covers arming the tracer: the capture layer, the call-site lifecycle, cost controls, read-only-container injection, and the hash function. references/reading-traces.md covers the three ways a correct trace yields a wrong conclusion -- the one-hop-later rule for kernels that bypass the dispatcher, known probe artifacts, and digest semantics.

On hashing, the guidance is to use torch.hash_tensor and not design there: it is far faster than a hand-written position-weighted digest and allocates no measurable scratch, where the custom digest needs three times the input tensor in temporaries. Its one real gap is permutations -- xor over any permutation of 0..n-1 is identically zero, so routing maps and MoE dispatch outputs are invisible when reduced whole-tensor. The fix is granularity, not a different hash: hash_tensor takes dim=, and chunked reduction costs the same as whole-tensor while catching any permutation that crosses a granule.

Benchmark constants are deliberately left out of the docs. They came from one GPU and one torch build; the ordering is the durable result.

  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact @NVIDIA/mcore-oncall.

Issue tracking

For PRs from open-source community contributors:

  • New features: a linked issue is required. Please open a feature request and reference it here before submitting the PR.
  • Small updates (bug fixes, minor improvements): a linked issue is recommended and will accelerate the PR review process.

Linked issue:

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

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

@copy-pr-bot

copy-pr-bot Bot commented Sep 11, 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 marked this pull request as draft September 11, 2026 22:52
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the zhiyul/determinism-debug-skills branch 5 times, most recently from f731fc4 to 45d0bf8 Compare September 11, 2026 23:10
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia marked this pull request as ready for review October 15, 2026 08:18
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team October 15, 2026 08:18
@github-actions github-actions Bot added the docs-only documentation only (docs or docstrings) label Oct 15, 2026
Two runs of a deterministic recipe that disagree give one number to work
from: the iteration where the loss curves split. That is where the
difference grew large enough to print, not where it started. This skill
documents the method that answers which op first diverged.

The method: run the job twice, fingerprint every op into a rank-local
ordered stream, diff the two streams offline. The first record whose
output differs while its inputs matched is the root cause -- everything
before it matched byte for byte, so no hypothesis is needed, and forming
one before that record is in hand is the most common way these
investigations go wrong.

SKILL.md carries the method: the capture ladder (loss curve -> semantic
boundaries -> ATen ops -> targeted probe -> below the dispatcher), the
multi-arm repro harness, how to read a first divergence, and how to turn
a site into a mechanism with a discriminator table.

references/tracing-setup.md covers arming the tracer: the capture layer,
the call-site lifecycle, cost controls, read-only-container injection,
and the hash function. references/reading-traces.md covers the three
ways a correct trace yields a wrong conclusion -- the one-hop-later rule
for kernels that bypass the dispatcher, known probe artifacts, and
digest semantics.

On hashing, the guidance is to use torch.hash_tensor and not design
there: it is far faster than a hand-written position-weighted digest and
allocates no measurable scratch, where the custom digest needs three
times the input tensor in temporaries. Its one real gap is permutations
-- xor over any permutation of 0..n-1 is identically zero, so routing
maps and MoE dispatch outputs are invisible when reduced whole-tensor.
The fix is granularity, not a different hash: hash_tensor takes dim=,
and chunked reduction costs the same as whole-tensor while catching any
permutation that crosses a granule.

Benchmark constants are deliberately left out of the docs. They came
from one GPU and one torch build; the ordering is the durable result.

Signed-off-by: Zhiyu Li <zhiyul@nvidia.com>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the zhiyul/determinism-debug-skills branch from 45d0bf8 to 07f36ac Compare October 22, 2026 21:30
Comment thread skills/mcore-determinism-debug/SKILL.md Outdated
name: mcore-determinism-debug
description: Root-cause method when two Megatron runs that should be bit-identical diverge: fingerprint every op, diff the two traces, first mismatch is the culprit.
license: Apache-2.0
when_to_use: Two identical training runs give different loss; a run is bit-exact at N nodes but not 2N; you need to know which op, layer or kernel first diverged; 'nondeterminism', 'not bit-exact', 'runs diverge', 'determinism trace', 'first divergence', 'which kernel is nondeterministic'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when_to_use is not supported universally. See #7982 for more information.

when_to_use is not part of the agent skills spec; append its contents to
description under a 'Use when' prefix and quote the value so the colon in
the summary stays valid YAML.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Zhiyu Li <zhiyul@nvidia.com>
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test b6dbc8d

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia added this pull request to the merge queue Oct 30, 2026
@nemo-automation-bot

Copy link
Copy Markdown

πŸ”„ Merge queue validation started!

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

@balasaajay
balasaajay removed this pull request from the merge queue due to a manual request Oct 30, 2026
@balasaajay
balasaajay merged commit 902feb8 into NVIDIA:main Oct 30, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-only documentation only (docs or docstrings)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants