Pytorch Torch Cuda Memory_Allocated
# PyTorch torch.cuda.memory_allocated Function
* * Pytorch torch Reference](#)
`torch.cuda.memory_allocated` is a function in PyTorch used to get the allocated GPU memory. It returns the size of memory allocated on the current CUDA device (in bytes).
### Function Definition
torch.cuda.memory_allocated(device=None)
* * *
## Usage Example
## Example
import torch
# Check Allocated GPU Memory
if torch.cuda.is_available():
print(f"Initial memory: {torch.cuda.memory_allocated()} bytes")
# Create tensor
x = torch.randn(1000,1000).cuda()
print(f"After allocation: {torch.cuda.memory_allocated()} bytes")
# Delete Tensors
del x
print(f"After deletion: {torch.cuda.memory_allocated()} bytes")
else:
print("CUDA not available")
* * Pytorch torch Reference](#)
YouTip