import tensorflow as tf

            if isinstance(grad, tf.IndexedSlices):
                grad_values = grad.values
            else:
                grad_values = grad
            summaries.append(tf.histogram_summary(var.op.name + ':gradient',
                                                  grad_values))
            summaries.append(tf.histogram_summary(var.op.name + ':gradient_norm',
                                                  tf.global_norm([grad_values])))
