You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GradientsTest.cs 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using NumSharp;
  6. using Tensorflow;
  7. using static Tensorflow.Python;
  8. namespace TensorFlowNET.UnitTest.gradients_test
  9. {
  10. [TestClass]
  11. public class GradientsTest : PythonTest
  12. {
  13. [Ignore("TODO")]
  14. [TestMethod]
  15. public void testGradients()
  16. {
  17. var g = tf.Graph().as_default();
  18. var inp = tf.constant(1.0, shape: new[] { 32, 100 }, name: "in");
  19. var w = tf.constant(1.0, shape: new[] { 100, 10 }, name: "w");
  20. var b = tf.constant(1.0, shape: new[] { 10 }, name: "b");
  21. var xw = math_ops.matmul(inp, w, name: "xw");
  22. var h = nn_ops.bias_add(xw, b, name: "h");
  23. var w_grad = gradients_impl.gradients(new[] { h }, new[] { w })[0];
  24. self.assertEquals("MatMul", w_grad.op.type);
  25. // TODO: Operation._original_op
  26. //self.assertEquals(w_grad.op._original_op, xw.op);
  27. self.assertTrue((bool)w_grad.op.get_attr("transpose_a"));
  28. self.assertFalse((bool)w_grad.op.get_attr("transpose_b"));
  29. }
  30. [TestMethod]
  31. public void testBatchMatMulGradient()
  32. {
  33. var a = tf.constant(np.array(Enumerable.Range(1, 18).Select(elem => (float)elem).ToArray()), shape: new[] { 2, 3, 3 });
  34. var b = tf.divide(a, tf.constant(2.0f));
  35. var c = tf.batch_matmul(a, b);
  36. var g = tf.gradients(c, new[] { a, b }, stop_gradients: new[] { a, b });
  37. var checkG = new[]
  38. {
  39. 3.0f, 7.5f, 12.0f,
  40. 3.0f, 7.5f, 12.0f,
  41. 3.0f, 7.5f, 12.0f,
  42. 16.5f, 21.0f, 25.5f,
  43. 16.5f, 21.0f, 25.5f,
  44. 16.5f, 21.0f, 25.5f,
  45. 12.0f, 12.0f, 12.0f,
  46. 15.0f, 15.0f, 15.0f,
  47. 18.0f, 18.0f, 18.0f,
  48. 39.0f, 39.0f, 39.0f,
  49. 42.0f, 42.0f, 42.0f,
  50. 45.0f, 45.0f, 45.0f
  51. };
  52. using (var sess = tf.Session())
  53. {
  54. var result = sess.run(g);
  55. var resultList = result[0].GetData<float>().ToList();
  56. resultList.AddRange(result[1].GetData<float>());
  57. Console.WriteLine(result.ToString());
  58. CollectionAssert.AreEqual(resultList.ToArray(), checkG);
  59. }
  60. }
  61. [TestMethod]
  62. public void testTanhGradient()
  63. {
  64. var a = tf.constant(1f);
  65. var b = tf.tanh(a);
  66. var g = tf.gradients(b, a);
  67. using (var sess = tf.Session())
  68. {
  69. var result = sess.run(g);
  70. var actual = result[0].GetData<float>()[0];
  71. self.assertEquals(0.41997434127f, actual);
  72. }
  73. }
  74. [TestMethod]
  75. public void testLgammaGrad()
  76. {
  77. var a = tf.constant(5f);
  78. var b = tf.lgamma(a);
  79. var g = tf.gradients(b, a);
  80. using (var sess = tf.Session())
  81. {
  82. var result = sess.run(new object[] { g, b });
  83. var actualDeriv = result[0].GetData<float>()[0];
  84. var actual = result[1].GetData<float>()[0];
  85. self.assertEquals(1.5061177f, actualDeriv);
  86. self.assertEquals(3.17805386f, actual);
  87. }
  88. }
  89. [TestMethod]
  90. public void testSliceGrad()
  91. {
  92. var a = tf.tanh(tf.constant(new[] { 2f, 3f }, shape: new[] { 2, 1 }));
  93. var b = tf.strided_slice(a,
  94. tf.constant(new[] { 0 }, tf.int32, new[] { 1 }),
  95. tf.constant(new[] { 1 }, tf.int32, new[] { 1 }),
  96. tf.constant(new[] { 1 }, tf.int32, new[] { 1 })
  97. );
  98. var g = tf.gradients(b, a);
  99. using (var sess = tf.Session())
  100. {
  101. var result = sess.run(new object[] { g, b });
  102. var actualDeriv = np.squeeze(result[0]);
  103. var actual = np.squeeze(result[1]);
  104. self.assertEquals(new float[] { 1, 0 }, new float[] { actualDeriv[0], actualDeriv[1] });
  105. self.assertEquals(0.9640276f, (float)actual);
  106. }
  107. }
  108. [TestMethod]
  109. public void testConcatGrad()
  110. {
  111. var a1 = tf.constant(new[] { 2f }, shape: new[] { 1 });
  112. var a2 = tf.constant(new[] { 3f }, shape: new[] { 1 });
  113. var a = tf.concat(new List<Tensor>(new[] { a1, a2 }), 0);
  114. var g = tf.gradients(a, a1);
  115. using (var sess = tf.Session())
  116. {
  117. var result = sess.run(new object[] { g, a });
  118. var actualDeriv = result[0].GetData<float>()[0];
  119. var actual = result[1].GetData<float>()[0];
  120. self.assertEquals(1f, actualDeriv);
  121. self.assertEquals(2f, actual);
  122. }
  123. }
  124. [Ignore("TODO")]
  125. [TestMethod]
  126. public void testUnusedOutput()
  127. {
  128. //def testUnusedOutput(self):
  129. // with ops.Graph().as_default():
  130. // w = constant(1.0, shape=[2, 2])
  131. // x = constant(1.0, shape=[2, 2])
  132. // wx = math_ops.matmul(w, x)
  133. // split_wx = array_ops.split(value=wx, num_or_size_splits=2, axis=0)
  134. // c = math_ops.reduce_sum(split_wx[1])
  135. // gw = gradients.gradients(c, [w])[0]
  136. // self.assertEquals("MatMul", gw.op.type)
  137. }
  138. [Ignore("TODO")]
  139. [TestMethod]
  140. public void testColocateGradients()
  141. {
  142. //def testColocateGradients(self):
  143. // with ops.Graph().as_default() as g:
  144. // w = constant(1.0, shape=[1, 1])
  145. // x = constant(1.0, shape=[1, 2])
  146. // with g.device("/device:GPU:0"):
  147. // wx = math_ops.matmul(w, x)
  148. // gw = gradients.gradients(wx, [w], colocate_gradients_with_ops=True)[0]
  149. // self.assertEqual(gw.op.colocation_groups(), wx.op.colocation_groups())
  150. }
  151. [Ignore("TODO")]
  152. [TestMethod]
  153. public void testColocateGradientsWithAggregation()
  154. {
  155. //def testColocateGradientsWithAggregation(self):
  156. // with ops.Graph().as_default() as g:
  157. // with g.device("/device:GPU:1"):
  158. // w = constant(1.0, shape=[1, 1])
  159. // x = constant(1.0, shape=[1, 2])
  160. // y = constant(1.0, shape=[1, 2])
  161. // wx = math_ops.matmul(w, x)
  162. // wy = math_ops.matmul(w, y)
  163. // with g.device("/device:GPU:0"):
  164. // z = wx + wy
  165. // gw1 = gradients.gradients(z, [w], colocate_gradients_with_ops=True)[0]
  166. // self.assertEqual(gw1.op.colocation_groups(), wx.op.colocation_groups())
  167. // gw2 = gradients.gradients(z, [w], colocate_gradients_with_ops=False)[0]
  168. // self.assertTrue(wx.op.colocation_groups() != gw2.op.colocation_groups())
  169. }
  170. [Ignore("TODO")]
  171. [TestMethod]
  172. public void testColocateGradientsWithAggregationInMultipleDevices()
  173. {
  174. //def testColocateGradientsWithAggregationInMultipleDevices(self):
  175. // with ops.Graph().as_default() as g:
  176. // with g.device("/device:GPU:1"):
  177. // w = constant(1.0, shape=[1, 1])
  178. // x = constant(1.0, shape=[1, 2])
  179. // y = constant(1.0, shape=[1, 2])
  180. // with g.device("/task:1"):
  181. // wx = math_ops.matmul(w, x)
  182. // with g.device("/task:2"):
  183. // wy = math_ops.matmul(w, y)
  184. // with g.device("/device:GPU:0"):
  185. // z = wx + wy
  186. // gw1 = gradients.gradients(z, [w], colocate_gradients_with_ops=True)[0]
  187. // self.assertEqual(gw1.op.colocation_groups(), w.op.colocation_groups())
  188. // gw2 = gradients.gradients(z, [w], colocate_gradients_with_ops=False)[0]
  189. // self.assertTrue(w.op.colocation_groups() != gw2.op.colocation_groups())
  190. }
  191. [Ignore("TODO")]
  192. [TestMethod]
  193. public void testColocateGradientsWithGateGradients()
  194. {
  195. //def testColocateGradientsWithGateGradients(self):
  196. // if not test_util.is_gpu_available():
  197. // self.skipTest("No GPU available")
  198. // with ops.Graph().as_default() as g:
  199. // with g.device("/device:CPU:0"):
  200. // x = constant(1.0, shape=[1, 1])
  201. // y = constant(1.0, shape=[1, 1])
  202. // s = x + y
  203. // with g.device("/device:GPU:0"):
  204. // z = math_ops.reduce_sum(s)
  205. // gz_x = gradients.gradients(z, [x], colocate_gradients_with_ops=True,
  206. // gate_gradients=True)[0]
  207. // with session.Session():
  208. // # Make sure the placer doesn't complain.
  209. // self.evaluate(gz_x)
  210. }
  211. [Ignore("TODO")]
  212. [TestMethod]
  213. public void testBoundaryStop()
  214. {
  215. //def testBoundaryStop(self):
  216. // # Test that we don't differentiate 'x'. The gradient function for 'x' is
  217. // # set explicitly to None so we will get an exception if the gradient code
  218. // # tries to differentiate 'x'.
  219. // with ops.Graph().as_default():
  220. // c = constant(1.0)
  221. // x = array_ops.identity(c)
  222. // y = x + 1.0
  223. // z = y + 1
  224. // grads = gradients.gradients(z, [x])
  225. // self.assertTrue(all(x is not None for x in grads))
  226. }
  227. [Ignore("TODO")]
  228. [TestMethod]
  229. public void testBoundaryContinue()
  230. {
  231. //@test_util.run_v1_only("b/120545219")
  232. //def testBoundaryContinue(self):
  233. // # Test that we differentiate both 'x' and 'y' correctly when x is a
  234. // # predecessor of y.
  235. // with self.cached_session():
  236. // x = constant(1.0)
  237. // y = x * 2.0
  238. // z = y * 3.0
  239. // grads = gradients.gradients(z, [x, y])
  240. // self.assertTrue(all(x is not None for x in grads))
  241. // self.assertEqual(6.0, grads[0].eval())
  242. }
  243. [Ignore("TODO")]
  244. [TestMethod]
  245. public void testAggregationMethodAccumulateN()
  246. {
  247. //@test_util.run_v1_only("b/120545219")
  248. //def testAggregationMethodAccumulateN(self):
  249. // with self.cached_session():
  250. // x = constant(1.0)
  251. // y = x * 2.0
  252. // z = y + y + y + y + y + y + y + y + y + y
  253. // grads = gradients.gradients(
  254. // z, [x, y],
  255. // aggregation_method=gradients.AggregationMethod.
  256. // EXPERIMENTAL_ACCUMULATE_N)
  257. // self.assertTrue(all(x is not None for x in grads))
  258. // self.assertEqual(20.0, grads[0].eval())
  259. // self.assertEqual(10.0, grads[1].eval())
  260. }
  261. [Ignore("TODO")]
  262. [TestMethod]
  263. public void testAggregationMethodAddN()
  264. {
  265. //@test_util.run_v1_only("b/120545219")
  266. //def testAggregationMethodAddN(self):
  267. // with self.cached_session():
  268. // x = constant(1.0)
  269. // y = x * 2.0
  270. // z = y + y + y + y + y + y + y + y + y + y
  271. // grads = gradients.gradients(
  272. // z, [x, y], aggregation_method=gradients.AggregationMethod.ADD_N)
  273. // self.assertTrue(all(x is not None for x in grads))
  274. // self.assertEqual(20.0, grads[0].eval())
  275. // self.assertEqual(10.0, grads[1].eval())
  276. }
  277. [Ignore("TODO")]
  278. [TestMethod]
  279. public void testAggregationMethodTree()
  280. {
  281. //@test_util.run_v1_only("b/120545219")
  282. //def testAggregationMethodTree(self):
  283. // with self.cached_session():
  284. // x = constant(1.0)
  285. // y = x * 2.0
  286. // z = y + y + y + y + y + y + y + y + y + y
  287. // grads = gradients.gradients(
  288. // z, [x, y],
  289. // aggregation_method=gradients.AggregationMethod.EXPERIMENTAL_TREE)
  290. // self.assertTrue(all(x is not None for x in grads))
  291. // self.assertEqual(20.0, grads[0].eval())
  292. // self.assertEqual(10.0, grads[1].eval())
  293. }
  294. [Ignore("TODO")]
  295. [TestMethod]
  296. public void testNoGradientForStringOutputs()
  297. {
  298. //def testNoGradientForStringOutputs(self):
  299. // with ops.Graph().as_default():
  300. // def _TestOpGrad(_, float_grad, string_grad):
  301. // """Gradient function for TestStringOutput."""
  302. // self.assertEquals(float_grad.dtype, dtypes.float32)
  303. // self.assertFalse(string_grad)
  304. // return float_grad
  305. // ops.RegisterGradient("TestStringOutput")(_TestOpGrad)
  306. // c = constant(1.0)
  307. // x, _ = test_ops.test_string_output(c)
  308. // z = x * 2.0
  309. // w = z * 3.0
  310. // grads = gradients.gradients(z, [c])
  311. // self.assertTrue(isinstance(grads[0], ops.Tensor))
  312. // grads = gradients.gradients(w, [c])
  313. // self.assertTrue(isinstance(grads[0], ops.Tensor))
  314. }
  315. [Ignore("TODO")]
  316. [TestMethod]
  317. public void testSingletonIndexedSlices()
  318. {
  319. //def testSingletonIndexedSlices(self):
  320. // with ops.Graph().as_default():
  321. // x = array_ops.placeholder(dtypes.float32)
  322. // y = array_ops.identity(x)
  323. // dy = ops.IndexedSlices(
  324. // array_ops.placeholder(dtypes.float32),
  325. // array_ops.placeholder(dtypes.int32))
  326. // dx, = gradients.gradients(y, x, grad_ys=dy)
  327. // # The IndexedSlices gradient of tf.identity is the identity map.
  328. // with self.cached_session() as sess:
  329. // vdx, vdy = sess.run(
  330. // [dx, dy], feed_dict={x: [1.0], dy.indices: [0], dy.values: [2.0]})
  331. // self.assertEqual(vdx, vdy)
  332. }
  333. [Ignore("TODO")]
  334. [TestMethod]
  335. public void testNonDifferentiableSwitchInWhileLoop()
  336. {
  337. //@test_util.run_v1_only("b/120545219")
  338. //def testNonDifferentiableSwitchInWhileLoop(self):
  339. // with ops.Graph().as_default():
  340. // v = array_ops.placeholder(dtypes.float32, [])
  341. // def _Step(i, a, ta):
  342. // a += math_ops.cast(v, dtypes.int32)
  343. // return (i + 1, a, ta.write(i, a))
  344. // n = 4
  345. // i, _, ta = control_flow_ops.while_loop(
  346. // lambda i, *_: i < n,
  347. // _Step, [0, 0, tensor_array_ops.TensorArray(
  348. // dtypes.int32, size=n)])
  349. // target = ta.read(i - 1)
  350. // grad, = gradients.gradients(target, v)
  351. // self.assertIsNone(grad)
  352. }
  353. [Ignore("TODO")]
  354. [TestMethod]
  355. public void testVariableReadValueGradient()
  356. {
  357. //def testVariableReadValueGradient(self):
  358. // with ops.Graph().as_default():
  359. // init = constant_op.constant(100.0)
  360. // var = variables.Variable(init)
  361. // gradient = gradients.gradients(var.read_value(), var)
  362. // self.assertIsNotNone(gradient)
  363. }
  364. [Ignore("TODO")]
  365. [TestMethod]
  366. public void testVariableAsGraphElementGradient()
  367. {
  368. //def testVariableAsGraphElementGradient(self):
  369. // with ops.Graph().as_default() as graph:
  370. // init = constant_op.constant(100.0)
  371. // var = variables.Variable(init)
  372. // gradient = gradients.gradients(graph.as_graph_element(var), var)
  373. // self.assertIsNotNone(gradient)
  374. }
  375. [Ignore("TODO")]
  376. [TestMethod]
  377. public void testVariableRefGradient()
  378. {
  379. //@test_util.run_v1_only("b/120545219")
  380. //def testVariableRefGradient(self):
  381. // with ops.Graph().as_default():
  382. // init = constant_op.constant(100.0)
  383. // var = variables.VariableV1(init)
  384. // gradient = gradients.gradients(var._ref(), var)
  385. // self.assertIsNotNone(gradient)
  386. }
  387. [Ignore("TODO")]
  388. [TestMethod]
  389. public void testDependentYs()
  390. {
  391. //@test_util.run_v1_only("b/120545219")
  392. //def testDependentYs(self):
  393. // with self.cached_session():
  394. // x = constant_op.constant(3.0)
  395. // y = math_ops.square(x)
  396. // y1 = math_ops.square(y)
  397. // y2 = math_ops.square(y1)
  398. // g = gradients.gradients([y, y2], x)
  399. // self.assertAllClose(17502.0, g[0].eval())
  400. // g = gradients.gradients(y + y2, x)
  401. // self.assertAllClose(17502.0, g[0].eval())
  402. // z = array_ops.identity(y)
  403. // z2 = array_ops.identity(y2)
  404. // g = gradients.gradients([z, z2], x)
  405. // self.assertAllClose(17502.0, g[0].eval())
  406. }
  407. [Ignore("TODO")]
  408. [TestMethod]
  409. public void testPartialDerivatives()
  410. {
  411. //@test_util.run_v1_only("b/120545219")
  412. //def testPartialDerivatives(self):
  413. // with self.cached_session():
  414. // x = constant_op.constant(1.)
  415. // y = 2 * x
  416. // z = x + y
  417. // totalg = gradients.gradients(z, [x, y])
  418. // self.assertEqual([3.0, 1.0], [g.eval() for g in totalg])
  419. // partialg = gradients.gradients(z, [x, y], stop_gradients=[x, y])
  420. // self.assertEqual([1.0, 1.0], [g.eval() for g in partialg])
  421. }
  422. [Ignore("TODO")]
  423. [TestMethod]
  424. public void testStopGradients()
  425. {
  426. //@test_util.run_v1_only("b/120545219")
  427. //def testStopGradients(self):
  428. // def _MakeGraph(rng, stop_gradients=()):
  429. // def _FunctionOf(xs, k=3):
  430. // return ops.convert_to_tensor(
  431. // sum(math_ops.matmul(rng.rand(k, k), x) for x in xs)
  432. // + rng.rand(k, k))
  433. // a = _FunctionOf([])
  434. // if "a" in stop_gradients: a = array_ops.stop_gradient(a)
  435. // b = _FunctionOf([a])
  436. // if "b" in stop_gradients: b = array_ops.stop_gradient(b)
  437. // c = _FunctionOf([a, b])
  438. // if "c" in stop_gradients: c = array_ops.stop_gradient(c)
  439. // d = _FunctionOf([b, c])
  440. // if "d" in stop_gradients: d = array_ops.stop_gradient(d)
  441. // return dict(a=a, b=b, c=c, d=d)
  442. // def _Gradients(ys, xs, **kwargs):
  443. // dydxs = gradients.gradients(ys, xs, **kwargs)
  444. // dydxs = [0. * x if dydx is None else dydx
  445. // for x, dydx in zip(xs, dydxs)]
  446. // return dydxs
  447. // seed = np.random.randint(1000)
  448. // cases = []
  449. // subsets = [""] + "a b c d ab ac ad bc bd cd abc abd acd bcd abcd".split()
  450. // graph = _MakeGraph(np.random.RandomState(seed))
  451. // for constants in subsets:
  452. // graph_with_stops = _MakeGraph(np.random.RandomState(seed), constants)
  453. // for variables_ in subsets:
  454. // # compute the gradient when stopped using tf.stop_gradients
  455. // grad1 = _Gradients([graph_with_stops["d"]],
  456. // [graph_with_stops[v] for v in variables_])
  457. // # compute the gradient when stopped using the stop_gradients kwarg
  458. // grad2 = _Gradients([graph["d"]],
  459. // [graph[v] for v in variables_],
  460. // stop_gradients=[graph[v] for v in constants])
  461. // cases.append(dict(grad1=grad1, grad2=grad2,
  462. // constants=constants, variables=variables_))
  463. // # evaluate all tensors in one call to session.run for speed
  464. // with self.cached_session() as sess:
  465. // results = sess.run([(case["grad1"], case["grad2"]) for case in cases])
  466. // for (npgrad1, npgrad2), case in zip(results, cases):
  467. // for a, b in zip(npgrad1, npgrad2):
  468. // np.testing.assert_allclose(a, b)
  469. }
  470. [Ignore("TODO")]
  471. [TestMethod]
  472. public void testUnconnectedGradientsNoneUnconnectedGradients()
  473. {
  474. //def testUnconnectedGradientsNoneUnconnectedGradients(self):
  475. // with ops.Graph().as_default():
  476. // x = constant(1.0, shape=[2, 2])
  477. // y = constant(3.0, shape=[3, 1])
  478. // grad = gradients.gradients(
  479. // [y], [x], unconnected_gradients="none")
  480. // self.assertIsNone(grad[0])
  481. }
  482. [Ignore("TODO")]
  483. [TestMethod]
  484. public void testUnconnectedGradientsZerosUnconnectedGradients()
  485. {
  486. //def testUnconnectedGradientsZerosUnconnectedGradients(self):
  487. // with ops.Graph().as_default():
  488. // x = constant(1.0, shape=[2, 2])
  489. // y = constant(3.0, shape=[3, 1])
  490. // grads = gradients.gradients(
  491. // [y], [x], unconnected_gradients="zero")
  492. // with self.cached_session() as sess:
  493. // self.assertAllEqual([[0.0, 0.0], [0.0, 0.0]], self.evaluate(grads)[0])
  494. }
  495. [Ignore("TODO")]
  496. [TestMethod]
  497. public void testUnconnectedGradientsZeroConnectedGradients()
  498. {
  499. //def testUnconnectedGradientsZeroConnectedGradients(self):
  500. // with ops.Graph().as_default():
  501. // x = constant(1.0)
  502. // y = x * 3.0
  503. // grad = gradients.gradients(
  504. // [y], [x], unconnected_gradients="zero")
  505. // with self.cached_session() as sess:
  506. // self.assertEquals(3.0, self.evaluate(grad)[0])
  507. }
  508. [Ignore("TODO")]
  509. [TestMethod]
  510. public void testUnknownUnconnectedGradientsValueGiven()
  511. {
  512. //def testUnknownUnconnectedGradientsValueGiven(self):
  513. // with ops.Graph().as_default():
  514. // x = constant(1.0)
  515. // y = constant(1.0)
  516. // with self.assertRaisesRegexp(
  517. // ValueError, "Unknown value for unconnected_gradients: 'nonsense'"):
  518. // gradients.gradients([y], [x], unconnected_gradients="nonsense")
  519. }
  520. /*
  521. */
  522. }
  523. }