-
Notifications
You must be signed in to change notification settings - Fork 535
cached_session for graph tests #1172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cached_session for graph tests #1172
Conversation
@@ -29,7 +30,7 @@ private void _testWhileContextHelper(int maximum_iterations) | |||
var b = new Func<Tensor, Tensor>(x => math_ops.add(x, 1, name: "c")); | |||
//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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it was flaky. Now it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Oceania2018 should we cleanup the graph and the config as well?
|
||
self.cached_session(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.