Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSDP] Another fix for DTensor, use_orig_params=True #89845

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions torch/distributed/fsdp/flat_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import torch.nn as nn
import torch.nn.functional as F
from torch import Tensor
from torch.distributed._tensor import DTensor
from torch.distributed.fsdp._common_utils import (
_set_fsdp_flattened,
HandleTrainingState,
Expand Down Expand Up @@ -1291,6 +1292,12 @@ def _use_unsharded_views(self, as_params: bool) -> None:
if hasattr(module, param_name):
delattr(module, param_name)
if self._use_orig_params and as_params:
if type(view) is DTensor:
# A `DTensor` `view` is not compatible with assigning
# `param.data = view`, so we cannot preserve the parameter
# variable.
setattr(module, param_name, nn.Parameter(view))
continue
param = self.flat_param._params[i] # type: ignore[index]
setattr(module, param_name, param)
param.data = view
Expand Down