본문 바로가기

Torch10

[DL] PyTorch: Autograd (Basic) Autograd 사용하기. 1. requires_grad 를 True로 설정. 편미분을 구할 Tensor 인스턴스에 대해 requires_grad=True 가 되도록하여, 해당 Tensor 인스턴스에 대한 연산을 추적하고, 자동으로 gradient를 계산할 수 있도록 수행. x = torch.tensor([2.0], requires_grad=True) autograd와 관련된 attributes는 다음과 같음. x.requires_grad : grad 를 구하기위해 forward propagation에서 gradient를 구하기 위해 필요한 연산 및 중간값을 추적하여 기록할지 여부를 나타냄 x.is_leaf: 계산 그래프에서 “leaf node"인지 여부를 나타냄. leaf node는 다른 tensor를.. 2024. 3. 22.
[DL] PyTorch: TPU사용하기 https://github.com/pytorch/xla GitHub - pytorch/xla: Enabling PyTorch on XLA Devices (e.g. Google TPU) Enabling PyTorch on XLA Devices (e.g. Google TPU). Contribute to pytorch/xla development by creating an account on GitHub. github.com 다음 문서도 참고할 것. https://github.com/pytorch/xla/blob/master/API_GUIDE.md TPU로 PyTorch를 사용하기 위해서는 PyTorch / XLA 를 이용한다. PyTorch / XLA PyTorch로 구현된 model 및 PyTorch co.. 2024. 3. 21.
[DL] Storage: PyTorch 텐서를 위한 메모리 관리 Storage는 Tensor 인스턴스의 실제 데이터가 저장되는 1D Numerical Array를 관리함. 여러 Tensor 인스턴스들이 같은 storage를 공유할 수 있음. Storage는 memory에서 contiguous data block를 관리하며, 컴퓨터의 memory에서 homogeneous and contiguous array의 특징상 1D 임. cpu 또는 gpu 등의 memory의 실제 data가 저장된 contiguous block을 관리. 다양한 shape의 Tensor 인스턴스들은 자신의 storage인스턴스를 통해 data block을 관리함. 어찌 보면 Tensor 인스턴스들은 고유한 shape, stride, offset 을 가진 일종의 View에 해당한다. 참고: 다음 U.. 2024. 3. 21.
[Tensor] vectorized op. (or universal func) Numpy에서 제공하는 ufunc. (Universal Functions)은 homogeneous and contiguous tensor 에서 모든 elements에 같은 연산을 적용하여 기존의 반복 loop에 기반한 연산에 비해 압도적인 속도를 보이면서 간편한 연산자 하나로 처리하도록 지원해줌. ufunc는 일종의 vectorized operation (or vector operation) 임. 실제로 ufunc은 homogeneous and contiguous에 최적화된 바이너리 구현물에 대한 binding이라고 볼 수 있음. Python interface가 제공되어 쉽게 사용가능하지만, 내부적으로는 C, C++등의 컴파일 언어로 만들어진 바이너리 구현물이 동작한다고 보면 된다. https://ds3.. 2024. 3. 19.
반응형