cs391R - Intorduction to Pytorch
Yifeng Zhu
Department of Computer Science The University of Texas at Austin
September 28, 2020
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 1 / 9
cs391R - Intorduction to Pytorch Yifeng Zhu Department of Computer - - PowerPoint PPT Presentation
cs391R - Intorduction to Pytorch Yifeng Zhu Department of Computer Science The University of Texas at Austin September 28, 2020 cs391R - Robot Learning Online September 28, 2020 1 / 9 Yifeng Zhu Disclaimer: Adopted from gatech tutorial: Link
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 1 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 2 / 9
Attributes of a tensor 't':
requires_grad- making a trainable parameter
○ t.requires_grad_()or ○ t = torch.randn(1, requires_grad=True)
○ t.data
○ t.grad grad_fn- history of operations for autograd
Numpy arrays to PyTorch tensors
PyTorchtensor to numpy
Using GPU acceleration
Fallback to cpu if gpu is unavailable:
Check cpu/gpu tensor OR numpyarray ?
○ numpy.ndarray ○ torch.Tensor ■ CPU - torch.cpu.FloatTensor ■ GPU - torch.cuda.FloatTensor
chain rule etc. ○ backward()does that
○ Need to zero out gradients after each update ○ tensor.grad_zero()
Optimizer
we want to update, the learning rate we want to use along with other hyper-parameters and performs the updates Loss
choose from
In PyTorch, a model is represented by a regular Python class that inherits from the Module class.
○ __init__(self): it defines the parts that make up the model- in our case, two parameters, a and b ○ forward(self, x) : it performs the actual computation, that is, it outputs a prediction, given the inputx
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 3 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 4 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 5 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 6 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 7 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 8 / 9
Yifeng Zhu cs391R - Robot Learning Online September 28, 2020 9 / 9