Fix distributed amax error handling#1944
Conversation
|
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. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a CPU-and-NCCL guard in ChangesCPU/NCCL amax sync guard
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
|
BB: Approved; make this a regular PR |
🐝 Approved—I'll mark this PR ready for review now. |
Done — PR #1944 is now a regular, ready-for-review PR. GitHub confirms it remains open and mergeable at |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
modelopt/torch/quantization/nn/modules/tensor_quantizer.py (1)
1350-1362: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGuard correctly narrows error handling to the CPU+NCCL case; consider rank-aware warning.
The explicit CPU+NCCL check replacing the blanket
try/except RuntimeErroris a solid fix — genuinedist.all_reduceerrors for other backends/cases now propagate instead of being silently swallowed as warnings, matching the PR's intent and the accompanying test.One nit: since this runs identically on every rank in the group,
warnings.warnwill fire redundantly on all ranks. Coding guidelines call for rank-aware logging in distributed code paths to avoid noisy duplicate output.♻️ Suggested tweak (if a rank-aware warn helper exists in the codebase)
- warnings.warn( + warn_rank_0( "Failed to synchronize amax because the tensor is on CPU, but NCCL only supports CUDA " "tensors. This warning can be ignored if happening during modelopt restore." )As per coding guidelines, "Develop with distributed processing in mind: use
print_rank_0orwarn_rank_0when possible and guard shared side effects against race conditions between ranks." Please confirm whether such a helper exists inmodelopt.torch.utilsbefore applying.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@modelopt/torch/quantization/nn/modules/tensor_quantizer.py` around lines 1350 - 1362, The CPU+NCCL warning in sync_amax_across_distributed_group is emitted on every rank, causing duplicate distributed logs. Update the warning path to use a rank-aware helper such as warn_rank_0 or print_rank_0 if it exists in modelopt.torch.utils, and keep the warning only for the CPU+NCCL branch while preserving the current all_reduce behavior for valid cases.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@modelopt/torch/quantization/nn/modules/tensor_quantizer.py`:
- Around line 1350-1362: The CPU+NCCL warning in
sync_amax_across_distributed_group is emitted on every rank, causing duplicate
distributed logs. Update the warning path to use a rank-aware helper such as
warn_rank_0 or print_rank_0 if it exists in modelopt.torch.utils, and keep the
warning only for the CPU+NCCL branch while preserving the current all_reduce
behavior for valid cases.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 89f4e79c-a26b-43cd-85aa-7c7dc8f16f7e
📒 Files selected for processing (2)
modelopt/torch/quantization/nn/modules/tensor_quantizer.pytests/gpu/torch/quantization/test_tensor_quantizer_cuda.py
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1944 +/- ##
==========================================
- Coverage 77.79% 77.16% -0.64%
==========================================
Files 519 519
Lines 57928 57928
==========================================
- Hits 45067 44699 -368
- Misses 12861 13229 +368
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/claude review |
73e88e4 to
1abccc8
Compare
There was a problem hiding this comment.
Claude review passed — no blocking issues found. LGTM
Scope: Reviewed the 2 files actually in this PR (modelopt/torch/quantization/nn/modules/tensor_quantizer.py, tests/gpu/torch/quantization/test_tensor_quantizer_cuda.py). Note: a stale shallow local base surfaced unrelated transformer_engine.py hunks in the raw diff; those are base drift (real base 2d4e472), not part of this PR, and were excluded.
Assessment (low risk):
- The core change narrows a blanket
try/except RuntimeErrorarounddist.all_reduceto an explicit CPU-amax + NCCL-backend pre-check that warns and returns early, letting genuine collective failures (e.g. NCCL OOM) propagate instead of being silently downgraded to warnings. This matches the stated intent. - Correctness checks pass:
dist.get_backend(...) == dist.Backend.NCCLis valid (Backendis astrsubclass),get_backendis safely gated behindis_initialized(), and the early-return leaves_amaxunsynchronized — consistent with the prior behavior and the new test's assertions. - No mode/state, export, or backward-compatibility surface is touched; the method signature and
modelopt_stateschema are unchanged. - The new 2-GPU NCCL test is well-placed and correctly validates the warning, the CPU device, and the per-rank amax value.
Findings — CRITICAL: 0, IMPORTANT: 0, SUGGESTION: 0 (new). CodeRabbit already raised the rank-aware warn_rank_0 nit (non-blocking); not duplicating it here.
4112850 to
0a82a7a
Compare
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
Signed-off-by: realAsma <akuriparambi@nvidia.com>
0a82a7a to
c4db72d
Compare
Description
TensorQuantizer.sync_amax_across_distributed_groupcurrently catches everyRuntimeErrorfromdist.all_reduceand converts it to a warning. This can mask failures such as NCCL OOMs, allowing ranks to diverge and hang in later collectives.This PR handles only the intended unsupported-device case before entering the collective:
Tests
pytest_pwd tests/unit/torch/quantization/test_dist.py -qpre-commit run --files modelopt/torch/quantization/nn/modules/tensor_quantizer.py tests/unit/torch/quantization/test_dist.pySummary by CodeRabbit
Bug Fixes
Tests