찬호의 Too Much Intelligence
torch.is_storage() 본문
torch.is_storage(obj, /)
Returns True if obj is a PyTorch storage object.
import torch
t = torch.tensor([1, 2, 3, 4])
s = t.storage()
print(torch.is_storage(t)) # False
print(torch.is_storage(s)) # True
❓PyTorch에서 storage란?
Pytorch storage object는 Tensor가 실제 데이터를 저장하는 low-level 메모리 버퍼 객체를 말한다.
Pytorch의 Tensor는 데이터를 담는 컨테이너이다.
그런데, Tensor 자체가 데이터를 바로 들고 있는 건 아니고, storage라는 하위 객체를 참조한다.
Tensor
├─ shape (크기)
├─ stride (메모리 배치 방식)
├─ dtype (데이터 타입)
├─ device (CPU/GPU 등)
└─ storage → 실제 데이터 배열이 저장된 버퍼
그래서 하나의 stroage를 여러 tensor가 공유할 수 있다.
import torch
t = torch.tensor([1, 2, 3, 4])
print(type(t)) # <class 'torch.Tensor'>
s = t.storage()
print(s) # [1, 2, 3, 4]
print(type(s)) # <class 'torch.storage._TypedStorage'>'PyTorch Reference API > torch' 카테고리의 다른 글
| torch.is_complex() (0) | 2025.10.21 |
|---|---|
| torch.is_tensor() (0) | 2025.10.21 |