Función torch.cuda.memory_allocated de PyTorch


Pytorch torch 参考手册Manual de referencia de Pytorch torch

torch.cuda.memory_allocatedEs una función en PyTorch utilizada para obtener la memoria de video asignada. Devuelve el tamaño de la memoria asignada por el dispositivo CUDA actual (en bytes).

Definición de la función

torch.cuda.memory_allocated(device=None)

Ejemplo de uso

Ejemplo

import torch

# Verificar la memoria de video asignada
if torch.cuda.is_available():
    print(f"Initial memory: {torch.cuda.memory_allocated()} bytes")

    # Crear tensor
    x = torch.randn(1000, 1000).cuda()
    print(f"After allocation: {torch.cuda.memory_allocated()} bytes")

    # Eliminar tensor
    del x
    print(f"After deletion: {torch.cuda.memory_allocated()} bytes")
else:
    print("CUDA not available")

Pytorch torch 参考手册Manual de referencia de Pytorch torch

Otras extensiones