-
Notifications
You must be signed in to change notification settings - Fork 699
[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
Conversation
Two questions I had while writing this:
|
related to #1953 |
See the issue above. We copy both inputs/outputs when we should not do it. |
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; |
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.
we'd similarly need isInput().
Probably !isOutput should be good, unless we could make isInput more efficient in implementation
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.
Some nodes can be inputs and outputs. For example, quantization nodes. How do we handle them?
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.
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.
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.
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()
.
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.
@nadavrot raised a good point about in/out placeholders.
Let's sort it out before merging
Given the in and out properties are part of the protobuf description (at least in C2), could we tag the placeholder upfront? |
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 :-(. |
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? |
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 :) |
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.
Approving this PR because it sounds like we have a way to move forward.
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 |
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