You should create an autograd function that makes all your sparse operation:
class SparseOperations(autograd.Function):
    def forward(self, input, weight, bias=None):
        # here comes the sparse operations
        return output

    def backward(self, grad_output):
        # here you compute the gradient of your sparse operation by hands
        return grad_input

Then you create a loss function from nn.Module:
class AwsomeLoss(nn.Module):
    def __init__(self):
        super(AwsomeLoss,self).__init__()
        self.sparse_operation = SparseOperation()

    def forward(self, input, target):
        loss = self.sparse_operation(input, target)
        return loss

Finaly, you can directly sum L = L1 + L2 and call L.backward(). If your gradient is well computed, it should work.