A small example would be
loss = criterion(predictions, target) 
optim.zero_grad()
loss.backward() # this actually calculates the gradients
optim.step()

Where criterion would be an instance of your custom loss-module, predictions and targets would be tensors holding the corresponding values (and a gradient-path for predictions, which is automatically tracked by autograd) and optim an instance of an optimizer-class of your choice.