The torch.is_storage() method determines whether a given object is a PyTorch storage object. If it is a valid storage, it will return True; otherwise, it will return False.
Storage objects are the underlying data containers that tensors use to store their actual data in memory.

TypedStorage (FloatStorage, IntStorage, etc.) is deprecated and will be removed in future PyTorch versions
Instead of using a tensor.storage() method to create a TypedStorage class, always use the tensor.untyped_storage() method to create the UntypedStorage class because it will be the default method in future PyTorch versions.
Syntax
torch.is_storage(obj)
Parameters
Argument | Description |
obj | It is an object to test. It can be any Python object. |
Basic storage detection
import torch # Create a tensor tensor = torch.tensor([1.0, 2.0, 3.0]) # DEPRECATED: TypedStorage access storage = tensor.storage() # RECOMMENDED: UntypedStorage access (future-proof) untyped_storage = tensor.untyped_storage() print(torch.is_storage(storage)) # Output: True (but deprecated) # UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. # This should only matter to you if you are using storages directly. # To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage() print(torch.is_storage(untyped_storage)) # Output: True (recommended) print(torch.is_storage(tensor)) # Output: False print(torch.is_storage([1, 2, 3])) # Output: False
Empty and Scalar Tensors
What if either a tensor is empty or a scalar tensor? Well, in both cases, the untyped_storage() method will return True.
import torch # Empty tensor empty_tensor = torch.empty(0) # Scalar tensor scalar_tensor = torch.tensor(5.0) # UntypedStorage access empty_untyped = empty_tensor.untyped_storage() print(f"Empty tensor untyped storage: {torch.is_storage(empty_untyped)}") # Output: True scalar_untyped = scalar_tensor.untyped_storage() print(f"Scalar tensor untyped storage: {torch.is_storage(scalar_untyped)}") # Output: TrueThat’s all!