Skip to content

Commit f3aba45

Browse files
justinchubypytorchmergebot
authored andcommitted
[ONNX] Create onnxscript-torchlib specific xfails/skips for fx tests (#110536)
Creates xfail_onnxscript/skip_onnxscript so that it is clear torchlib needs to support it. Pull Request resolved: #110536 Approved by: https://github.com/BowenBao
1 parent 95c59b3 commit f3aba45

File tree

1 file changed

+62
-13
lines changed

1 file changed

+62
-13
lines changed

test/onnx/test_fx_op_consistency.py

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from __future__ import annotations
2626

2727
import copy
28-
from typing import Optional, Tuple
28+
from typing import Any, Callable, Collection, Optional, Tuple, Union
2929

3030
import onnx_test_common
3131

@@ -162,6 +162,62 @@
162162
]
163163
)
164164

165+
166+
# NOTE: For ATen signature modifications that will break ONNX export,
167+
# use **xfail_torchlib_forward_compatibility** and **skip_torchlib_forward_compatibility** instead of xfail or skip
168+
# to make the signal apparent for maintainers.
169+
def xfail_torchlib_forward_compatibility(
170+
op_name: str,
171+
variant_name: str = "",
172+
*,
173+
reason: str,
174+
github_issue: str,
175+
opsets: Optional[Collection[Union[int, Callable[[int], bool]]]] = None,
176+
dtypes: Optional[Collection[torch.dtype]] = None,
177+
matcher: Optional[Callable[[Any], bool]] = None,
178+
enabled_if: bool = True,
179+
):
180+
"""Prefer using this (xfail) over skip when possible.
181+
182+
Only skip when the test is not failing consistently.
183+
"""
184+
return xfail(
185+
op_name,
186+
variant_name=variant_name,
187+
reason=f"{reason}. GitHub Issue: {github_issue}",
188+
opsets=opsets,
189+
dtypes=dtypes,
190+
matcher=matcher,
191+
enabled_if=enabled_if,
192+
)
193+
194+
195+
def skip_torchlib_forward_compatibility(
196+
op_name: str,
197+
variant_name: str = "",
198+
*,
199+
reason: str,
200+
github_issue: str,
201+
opsets: Optional[Collection[Union[int, Callable[[int], bool]]]] = None,
202+
dtypes: Optional[Collection[torch.dtype]] = None,
203+
matcher: Optional[Callable[[Any], Any]] = None,
204+
enabled_if: bool = True,
205+
):
206+
"""Prefer using xfail_torchlib_forward_compatibility over this (skip) when possible.
207+
208+
Only skip when the test is not failing consistently.
209+
"""
210+
return skip(
211+
op_name,
212+
variant_name=variant_name,
213+
reason=f"{reason}. GitHub Issue: {github_issue}",
214+
opsets=opsets,
215+
dtypes=dtypes,
216+
matcher=matcher,
217+
enabled_if=enabled_if,
218+
)
219+
220+
165221
# fmt: off
166222
# Turn off black formatting to keep the list compact
167223

@@ -541,28 +597,21 @@
541597
matcher=lambda sample: not isinstance(sample.kwargs.get("weight"), int),
542598
reason="ONNX SoftmaxCrossEntropyLoss op only accept argument[weight] is int type",
543599
),
544-
skip(
600+
skip_torchlib_forward_compatibility(
545601
"nn.functional.embedding_bag",
546602
matcher=lambda sample: sample.kwargs.get("padding_idx") is not None or True,
547-
reason=(
548-
"Torchlib does not support 'padding_idx' overload for _embedding_bag and _embedding_bag_forward_only. "
549-
"'padding_idx=-1' is emitted for aten op when 'padding_idx' is not provided. "
550-
"See https://github.com/microsoft/onnxscript/issues/1056 for details."
603+
reason=onnx_test_common.reason_onnx_script_does_not_support(
604+
"'padding_idx' overload for _embedding_bag and _embedding_bag_forward_only. "
605+
"'padding_idx=-1' is emitted for aten op when 'padding_idx' is not provided"
551606
),
607+
github_issue="https://github.com/microsoft/onnxscript/issues/1056",
552608
),
553609
skip(
554610
"nn.functional.max_pool3d",
555611
matcher=lambda sample: sample.kwargs.get("ceil_mode") is True
556612
and sample.kwargs.get("padding") == 1,
557613
reason="FIXME: After https://github.com/microsoft/onnxruntime/issues/15446 is fixed",
558614
),
559-
skip(
560-
"nn.functional.nll_loss",
561-
matcher=lambda sample: isinstance(sample.kwargs.get("reduction"), str),
562-
reason=onnx_test_common.reason_onnx_script_does_not_support(
563-
"string in reduction kwarg: https://github.com/microsoft/onnxscript/issues/726"
564-
),
565-
),
566615
xfail(
567616
"nonzero",
568617
matcher=lambda sample: len(sample.input.shape) == 0

0 commit comments

Comments
 (0)