Unverified Commit 6c61887d authored by Min Xu's avatar Min Xu Committed by GitHub
Browse files

[minor] clarify a comment (#673)

- we do have a use case of empty params inside a FSDP -- for the
overlapping fsdp unit test, we use it to measure timing of compute
when no params is needed for all_gather
- therefore, I updated the comment to be more correct there.
- fixes #661
parent 002aae63
...@@ -1317,18 +1317,15 @@ class FullyShardedDataParallel(nn.Module): ...@@ -1317,18 +1317,15 @@ class FullyShardedDataParallel(nn.Module):
if isinstance(m, FullyShardedDataParallel): if isinstance(m, FullyShardedDataParallel):
_remove_shard_bwd_hook(m) _remove_shard_bwd_hook(m)
m._pre_backward_hook_has_run = False m._pre_backward_hook_has_run = False
# Note: m.parameters() should not be an empty list. FSDP
# wrapping modules without weights is not tested at the moment.
if any(p.requires_grad for p in m.parameters()): if any(p.requires_grad for p in m.parameters()):
if m._has_params: if m._has_params:
m.assert_state(TrainingState.BACKWARD_POST) m.assert_state(TrainingState.BACKWARD_POST)
else: else:
m.assert_state(TrainingState.BACKWARD_PRE) m.assert_state(TrainingState.BACKWARD_PRE)
else: else:
# Unlikely case. When m and its children has no params # Unlikely case. When `m` and its children has no params or has params but
# with `requires_grad==True`, then m's pre-backward and # none with `requires_grad==True`, then m's pre-backward and post-backward
# post-backward hooks aren't called by autograd. Therefore, # hooks aren't called by autograd. Therefore, it is in IDLE state.
# it is in IDLE state.
m.assert_state(TrainingState.IDLE) m.assert_state(TrainingState.IDLE)
m.training_state = TrainingState.IDLE m.training_state = TrainingState.IDLE
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment