def testRateOverrides(self, mocked_parametrized):
     mocked_parametrized.side_effect = (
         lambda x, rate: scale_gradient.scale_gradient(x, -rate))
     rate = 7.3
     cons = optimization_constraints.OptimizationConstraints()
     lhs = tf.zeros_like(1.0)
     rhs = tf.ones_like(1.0)
     x = cons.add(lhs < rhs, rate=rate)()
     v = tf.all_variables()[0]
     dxdl = tf.gradients(x, v)
     with tf.train.MonitoredSession() as sess:
         grads = sess.run(dxdl)
     self.assertAllClose(grads[0], rate)
Exemplo n.º 2
0
def _parametrize(x, rate=1.0):
    return scale_gradient.scale_gradient(_squared_softplus(x), -rate)