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

empty tensor moving to default device #2948

Merged
merged 2 commits into from
Jun 28, 2024
Merged
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: 6 additions & 1 deletion py/torch_tensorrt/dynamo/lowering/_decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def empty_permuted_decomposition(*args, **kwargs) -> torch.Tensor:
perm = [0] * len(empty_size)
for permute_index, permute_element in enumerate(empty_permute):
perm[permute_element] = permute_index
default_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the default device defined in our _defaults.py : https://github.com/pytorch/TensorRT/blob/main/py/torch_tensorrt/dynamo/_defaults.py#L37
and convert this into a torch device via _enums.to()

kwargs["device"] = default_device
return torch.empty([empty_size[l] for l in empty_permute], **kwargs).permute(perm)


Expand Down Expand Up @@ -233,7 +235,10 @@ def select_scatter_decomposition(
def empty_strided_decomposition(*args, **kwargs) -> torch.Tensor:
empty_size = args[0]
empty_stride = args[1]
return torch.as_strided(torch.empty(empty_size), empty_size, empty_stride)
default_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

return torch.as_strided(
torch.empty(empty_size, device=default_device), empty_size, empty_stride
)


def get_decompositions(
Expand Down
Loading