A simple example first
import torch
import torch.nn as nn

loss = nn.MSELoss()  # see other loss classes in nn 
input = torch.randn(3, 5, requires_grad=True)
target = torch.randn(3, 5)
output = loss(input, target)
output.backward() # <-- backprop kicks in

Please see this 2 and this 3. Later more complete example 7.