Skip storage check debug assert in view codegen when output is a subclass instance (#122718)

Before the fix, this assert blows up in DEBUG mode for views where the input (base) is a dense tensor and the output (view) is a subclass instance.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/122718
Approved by: https://github.com/soulitzer
This commit is contained in:
Joel Schlosser 2024-03-26 15:07:30 -04:00 committed by PyTorch MergeBot
parent 105381ea11
commit eb5381da66

View File

@ -417,7 +417,8 @@ ENFORCE_SAME_TENSOR_STORAGE = CodeTemplate(
"""\
if (${tensor_name}_storage_saved.has_value() &&
!at::impl::dispatch_mode_enabled() &&
!at::impl::tensor_has_dispatch(${tensor_name}))
!at::impl::tensor_has_dispatch(${tensor_name}) &&
!at::impl::tensor_has_dispatch(${out_tensor_name}))
TORCH_INTERNAL_ASSERT(${tensor_name}_storage_saved.value().is_alias_of(${out_tensor_name}.storage()));
"""
)