Skip to content

Commit 4d35dca

Browse files
authored
Merge branch 'master' into model_opsets
2 parents 7baf78c + 2ec2086 commit 4d35dca

File tree

10 files changed

+117
-24
lines changed

10 files changed

+117
-24
lines changed

.flexci/config.pbtxt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ configs {
7777
}
7878
}
7979

80+
configs {
81+
key: "pytorch-pfn-extras.torch112-linux"
82+
value {
83+
requirement {
84+
cpu: 6
85+
gpu: 2
86+
memory: 32
87+
disk: 10
88+
}
89+
time_limit: {
90+
seconds: 1200
91+
}
92+
command: "bash .flexci/linux/script.sh torch112"
93+
}
94+
}
95+
8096
configs {
8197
key: "pytorch-pfn-extras.torch18-win"
8298
value {
@@ -144,3 +160,20 @@ configs {
144160
command: ".flexci\\windows\\run.bat torch111"
145161
}
146162
}
163+
164+
configs {
165+
key: "pytorch-pfn-extras.torch112-win"
166+
value {
167+
requirement {
168+
cpu: 4
169+
gpu: 2
170+
memory: 24
171+
disk: 10
172+
image: "windows"
173+
}
174+
time_limit: {
175+
seconds: 1200
176+
}
177+
command: ".flexci\\windows\\run.bat torch112"
178+
}
179+
}

.flexci/linux/build_and_push.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ "${IMAGE_BASE}" = "" ]; then
88
fi
99

1010
TEST_PIP_PACKAGES="
11-
matplotlib tensorboard ipython ipywidgets pandas optuna onnx onnxruntime
11+
matplotlib tensorboard ipython ipywidgets pandas optuna onnxruntime
1212
pytest flake8 pysen[lint] pytest-cov
1313
"
1414

@@ -34,7 +34,7 @@ docker_build_and_push torch18 \
3434
--build-arg base_image="nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04" \
3535
--build-arg python_version="3.6.9" \
3636
--build-arg pip_install_torch_args="torch==1.8.* torchvision==0.9.* -f https://download.pytorch.org/whl/cu102/torch_stable.html" \
37-
--build-arg pip_install_dep_args="cupy-cuda102 pytorch-ignite ${TEST_PIP_PACKAGES}" \
37+
--build-arg pip_install_dep_args="cupy-cuda102 pytorch-ignite onnx==1.11.0 ${TEST_PIP_PACKAGES}" \
3838
&
3939
WAIT_PIDS="$! ${WAIT_PIDS}"
4040

@@ -43,7 +43,7 @@ docker_build_and_push torch19 \
4343
--build-arg base_image="nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04" \
4444
--build-arg python_version="3.9.5" \
4545
--build-arg pip_install_torch_args="torch==1.9.* torchvision==0.10.* -f https://download.pytorch.org/whl/cu102/torch_stable.html" \
46-
--build-arg pip_install_dep_args="cupy-cuda102 pytorch-ignite ${TEST_PIP_PACKAGES}" \
46+
--build-arg pip_install_dep_args="cupy-cuda102 pytorch-ignite onnx ${TEST_PIP_PACKAGES}" \
4747
&
4848
WAIT_PIDS="$! ${WAIT_PIDS}"
4949

@@ -52,16 +52,31 @@ docker_build_and_push torch110 \
5252
--build-arg base_image="nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04" \
5353
--build-arg python_version="3.9.7" \
5454
--build-arg pip_install_torch_args="torch==1.10.* torchvision==0.11.* -f https://download.pytorch.org/whl/cu113/torch_stable.html" \
55-
--build-arg pip_install_dep_args="cupy-cuda113 pytorch-ignite ${TEST_PIP_PACKAGES}" \
55+
--build-arg pip_install_dep_args="cupy-cuda113 pytorch-ignite onnx ${TEST_PIP_PACKAGES}" \
5656
&
5757
WAIT_PIDS="$! ${WAIT_PIDS}"
5858

59+
# Wait until the build complete.
60+
for P in ${WAIT_PIDS}; do
61+
wait ${P}
62+
done
63+
WAIT_PIDS=""
64+
5965
# PyTorch 1.11 + Python 3.9
6066
docker_build_and_push torch111 \
6167
--build-arg base_image="nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04" \
6268
--build-arg python_version="3.9.7" \
6369
--build-arg pip_install_torch_args="torch==1.11.* torchvision==0.12.* -f https://download.pytorch.org/whl/cu113/torch_stable.html" \
64-
--build-arg pip_install_dep_args="cupy-cuda113 pytorch-ignite ${TEST_PIP_PACKAGES}" \
70+
--build-arg pip_install_dep_args="cupy-cuda113 pytorch-ignite onnx ${TEST_PIP_PACKAGES}" \
71+
&
72+
WAIT_PIDS="$! ${WAIT_PIDS}"
73+
74+
# PyTorch 1.12 + Python 3.9
75+
docker_build_and_push torch112 \
76+
--build-arg base_image="nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04" \
77+
--build-arg python_version="3.9.7" \
78+
--build-arg pip_install_torch_args="torch==1.12.* torchvision==0.13.* -f https://download.pytorch.org/whl/cu113/torch_stable.html" \
79+
--build-arg pip_install_dep_args="cupy-cuda113 pytorch-ignite onnx ${TEST_PIP_PACKAGES}" \
6580
&
6681
WAIT_PIDS="$! ${WAIT_PIDS}"
6782

.flexci/windows/test.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ if ($test -eq "torch18") {
3737
RunOrDie python -m pip install -U pip "setuptools<59.6"
3838
RunOrDieWithRetry 3 python -m pip install torch==1.11.* torchvision==0.12.* -f https://download.pytorch.org/whl/cu113/torch_stable.html
3939

40+
} elseif ($test -eq "torch112") {
41+
# PyTorch 1.12 + Python 3.9
42+
ActivateCUDA 11.3
43+
ActivatePython 3.9
44+
RunOrDie python -m pip install -U pip "setuptools<59.6"
45+
RunOrDieWithRetry 3 python -m pip install torch==1.12.* torchvision==0.13.* -f https://download.pytorch.org/whl/cu113/torch_stable.html
46+
4047
} else {
4148
throw "Unsupported test variant: $test"
4249
}

.github/CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* @asi1024 @emcastillo @kmaehashi
2-
/pytorch_pfn_extras/onnx @take-cheeze @okdshin
3-
/tests/pytorch_pfn_extras_tests/onnx @take-cheeze @okdshin
2+
/pytorch_pfn_extras/onnx @xuzijian629 @okdshin
3+
/tests/pytorch_pfn_extras_tests/onnx @xuzijian629 @okdshin

.github/workflows/pretest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-18.04
88
strategy:
99
matrix:
10-
torch: ['1.8.*', '1.9.*', '1.10.*', '1.11.*']
10+
torch: ['1.8.*', '1.9.*', '1.10.*', '1.11.*', '1.12.*']
1111

1212
steps:
1313
- name: Checkout
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytorch_pfn_extras
2+
import torch.onnx
3+
import torch.onnx.symbolic_helper
4+
5+
if pytorch_pfn_extras.requires("1.12.0"):
6+
from torch.onnx._constants import * # NOQA
7+
else:
8+
onnx_default_opset = torch.onnx.symbolic_helper._default_onnx_opset_version
9+
onnx_main_opset = torch.onnx.symbolic_helper._onnx_main_opset
10+
onnx_stable_opsets = torch.onnx.symbolic_helper._onnx_stable_opsets
11+
onnx_constant_folding_opsets = torch.onnx.symbolic_helper._constant_folding_opset_versions if pytorch_pfn_extras.requires("1.11.0") else torch.onnx.constant_folding_opset_versions # type: ignore[attr-defined]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytorch_pfn_extras
2+
import torch
3+
import torch.onnx.symbolic_helper
4+
from typing import Optional
5+
6+
7+
class _InternalGlobalsBeforeTorch1_11:
8+
@property
9+
def export_onnx_opset_version(self) -> int:
10+
return torch.onnx.symbolic_helper._export_onnx_opset_version
11+
12+
@property
13+
def operator_export_type(self) -> Optional[torch._C._onnx.OperatorExportTypes]:
14+
return torch.onnx.symbolic_helper._operator_export_type
15+
16+
@property
17+
def training_mode(self) -> Optional[torch._C._onnx.TrainingMode]:
18+
return torch.onnx.symbolic_helper._training_mode
19+
20+
@property
21+
def onnx_shape_inference(self) -> bool:
22+
return torch.onnx.symbolic_helper._onnx_shape_inference
23+
24+
25+
if pytorch_pfn_extras.requires("1.12.0"):
26+
import torch.onnx._globals
27+
GLOBALS = torch.onnx._globals.GLOBALS
28+
else:
29+
GLOBALS = _InternalGlobalsBeforeTorch1_11()

pytorch_pfn_extras/onnx/export_testcase.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import onnx
1212
import onnx.numpy_helper
1313
import pytorch_pfn_extras
14+
import pytorch_pfn_extras.onnx._constants
1415
import torch
1516
import torch.autograd
1617
from torch.onnx import OperatorExportTypes
@@ -151,12 +152,7 @@ def _export(
151152
bytesio = io.BytesIO()
152153
opset_ver = kwargs.get('opset_version', None)
153154
if opset_ver is None:
154-
if pytorch_pfn_extras.requires('1.12.0'):
155-
from torch.onnx._constants import onnx_default_opset
156-
opset_ver = onnx_default_opset
157-
else:
158-
from torch.onnx.symbolic_helper import _default_onnx_opset_version
159-
opset_ver = _default_onnx_opset_version
155+
opset_ver = pytorch_pfn_extras.onnx._constants.onnx_default_opset
160156
kwargs['opset_version'] = opset_ver
161157
if use_pfto or not pytorch_pfn_extras.requires('1.10.0'):
162158
strip_doc_string = kwargs.get('strip_doc_string', True)

pytorch_pfn_extras/onnx/pfto_exporter/export.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import onnx.numpy_helper
1010
import onnx.shape_inference
1111
import pytorch_pfn_extras
12+
import pytorch_pfn_extras.onnx._constants
13+
from pytorch_pfn_extras.onnx._globals import GLOBALS
1214
import torch
1315
import torch.jit
1416
import torch.onnx.symbolic_helper as sym_hel
@@ -316,11 +318,7 @@ def optimize_onnx(self, graph: torch._C.Graph) -> torch._C.Graph:
316318
else:
317319
self.run_jit_pass(torch._C._jit_pass_onnx_scalar_type_analysis, graph)
318320

319-
opset_versions = (
320-
sym_hel._constant_folding_opset_versions # type: ignore[attr-defined]
321-
if pytorch_pfn_extras.requires("1.11.0")
322-
else torch.onnx.constant_folding_opset_versions) # type: ignore[attr-defined]
323-
if self.do_constant_folding and self.opset_version in opset_versions:
321+
if self.do_constant_folding and self.opset_version in pytorch_pfn_extras.onnx._constants.onnx_constant_folding_opsets:
324322
folded: Dict[str, torch.IValue] = torch._C._jit_pass_onnx_constant_fold( # type: ignore[attr-defined]
325323
graph, self.vars, self.opset_version
326324
)
@@ -502,6 +500,8 @@ def run_symbolic_function(self, g: torch._C.Graph, n: torch._C.Node, sym_func: C
502500
node_inputs = list(n.inputs())
503501
if n.kind() == "prim::PythonOp":
504502
node_inputs.extend(n.scalar_args())
503+
if "module" in attrs:
504+
del attrs["module"]
505505
sym_outs = _to_tuple_if_not_sequence(sym_func(g, *node_inputs, **attrs))
506506
assert len(sym_outs) == n.outputsSize(), f"{sym_outs}: {len(sym_outs)} vs {n.outputsSize()}"
507507

@@ -829,6 +829,8 @@ def apply_dynamic_axes_info(out: onnx.ValueInfoProto, k: str) -> None:
829829
inout_names.append(k)
830830
onnx_outputs.append(onnx_value(v, k))
831831
if idx < len(self.outputs):
832+
if isinstance(self.outputs[idx], tuple):
833+
raise RuntimeError('Models returning nested lists/tuples are not supported yet')
832834
_apply_tensor_info_to_value_info(onnx_outputs[-1], self.outputs[idx])
833835
apply_dynamic_axes_info(onnx_outputs[-1], k)
834836

@@ -878,11 +880,11 @@ def _convert(self) -> None:
878880
assert not to_utils.is_in_onnx_export() # type: ignore[no-untyped-call]
879881
with to_utils.select_model_mode_for_export(self.original_model, self.training):
880882
to_utils.__IN_ONNX_EXPORT = True
881-
prev_opset_version = sym_hel._export_onnx_opset_version
883+
prev_opset_version = GLOBALS.export_onnx_opset_version
882884
sym_hel._set_opset_version(self.opset_version) # type: ignore[no-untyped-call]
883-
prev_export_type = sym_hel._operator_export_type
885+
prev_export_type = GLOBALS.operator_export_type
884886
sym_hel._set_operator_export_type(self.operator_export_type) # type: ignore[no-untyped-call]
885-
prev_shape_inference = sym_hel._onnx_shape_inference
887+
prev_shape_inference = GLOBALS.onnx_shape_inference
886888
sym_hel._set_onnx_shape_inference( # type: ignore[no-untyped-call]
887889
False # TODO(twata): Use `self.onnx_shape_inference`
888890
)

tests/pytorch_pfn_extras_tests/onnx_tests/test_export_testcase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import torch
1212
import torch.nn as nn
1313
import torch.nn.functional as F
14-
from torch.onnx.symbolic_helper import _default_onnx_opset_version
1514

1615
from pytorch_pfn_extras.onnx import export
1716
from pytorch_pfn_extras.onnx import export_testcase
1817
from pytorch_pfn_extras.onnx import is_large_tensor
1918
from pytorch_pfn_extras.onnx import LARGE_TENSOR_DATA_THRESHOLD
19+
import pytorch_pfn_extras.onnx._constants
2020
from pytorch_pfn_extras.onnx.strip_large_tensor import _strip_large_tensor_tool_impl
2121
from pytorch_pfn_extras.onnx.unstrip_tensor import unstrip
2222

@@ -45,7 +45,7 @@ def forward(self, x):
4545

4646
def _get_output_dir(d, **kwargs):
4747
output_dir_base = 'out'
48-
opset_ver = kwargs.get('opset_version', _default_onnx_opset_version)
48+
opset_ver = kwargs.get('opset_version', pytorch_pfn_extras.onnx._constants.onnx_default_opset)
4949

5050
output_dir = os.path.join(
5151
output_dir_base, 'opset{}'.format(opset_ver), d)

0 commit comments

Comments
 (0)