Add torch.Tensor._make_wrapper_subclass to torch/_C/__init__.pyi (#154022)

Fixes #153790

Pull Request resolved: https://github.com/pytorch/pytorch/pull/154022
Approved by: https://github.com/Skylion007
This commit is contained in:
Yuanhao Ji
2025-05-27 14:09:55 +00:00
committed by PyTorch MergeBot
parent d88699308f
commit 0a7eef140b
13 changed files with 44 additions and 19 deletions

View File

@ -138,13 +138,14 @@ class SparseSemiStructuredTensor(torch.Tensor):
else:
raise ValueError("At least one of packed or packed_t must be provided")
kwargs = {
"device": previous_tensor.device,
"dtype": previous_tensor.dtype,
"layout": previous_tensor.layout,
"requires_grad": requires_grad,
}
tensor = torch.Tensor._make_wrapper_subclass(cls, shape, **kwargs) # type: ignore[attr-defined]
tensor = torch.Tensor._make_wrapper_subclass(
cls,
shape,
device=previous_tensor.device,
dtype=previous_tensor.dtype,
layout=previous_tensor.layout,
requires_grad=requires_grad,
)
tensor.packed = packed
tensor.meta = meta