cached_session for graph tests#1172
Conversation
| //control_flow_ops.while_loop( | ||
| // c, b, i , maximum_iterations: tf.constant(maximum_iterations)); | ||
| foreach (Operation op in sess.graph.get_operations()) | ||
| foreach (Operation op in sess.Single().graph.get_operations()) |
There was a problem hiding this comment.
@Oceania2018 I'm not sure how exactly IEnumerable should work there since Python generator produces only one instance. Anyway this test wasn't working and it is still not implemented yet.
There was a problem hiding this comment.
The test didn't come through.
Test method TensorFlowNET.UnitTest.Gradient.GradientTest.testBoundaryContinue threw exception:
Tensorflow.ValueError: Cannot use the default session to evaluate tensor: the tensor's graph is different from the session's graph. Pass an explicit session to `eval(session=sess)`.There was a problem hiding this comment.
Sorry, it was flaky. Now it should work.
There was a problem hiding this comment.
@Oceania2018 I'm not sure how exactly IEnumerable should work there since Python generator produces only one instance. Anyway this test wasn't working and it is still not implemented yet.
Since the different behavior of yield in Python and C#, If cached_session only need to have one session, I think it is better not to use yield? And then you can use using to replace with in GradientTest.cs
There was a problem hiding this comment.
Could, please, explain me why yield used in Python in this case?
Anyway fixed.
| { | ||
| if (self._cached_session != null) | ||
| { | ||
| self._cached_session.Dispose(); |
There was a problem hiding this comment.
@Oceania2018 should we cleanup the graph and the config as well?
| // Test that we differentiate both 'x' and 'y' correctly when x is a | ||
| // predecessor of y. | ||
|
|
||
| self.cached_session(); |
There was a problem hiding this comment.
@Oceania2018 I'm not sure how exactly "with" should be ported there, since "IEnumerable" isn't "IDisposable" and we don't need to call any "Dispose" for the enumerable itself. I guess session's "Dispose" should be called automatically.
4cbb062 to
9d71cad
Compare
Implementation of cached_session for the possibility of further porting of tests.
cached_session is a singleton which is constructed on the first call and disposed on the tests cleanup.
There's also testBoundaryContinue() test implemented to prove that cache_session() works.