모든 tensor 가 세 조각의 정체성을 들고 있어
print(t) 하면 PyTorch 는 값을 보여줘. 뭔가 깨지면 값은 거의 안 중요해 — metadata 가 중요해. 디버깅 중요도 순서로 세 attribute:
- shape — 차원. 어떤 에러든 첫 체크.
- dtype — element type. 두 번째 체크, 특히 mixed-precision training.
- device — data 가 물리적으로 사는 곳. 'expected cuda:0 got cpu' 에러.
dtype family 는 외워둬야 해 — mixed-precision training 이 진지한 작업의 default 가 됐으니까:
torch.float32(aliastorch.float) — activation 과 weight 의 universal default.torch.float16(aliastorch.half) — 메모리 절반, bandwidth 절반, 근데 좁은 dynamic range 라 GradScaler 필요.torch.bfloat16— float32 와 같은 exponent range, mantissa 정밀도가 덜함. Ampere+ GPU 와 Apple Silicon 의 modern mixed-precision dtype. GradScaler 보통 불필요.torch.float64(double) — 완전 정밀도. 과학 계산이나 수치 문제 의심될 때 사용, training default 절대 아님.torch.int64(long) — class label, index, embedding lookup 의 default.torch.bool— mask.
casting
.to() 가 universal mover/caster. dtype, device, 또는 둘 다 받고, 이미 요청 형태면 no-op. shorthand 도 있어 (.float(), .half(), .cpu(), .cuda()) — context 에 따라 더 깔끔한 거 써.