Repository navigation
Add control input dependency to Java bindings - #9815
Conversation
Add a builder method to OperationBuilder to allow adding control inputs to Operations.
|
Can one of the admins verify this patch? |
asimshankar
left a comment
There was a problem hiding this comment.
Thanks very much for the change.
Some minor comments, otherwise looks great.
| } | ||
|
|
||
| /** | ||
| * A control input is an Operation that must be executed or computed |
There was a problem hiding this comment.
I believe the idea is for the first sentence to appear as the summary in Javadoc, so maybe rewrite it a bit:
/**
* Ensure that the operation does not execute before the control operation does.
*
* <what you already have here>
*/| } | ||
|
|
||
| /** | ||
| * A control input is an Operation that must be executed or computed |
There was a problem hiding this comment.
Instead "executed or computed", how about just "executed"
Something like:
A control input is an Operation that must be executed before the operation being built.
|
|
||
| JNIEXPORT void JNICALL Java_org_tensorflow_OperationBuilder_addControlInput( | ||
| JNIEnv* env, jclass clazz, jlong handle, jlong op_handle) { | ||
| TF_Operation* control = requireOperation(env, op_handle); |
There was a problem hiding this comment.
This seems like the only use of requireOperation. Might be better to inline it and tailor the exception message> Something like:
if (op_handle == 0) {
throwException(env, kIllegalStateException, "control input is not valid, perhaps the Graph containing it has been closed()?");
return;
}
TF_Operation* control = reinterpret_cast<TF_Operation*>(op_handle);| public void addControlInput() { | ||
| assertEquals(0, lessEqualControl(2, 3).size()); | ||
| try { | ||
| lessEqualControl(3, 2); |
There was a problem hiding this comment.
There is a lot happening in lessEqualControl to be able to tie the exception to the specific line we want.
It might be better to create a simpler graph with a placeholder and have the try{} block around just the session run call. Something like:
public void addControlInput() {
try (Graph g = new Graph();
Session s = new Session(g);
Tensor yes = Tensor.create(true);
Tensor no = Tensor.create(false)) {
Output placeholder = TestUtil.placeholder(g, "boolean", DataType.BOOL);
Output assert = g.opBuilder("Assert", "assert")
.addInput(placeholder)
.addInputList(new Output[]{})
.build();
Output noop = g.opBuilder("NoOp", "noop")
.addControlInput(assert)
.build();
// No problems when the assert succeeds
s.runner().feed(placeholder, yes).addTarget(noop).run();
// Exception thrown by the execution of the Assert node
try {
s.runner().feed(placeholder, no).addTarget(noop).run();
fail(...);
} catch (IllegalArgumentException e) {
// expected
}
}
}There was a problem hiding this comment.
Nice! Thanks @asimshankar for the pointers to simplify the test, and the other suggestions. I've incorporated all of them in the next update of this PR.
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
||
| import java.util.List; |
There was a problem hiding this comment.
Why was this import needed?
|
@tensorflow-jenkins test this please |
|
Can one of the admins verify this patch? |
|
Is there perhaps a flaky test in the windows CMake build? The only time the ci build ran it reported an error in a seemingly unrelated area of the code; and I'm not able to connect the dots between the reported failure and this change. |
|
@tensorflow-jenkins test this please |
Add a builder method to OperationBuilder to allow adding
control inputs to Operations.