One method for multi-task learning is to define a new loss function
loss = err1 + a*err2, where is a constant.
loss.backward()  will jointly optimize the two nets (net1 and net2) by performing backward pass.
We are calling variable.backward(), which in turn  calls autograd.backward
The gradient in the .backword call is the gradient with respect to output (or loss)
For loss.backward() there is no need to provide gradient (as gradient of loss is initialized to 1 by default.