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

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