Fix FusedAdam empty tensor handling#3212
Open
wujingyue wants to merge 1 commit into
Open
Conversation
Contributor
Greptile SummaryThis PR fixes empty tensor handling in fused optimizer multi-tensor launches. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (3): Last reviewed commit: "Fix FusedAdam empty tensor handling" | Re-trigger Greptile |
wujingyue
force-pushed
the
agent/fix-fusedadam-empty-param
branch
from
July 15, 2026 01:20
2306b6e to
0b4b00b
Compare
Signed-off-by: Jingyue Wu <wujingyue@gmail.com>
wujingyue
force-pushed
the
agent/fix-fusedadam-empty-param
branch
from
July 15, 2026 02:37
0b4b00b to
69337e7
Compare
wujingyue
commented
Jul 15, 2026
| from torch.distributed._tensor import DTensor | ||
|
|
||
|
|
||
| def filter_empty_tensor_lists(tensor_lists): |
Contributor
Author
There was a problem hiding this comment.
Should we call this from MultiTensorApply unconditionally? I'm not sure whether filtering is safe for every optimizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
multi_tensor_applymulti_tensor_applycheck so zero-chunk tensors fail with a clear error if they reach the launcherRoot cause
multi_tensor_applydrives launch bookkeeping from the per-tensor chunk loop. A zero-sized tensor has zero chunks, so if an empty tensor appears at the end of a group, pending work for earlier tensors can remain unlaunched and FusedAdam silently skips the update.The generic
MultiTensorApplywrapper still preserves caller-visible slot semantics. Adam and SGD opt into filtering because empty tensor slots are no-op optimizer updates.Fixes #3207
Validation
NVTE_FRAMEWORK=pytorch NVTE_CUDA_ARCHS=86 NVTE_WITH_NCCL_EP=0 NVTE_SKIP_SUBMODULE_CHECKS_DURING_BUILD=1 MAX_JOBS=4 NVTE_BUILD_THREADS_PER_JOB=1 python setup.py build_ext --inplacepython -m py_compile transformer_engine/pytorch/optimizers/fused_adam.py transformer_engine/pytorch/optimizers/fused_sgd.py transformer_engine/pytorch/optimizers/multi_tensor_apply.pyPYTHONPATH=/tmp/TransformerEngine pytest -q tests/pytorch/test_fused_optimizer.py::TestFusedAdam::test_empty_param_at_end_of_group tests/pytorch/test_fused_optimizer.py::TestFusedSGD::test_empty_param_at_end_of_groupte.optimizers.FusedAdamandte.optimizers.FusedSGD: both completedstep()andtorch.cuda.synchronize()te 0.0009999871253967285,torch 0.0009999871253967285git diff --check