Skip to content

Commit

Permalink
[ONNX] Enable tests for opset 12 (pytorch#37846)
Browse files Browse the repository at this point in the history
Summary:
Update ORT nightly version and enable opset 12 tests.
Pull Request resolved: pytorch#37846

Reviewed By: hl475

Differential Revision: D21467903

Pulled By: houseroad

fbshipit-source-id: 20d249790edfb0091a02ebfc58c3d306087e8471
  • Loading branch information
neginraoof authored and facebook-github-bot committed May 8, 2020
1 parent 5ee2302 commit 29f19bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .jenkins/caffe2/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ if [[ "$BUILD_ENVIRONMENT" == *onnx* ]]; then
# default pip version is too old(9.0.2), unable to support tag `manylinux2010`.
# Fix the pip error: Couldn't find a version that satisfies the requirement
sudo pip install --upgrade pip
pip install -q --user -i https://test.pypi.org/simple/ ort-nightly==1.2.0.dev202004201
pip install -q --user -i https://test.pypi.org/simple/ ort-nightly==1.2.0.dev202005041
fi
"$ROOT_DIR/scripts/onnx/test.sh"
fi
30 changes: 5 additions & 25 deletions test/onnx/test_pytorch_onnx_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def forward(self, input):
self.run_model_test_with_external_data(model, x)

@skipIfUnsupportedMinOpsetVersion(9) # Because external data format was released with Opset 9.
@skipIfUnsupportedOpsetVersion([12])
def test_mobilenet_v2_with_external_data(self):
model = torchvision.models.mobilenet_v2(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
Expand All @@ -205,43 +204,36 @@ def test_alexnet(self):
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,))

@skipIfUnsupportedOpsetVersion([12])
def test_densenets(self):
model = torchvision.models.densenet121(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_googlenet(self):
model = torchvision.models.googlenet(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_inception(self):
model = torchvision.models.inception_v3(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_mnasnet(self):
model = torchvision.models.mnasnet1_0(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_mobilenet(self):
model = torchvision.models.mobilenet_v2(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_resnet(self):
model = torchvision.models.resnet50(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,))

@skipIfUnsupportedOpsetVersion([12])
def test_shufflenet(self):
model = torchvision.models.shufflenet_v2_x1_0(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
Expand All @@ -252,7 +244,6 @@ def test_squeezenet(self):
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,))

@skipIfUnsupportedOpsetVersion([12])
def test_vgg(self):
model = torchvision.models.vgg19(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
Expand All @@ -261,32 +252,27 @@ def test_vgg(self):
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedMinOpsetVersion(11)
@skipIfUnsupportedOpsetVersion([12])
def test_fcn(self):
model = torchvision.models.segmentation.segmentation.fcn_resnet101(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedMinOpsetVersion(11)
@skipIfUnsupportedOpsetVersion([12])
def test_deeplab(self):
model = torchvision.models.segmentation.segmentation.deeplabv3_resnet101(pretrained=True)
x = torch.randn(2, 3, 224, 224, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_r3d_18_video(self):
model = torchvision.models.video.r3d_18(pretrained=True)
x = torch.randn(1, 3, 4, 112, 112, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_mc3_18_video(self):
model = torchvision.models.video.mc3_18(pretrained=True)
x = torch.randn(1, 3, 4, 112, 112, requires_grad=True)
self.run_test(model, (x,), rtol=1e-3, atol=1e-5)

@skipIfUnsupportedOpsetVersion([12])
def test_r2plus1d_18_video(self):
model = torchvision.models.video.r2plus1d_18(pretrained=True)
x = torch.randn(1, 3, 4, 112, 112, requires_grad=True)
Expand Down Expand Up @@ -1393,7 +1379,6 @@ def forward(self, input):
model = StandardDeviation()
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_bitshift(self):
class BitshiftModel(torch.nn.Module):
def forward(self, input, input2):
Expand All @@ -1403,7 +1388,6 @@ def forward(self, input, input2):
input2 = torch.arange(24, dtype=torch.int64).reshape(3, 4, 2)
self.run_test(BitshiftModel(), (input, input2))

@skipIfUnsupportedOpsetVersion([12])
def test_bitshift_other_fp(self):
class BitshiftModel(torch.nn.Module):
def forward(self, input):
Expand Down Expand Up @@ -1498,7 +1482,11 @@ def forward(self, x):
def test_topk_smallest_unsorted(self):
class MyModule(torch.nn.Module):
def forward(self, x, k):
return torch.topk(x, k, largest=False, sorted=False)
# When sorted=False, order of elements in the outout tensors
# are not expected to match between PyTorch and ORT
topk_unsorted = torch.topk(x, k, largest=False, sorted=False)
topk_sorted = torch.topk(x, k, largest=False, sorted=True)
return topk_sorted, torch.sort(topk_unsorted.values).values

x = torch.arange(1., 6., requires_grad=True)
k = torch.tensor(3)
Expand All @@ -1524,13 +1512,11 @@ def forward(self, x):
x = torch.randn(3, 3)
self.run_test(Model(), x)

@skipIfUnsupportedOpsetVersion([12])
def test_layer_norm(self):
model = torch.nn.LayerNorm([10, 10])
x = torch.randn(20, 5, 10, 10)
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_batchnorm1d(self):
x = torch.randn(10, 10)
model = torch.nn.BatchNorm1d(10, affine=True)
Expand All @@ -1539,7 +1525,6 @@ def test_batchnorm1d(self):
x = torch.randn(10, 10, 128)
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_batchnorm1d_noaffine(self):
x = torch.randn(10, 10)
model = torch.nn.BatchNorm1d(10, affine=False)
Expand All @@ -1548,25 +1533,21 @@ def test_batchnorm1d_noaffine(self):
x = torch.randn(10, 10, 128)
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_batchnorm2d(self):
x = torch.randn(10, 3, 128, 128)
model = torch.nn.BatchNorm2d(3, affine=True)
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_batchnorm2d_noaffine(self):
x = torch.randn(10, 3, 128, 128)
model = torch.nn.BatchNorm2d(3, affine=False)
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_batchnorm3d(self):
x = torch.randn(10, 3, 128, 128, 128)
model = torch.nn.BatchNorm3d(3, affine=True)
self.run_test(model, x)

@skipIfUnsupportedOpsetVersion([12])
def test_batchnorm3d_noaffine(self):
x = torch.randn(10, 3, 128, 128, 128)
model = torch.nn.BatchNorm3d(3, affine=False)
Expand Down Expand Up @@ -2413,7 +2394,6 @@ def forward(self, x):
x = torch.randn(3, 4, 5, requires_grad=True)
self.run_test(MaskedScatterModel(), x)

@skipIfUnsupportedOpsetVersion([12])
@skipIfUnsupportedMinOpsetVersion(11)
def test_masked_select(self):
class MaskedSelectModel(torch.nn.Module):
Expand Down

0 comments on commit 29f19bf

Please sign in to comment.