Tutorial 2 Flashcards
What are the two optimization steps and loss step you need to perform in the training loop?
optimizer. zero_grad() - To zero out accumulated gradients
loss. backward() - To backpropagate and accumulate gradients for all parameters.
optimizer. step() - To update all parameters in the model according to the optimizer.
what does model(x).detach() do?
It constructs a new view on the tensor that is not attached to the computational graph.
what is tf.nn.CrossEntropyLoss()
It is a loss function in pytorch that calculates the cross entropy loss. It also internally applies the softmax function so all inputs should be raw and unnormalized.
What does torch.max(tensor, dim) give you?
It gives you the maximum values along the dimensions. It also returns the indices of the maximum values if multidimensional array is being called.
What does model.eval() do?
This tells all the layers that you are in eval() mode, meaning batchnorm or dropout layers will work in eval mode rather than training mode.
What does with torch.no_grad(): do?
Deactivates the autograd engine, resulting in less memory use and performance speedups, but no backpropagation.
What does tensor.size(d) do
Gives you size along the dth dimension.
How do you reshape a tensor
tensor.reshape()
How do you some up all the elements of a tensor in a given dimension?
tensor.sum(d)