Skip to content

fix: Preserve quant worker hook overrides during fp8 setup - #2803

Merged
yuki-97 merged 4 commits into
mainfrom
mxin/fix-forward-hook
Jun 13, 2026
Merged

yuki-97 merged 4 commits into
mainfrom
mxin/fix-forward-hook

Conversation

@mxinO

@mxinO mxinO commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Fix the issue by #2633, The fp8_params initialization path disabled Megatron DDP forward pre-hooks by calling the raw DDP method directly. ModelOpt quant workers already override the worker-level hook toggles to hide TensorQuantizer modules from DDP module iteration, so the raw call bypassed that protection and exposed TensorQuantizer(disabled) entries that had no registered hook handle.

We didn't have any QARL test in CI Lfast, I moved the small QA-distill to fast, so people won't miss QARL things next time.

Issues

closes #2805

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

The fp8_params initialization path disabled Megatron DDP forward pre-hooks by calling the raw DDP method directly. ModelOpt quant workers already override the worker-level hook toggles to hide TensorQuantizer modules from DDP module iteration, so the raw call bypassed that protection and exposed TensorQuantizer(disabled) entries that had no registered hook handle.

Constraint: Megatron DDP assumes every current module has a forward-pre-hook handle when disabling overlap-param-gather hooks.\nRejected: Special-case TensorQuantizer in the base worker | the quant worker already owns that behavior through its override.\nConfidence: high\nScope-risk: narrow\nDirective: Forward-pre-hook toggles in helper paths should dispatch through worker methods so subclasses can preserve their invariants.\nTested: ruff format --check and ruff check on touched files; python -m py_compile on touched files; Slurm container pytest tests/unit/models/policy/test_megatron_worker.py -k forward_pre_hook --mcore-only passed in job 214815.\nNot-tested: Full tests/functional/qa_distillation_megatron.sh in this container; current smoke container lacked some Megatron runtime deps for direct full-module unit imports.
Signed-off-by: Meng Xin <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@mxinO mxinO changed the title Preserve quant worker hook overrides during fp8 setup fix: Preserve quant worker hook overrides during fp8 setup Jun 13, 2026
@mxinO mxinO added the CI:L1 Run doctests, unit tests, and functional tests label Jun 13, 2026
The initial regression guard only inspected the source shape. Execute the actual helper body from the production file inside a lightweight fake worker so the test fails on the original raw-DDP bypass and also verifies the worker-level hook override receives param_sync=False.

Constraint: Importing the full Megatron worker in lightweight unit environments can require heavy Megatron-Bridge and Transformer Engine dependencies.\nRejected: Full quant-worker integration unit | too heavyweight for the narrow regression and already covered by functional QARL smoke surfaces.\nConfidence: high\nScope-risk: narrow\nDirective: Keep this test focused on dispatch behavior; broader quant hook integration belongs in functional tests.\nTested: ruff format --check and ruff check on touched files; python -m py_compile on touched files; Slurm container pytest tests/unit/models/policy/test_megatron_worker.py -k forward_pre_hook --mcore-only passed in job 214818.\nRelated: Reviewer re-check approved after replacing structural-only assertion with behavioral source-execution test.
Signed-off-by: Meng Xin <[email protected]>
The QARL distillation functional test uses Qwen3-0.6B on two GPUs for one training step plus quantized HF export. That makes it comparable to the existing fast Megatron checks while covering the quantized distillation path that exposed the TensorQuantizer forward-hook regression.

Constraint: This is the only functional coverage for the quantized QA distillation path that hit the forward-hook regression.\nConfidence: high\nScope-risk: narrow\nTested: bash -n tests/functional/L1_Functional_Tests_Megatron_3.sh tests/functional/qa_distillation_megatron.sh\nTested: Slurm qa_distillation_megatron.sh job 214980 completed with train/loss=0.1924101710319519 and HF export PASS\nNot-tested: Full CI matrix
Signed-off-by: Meng Xin <[email protected]>
@mxinO mxinO added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Jun 13, 2026
@mxinO

mxinO commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@mxinO
mxinO marked this pull request as ready for review June 13, 2026 07:59
@mxinO
mxinO requested review from a team as code owners June 13, 2026 07:59
@copy-pr-bot

copy-pr-bot Bot commented Jun 13, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@mxinO

mxinO commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for the fix!

@yuki-97
yuki-97 merged commit e8d55b9 into main Jun 13, 2026
81 checks passed
@yuki-97
yuki-97 deleted the mxin/fix-forward-hook branch June 13, 2026 12:28
copy-pr-bot Bot pushed a commit that referenced this pull request Jun 14, 2026
copy-pr-bot Bot pushed a commit that referenced this pull request Jun 15, 2026
ashors1 pushed a commit that referenced this pull request Jun 27, 2026

This branch was previously deployed

2 inactive deployments
public — 471bb700 Deployed Jun 13, 2026 by copy-pr-bot[bot] via release / finalize / publish-docs #1071
test — 471bb700 Deployed Jun 13, 2026 by copy-pr-bot[bot] via Wait in test approval queue #12328
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/functional/qa_distillation_megatron.sh fails on main

2 participants