from tensorflow.python.ops import gradients

    linear_vars = self._get_linear_vars()
    dnn_vars = self._get_dnn_vars()
    grads = gradients.gradients(loss, dnn_vars + linear_vars)
    dnn_grads = grads[0:len(dnn_vars)]
