Skip to content

Add control input dependency to Java bindings - #9815

Merged
caisq merged 2 commits into
tensorflow:masterfrom
kbsriram:java-control-inputs
May 14, 2017
Merged

caisq merged 2 commits into
tensorflow:masterfrom
kbsriram:java-control-inputs

Conversation

@kbsriram

Copy link
Copy Markdown
Contributor

Add a builder method to OperationBuilder to allow adding
control inputs to Operations.

Add a builder method to OperationBuilder to allow adding
control inputs to Operations.
@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@asimshankar
asimshankar self-requested a review May 10, 2017 22:48
@asimshankar asimshankar self-assigned this May 10, 2017

@asimshankar asimshankar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the change.

Some minor comments, otherwise looks great.

}

/**
* A control input is an Operation that must be executed or computed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
      }
  }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this import needed?

@asimshankar asimshankar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@caisq

caisq commented May 11, 2017

Copy link
Copy Markdown
Contributor

@tensorflow-jenkins test this please

@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@kbsriram

Copy link
Copy Markdown
Contributor Author

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.

@caisq

caisq commented May 14, 2017

Copy link
Copy Markdown
Contributor

@tensorflow-jenkins test this please

@caisq
caisq merged commit a8271ea into tensorflow:master May 14, 2017
@kbsriram
kbsriram deleted the java-control-inputs branch May 15, 2017 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants