Fix FSDP2 offload param+adamw8bit
I received below error when use FSDP param offload + Adamw8bits.
[rank3]: File "/usr/local/lib/python3.11/dist-packages/torch/_subclasses/fake_tensor.py", line 2830, in wrap
[rank3]: ) = FakeTensor._find_common_device(func, flat_args)
[rank3]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank3]: File "/usr/local/lib/python3.11/dist-packages/torch/_subclasses/fake_tensor.py", line 941, in _find_common_device
[rank3]: merge_devices(arg)
[rank3]: File "/usr/local/lib/python3.11/dist-packages/torch/_subclasses/fake_tensor.py", line 936, in merge_devices
[rank3]: raise RuntimeError(
[rank3]: torch._dynamo.exc.TorchRuntimeError: Dynamo failed to run FX node with fake tensors: call_function <built-in function mul>(*(FakeTensor(..., device='cuda:3', size=()), DTensor(local_tensor=FakeTensor(..., size=(37984, 2048)), device_mesh=DeviceMesh('cuda', [0, 1, 2, 3], mesh_dim_names=('dp_shard_cp',)), placements=(Shard(dim=0),))), **{}): got RuntimeError('Unhandled FakeTensor Device Propagation for aten.mul.Tensor, found two different devices cuda:3, cpu')
[rank3]: from user code:
[rank3]: File "/usr/local/lib/python3.11/dist-packages/torchao/optim/adam.py", line 183, in single_param_adam
[rank3]: p_f32 = p_f32 - lr * weight_decay * p_f32
[rank3]: Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"
Have confict device between lr(is Tensor) and p_f32.
This PR fix this issue by use inplace multiply, reference from pytorch implementation.
https://github.com/pytorch/pytorch/blob/39c340ec9e2ee3011f1d260f581b5a95f3c99039/torch/optim/adam.py#L345
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3116
- :page_facing_up: Preview Python docs built from this PR
Note: Links to docs will display an error until the docs builds have been completed.
This comment was automatically generated by Dr. CI and updates every 15 minutes.
Hi @nguyen599!
Thank you for your pull request and welcome to our community.
Action Required
In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.
Process
In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.
Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Hi @vkuzo , Can you look into it when you have some time?