-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Checker should validate the node's inputs/outputs have names when its formal parameter is Variadic #3979
Conversation
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
A quick comment: I suspect that issue 3969 will need a specific check in Loop operator's shape-inference method. I doubt if a generic check will be sufficient. Eg., note that a loop might use 5 loop-carried dependences ... then, it should be checking it has 5 outputs to handle them all. In fact, we should already have logic that updates the output-types for all these outputs ... that logic should ensure that these outputs do exist. |
Are you saying that the input number of Loop's state variable (except M and condition) should equal to the output number? If so, yes I think current Loop's shape inference should cover that by type propagation. A question: does OpSchema::Variadic allow any optional output (or input)? If not, current checker does not check that and that's why I added a generic check (checking OpSchema::Variadic cannot have any optional input/output). IIUC, this generic check should cover cases like issue 3969. Please correct me if I am wrong. Thank you! |
Ok, I think there are two separate problems. For your question about Variadic: we allow the op-spec to specify a "min arity" which is the minimum number of expected parameters. This is used to calculate min_input_ and max_input_ (and similarly for outputs). This is checked here: Line 151 in e4e1797
|
But I think the loop problem is a separate one, because the loop does not specify a minimum number of loop-carried dependences. That check is specific to that op, and hence must be in that op's shape-inference method. |
To confirm: So it is OK that for Variadic parameter, the input (or output) whose index > min_input_ (or min_output_) has any optional variable? I wasn't sure about this case and it seems a weird use case to me. If yes, I will update my current check for only considering index smaller than min_input_ (or min_output_).
Thank you for the clarification. So another missing check only for Loop op is to make sure the exact output number needs to be exactly the same as the input number? If so, yes I can include that check into this PR as well. |
You are right, these are all weird cases, and are not expected to happen in practice. I think the check you have is fine too, and let us keep it the way you have. I think the main case we want to catch is, for example, if users call the Max (or Mean, or Min, etc.) operator https://github.com/onnx/onnx/blob/main/docs/Operators.md#Max with zero inputs, because we expect 1 or more inputs. This is already being caught if the user omits the parameters completely, but if they use empty string it won't be caught. But you are right that if they call Min(x, "", y), it is a bit weird too ... should we complain, or just treat it as Min (x, y)? It may be safer to complain, it helps simplify the backends/runtimes from handling these weird cases. |
Yes. But I look at the existing code. This requires some non-trivial extension. The existing InferenceContext does not give us a direct API to check if an input/output exists. The right solution might be to extend it to add |
Agreed. I will keep it then.
I might miss something here -- Can't we simply just use |
Yes, you are right. Combined with the separate variadic check, this should work. I just realized that there is one disdvantage with the variadic check itself. It works for current ops, but if we add an op in the future where the variadic parameters have some specific interpretation, users might want to pass in inputs like |
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
This reverts commit 6aff395. Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
5b48eb6
to
68d449b
Compare
Attached a model that is now declared illegal. This model is produced by ORT training tests: It seems like the code here creates a node where some inputs may be empty, followed by non-empty inputs: It seems it was intentionally added in this PR: I'm not sure why they can't just include all inputs in that for loop. I think it might be a performance optimization. |
I think we should make the checker more lenient here. (As discussed above.) It does mean that checking that all inputs are specified for a loop op may be harder (as discussed above). But given the time-constraint, we could postpone the stronger-check for loops to after current release (as it might be non-trivial)? |
The final decision is reverting this PR for now: #4283. Thanks for catching this. |
… formal parameter is Variadic (onnx#3979) * check whether there is any empty string when Variadic Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add 2 tests Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * typo Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * fix typecheck Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * add a check for loop state variables Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com> * Revert "add a check for loop state variables" This reverts commit 6aff395. Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Description
Motivation and Context
Closes #3969. Current checker does not validate the Loop inputs/outputs have names when its formal parameter is Variadic.