-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix fsdp not freeing forzen full params * add test * formatting * remove unnecessary env var in test Co-authored-by: Liyang90 <[email protected]>
- Loading branch information
1 parent
a1d3651
commit 89574d2
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sys | ||
import torch | ||
import torch.nn as nn | ||
import torch_xla.core.xla_model as xm | ||
import torch_xla.distributed.xla_multiprocessing as xmp | ||
from torch_xla.distributed.fsdp import XlaFullyShardedDataParallel as FSDP | ||
|
||
|
||
def _mp_fn(index): | ||
dev = xm.xla_device() | ||
if xm.xla_device_hw(dev) not in ('TPU', 'GPU'): | ||
print( | ||
'Default device {} is not a TPU or GPU device'.format(dev), | ||
file=sys.stderr) | ||
return | ||
|
||
model = nn.Linear(1024, 1024) | ||
model.weight.requires_grad = False # the weight param is frozen | ||
|
||
model = FSDP(model) # wrapping the linear module with FSDP | ||
|
||
input = torch.rand((2, 1024), device=xm.xla_device()) | ||
|
||
output = model(input) | ||
loss = torch.sum(output) | ||
loss.backward() | ||
assert not any(p._has_full_param for p in model.full_params), \ | ||
'Expecting all the full params to be freed at this moment.' | ||
|
||
|
||
if __name__ == "__main__": | ||
xmp.spawn(_mp_fn, args=()) |
This file contains 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