Skip to content

[graph] Method to test if placeholder is an output #2160

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

Closed
wants to merge 3 commits into from

Conversation

bertmaher
Copy link
Contributor

Description: I've often wanted to know whether a placeholder is an output of a function, but we lack a succinct way of doing that test. So I've added one :-)

Testing: new graphTest case

Documentation: n/a

@bertmaher
Copy link
Contributor Author

Two questions I had while writing this:

  1. This could be confusing if the same Placeholder is shared by multiple Functions in a Module, and is an output of one but not another. Should isOutput take a Function to test against?
  2. Are there some logical places we could use this elsewhere in the codebase? I've only added it in a test case so far.

@rdzhabarov
Copy link
Contributor

related to #1953

@rdzhabarov
Copy link
Contributor

Are there some logical places we could use this elsewhere in the codebase? I've only added it in a test case so far.

See the issue above. We copy both inputs/outputs when we should not do it.

@jfix71
Copy link
Contributor

jfix71 commented Dec 11, 2018

This could be confusing if the same Placeholder is shared by multiple Functions in a Module, and is an output of one but not another. Should isOutput take a Function to test against?

Yeah, I think it makes sense to take a Function to test against. Given the use case @rdzhabarov mentioned, where it's used to determine what to copy over to a device for executing a Function, you would want to check if the Placeholder is an output of that Function you're executing.

@@ -123,6 +123,9 @@ class Placeholder : public Storage {
/// differentiation.
bool isTraining() const { return isTrainable_; }

/// \returns True if this placeholder is an output of \p F.
bool isOutput(Function *F) const;
Copy link
Contributor

@rdzhabarov rdzhabarov Dec 12, 2018

Choose a reason for hiding this comment

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

we'd similarly need isInput().
Probably !isOutput should be good, unless we could make isInput more efficient in implementation

Copy link
Contributor

Choose a reason for hiding this comment

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

Some nodes can be inputs and outputs. For example, quantization nodes. How do we handle them?

Copy link
Contributor

@rdzhabarov rdzhabarov Dec 12, 2018

Choose a reason for hiding this comment

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

Good point! Profiling nodes are kinda special (similar thing would happen with training placeholders, but we have a way to check isTraining).

  • one simple solution would be to have an enum for type of placeholder { in, out, inout } and return it here.
  • another idea is to force placeholders for profiling nodes to be trainable (since we change values and then re-read them, similar process to training).
  • something else?

First approach seems to be cleaner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option could be to use isOverwrittenNthInput() -- we use it for checking for these other cases (profiling and training), right? So we could also add a check here for if a user is using the Placeholder as an overwritten input. Then we would also need a separate isInput().

Copy link
Contributor

@rdzhabarov rdzhabarov left a comment

Choose a reason for hiding this comment

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

@nadavrot raised a good point about in/out placeholders.

Let's sort it out before merging

@qcolombet
Copy link
Contributor

Given the in and out properties are part of the protobuf description (at least in C2), could we tag the placeholder upfront?
As for the quantization node problem, it feels to me like an exception that we don't really care in the sense that real network won't have those.

@bertmaher
Copy link
Contributor Author

Yeah, tagging the output PH up front maps pretty well to what I actually want out of this method. Of course there's still the matter of the 600 or so usages of createPlaceholder from the C++ APIs in unit tests :-(.

@nadavrot
Copy link
Contributor

I think that one way to move forward here is to change the name of the method into something like "isSavedInto" or something like that. In the future we should probably adopt the in/out attributes that the low-level IR has to the graph. What do you think?

@bertmaher
Copy link
Contributor Author

I'd be cool with a name-change in the short term (with a long-term desire to add attributes). I guess I also don't have a super-pressing need to land this change in the master branch. I was going to look at the use-case in the runtime so that this change is actually used by non-test code :)

Copy link
Contributor

@nadavrot nadavrot left a comment

Choose a reason for hiding this comment

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

Approving this PR because it sounds like we have a way to move forward.

@bertmaher
Copy link
Contributor Author

So I realized this morning that the way I was using this in a backend was just incorrect (for the curious, I was looking for SaveNode outputs during CompiledFunction::execute, which assumes the Function still exists, which is not guaranteed). Since I don't have any other use of this method planned, I'd rather not provide others with a convenient footgun. If this is useful at some future point, it won't be hard to re-create this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants