Improve error message for Pad operator#39651
Improve error message for Pad operator#39651yaeldekel wants to merge 9 commits intopytorch:masterfrom
Conversation
💊 CI failures summary and remediationsAs of commit 3046a00 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 52 times. |
There was a problem hiding this comment.
Thanks, what's the error message in this case? Does it clarify the non-Constant issue?
facebook-github-bot
left a comment
There was a problem hiding this comment.
@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
neginraoof
left a comment
There was a problem hiding this comment.
Thanks! Can you add a test to cover this use-case?
There was a problem hiding this comment.
My understanding is that padding arg in reflecion_pad and replication_pad ops is always an array of ints.
Could padding be a single int?
Also, can you use _maybe_get_const() function from symbolic_helper to parse 'is'?
If the output is still a torch._C.Value, then throw the exception?
There was a problem hiding this comment.
You are correct. The padding arg has to be an array of ints, which can be represented either in an onnx::Constant node containing a tensor value, or a prim::ListConstruct node.
In reply to: 441648471 [](ancestors = 441648471)
There was a problem hiding this comment.
Sorry I meant sym_helper._get_const here.
Maybe something like:
try:
padding = sym_help._get_const(padding, 'is', 'constant_pad_nd')
except:
_unimplemented('constant_pad_nd', "<msg>")
There was a problem hiding this comment.
can you simplify the code by using _unpack_list: https://github.com/pytorch/pytorch/blob/master/torch/onnx/symbolic_helper.py#L109
to get the list values from prim::ListConstruct?
neginraoof
left a comment
There was a problem hiding this comment.
Thanks! Are there any related failures on CI?
There was a problem hiding this comment.
Sorry I should've asked for sym_help._get_const here.
This one throws an error if all list elements are not const.
Maybe something like:
try:
padding = sym_help._get_const(padding, 'is', 'constant_pad_nd')
except:
_unimplemented('constant_pad_nd', "<msg>")
There was a problem hiding this comment.
I think sym_help._get_const won't work in this case, because this is the condition that it checks (it throws an exception when it is true):
_is_value(value) and value.node().kind() not in ('onnx::Constant', 'prim::Constant')
and in the padding case, it can also be prim::ListConstruct.
But I did use your suggestion below for parsing the value in constant_pad_nd.
In reply to: 443761593 [](ancestors = 443761593)
There was a problem hiding this comment.
How about after you unpack the list? Maybe like:
try:
padding = [sym_help._get_const(v, 'is', 'constant_pad_nd') for v in input_list]
except:
_unimplemented('constant_pad_nd', "<msg>")
It checks for prim:Constant type as well, also use of _unimplemented is more consistent.
I'm trying to avoid custom arg parsing or error handling for symbolics.
There was a problem hiding this comment.
This looks okay for now. If see this type of error handling (per opset) repeating more often, we should handle it in a separate function to make it more generic.
|
cc @houseroad for review. Thanks! |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@houseroad has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@houseroad merged this pull request in 6e4f501. |
Summary: In issue pytorch#36997 the user encountered a non-meaningful error message when trying to export the model to ONNX. The Pad operator in opset 9 requires the list of paddings to be constant. This PR tries to improve the error message given to the user when this is not the case. Pull Request resolved: pytorch#39651 Reviewed By: hl475 Differential Revision: D21992262 Pulled By: houseroad fbshipit-source-id: b817111c2a40deba85e4c6cdb874c1713312dba1
This reverts commit acedeec.
Summary: In issue pytorch#36997 the user encountered a non-meaningful error message when trying to export the model to ONNX. The Pad operator in opset 9 requires the list of paddings to be constant. This PR tries to improve the error message given to the user when this is not the case. Pull Request resolved: pytorch#39651 Reviewed By: hl475 Differential Revision: D21992262 Pulled By: houseroad fbshipit-source-id: b817111c2a40deba85e4c6cdb874c1713312dba1
In issue #36997 the user encountered a non-meaningful error message when trying to export the model to ONNX. The Pad operator in opset 9 requires the list of paddings to be constant. This PR tries to improve the error message given to the user when this is not the case.