avoid allocation when tensor_new from storage (#149797)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/149797
Approved by: https://github.com/Skylion007
This commit is contained in:
Yuxin Wu 2025-03-24 20:02:45 +00:00 committed by PyTorch MergeBot
parent 112f983056
commit 40ec9d2bfa

View File

@ -417,7 +417,7 @@ Tensor internal_new_from_data(
" or an UntypedStorage, but got ",
storage_scalar_type);
tensor = at::empty(
sizes,
{0}, // sizes. Storage will be set later.
at::initialTensorOptions()
.dtype(
is_typed_storage ? storage_scalar_type