onnx/test.sh: Run test/onnx in only shard 1 (#65722)

Summary:
Fixes https://github.com/pytorch/pytorch/issues/65458

Pull Request resolved: https://github.com/pytorch/pytorch/pull/65722

Reviewed By: albanD

Differential Revision: D31223236

Pulled By: janeyx99

fbshipit-source-id: 3b648cb940a95866f465b27b8bdc74b06d258140
diff --git a/scripts/onnx/test.sh b/scripts/onnx/test.sh
index f39d4f0..463d379 100755
--- a/scripts/onnx/test.sh
+++ b/scripts/onnx/test.sh
@@ -49,23 +49,23 @@
   args+=("3")
 fi
 
-# These exclusions are for tests that take a long time / a lot of GPU
-# memory to run; they should be passing (and you will test them if you
-# run them locally
-pytest "${args[@]}" \
-  --ignore "$top_dir/test/onnx/test_pytorch_onnx_onnxruntime.py" \
-  --ignore "$top_dir/test/onnx/test_custom_ops.py" \
-  --ignore "$top_dir/test/onnx/test_models_onnxruntime.py" \
-  --ignore "$top_dir/test/onnx/test_utility_funs.py" \
-  --ignore "$top_dir/test/onnx/test_pytorch_onnx_caffe2.py" \
-  --ignore "$top_dir/test/onnx/test_pytorch_onnx_shape_inference.py" \
-  --ignore "$top_dir/test/onnx/test_pytorch_onnx_onnxruntime_cuda.py" \
-  --ignore "$top_dir/test/onnx/test_pytorch_onnx_caffe2_quantized.py" \
-  "${test_paths[@]}"
-
 # onnxruntime only support py3
 # "Python.h" not found in py2, needed by TorchScript custom op compilation.
 if [[ "$BUILD_ENVIRONMENT" == *ort_test1* ]]; then
+  # These exclusions are for tests that take a long time / a lot of GPU
+  # memory to run; they should be passing (and you will test them if you
+  # run them locally
+  pytest "${args[@]}" \
+    --ignore "$top_dir/test/onnx/test_pytorch_onnx_onnxruntime.py" \
+    --ignore "$top_dir/test/onnx/test_custom_ops.py" \
+    --ignore "$top_dir/test/onnx/test_models_onnxruntime.py" \
+    --ignore "$top_dir/test/onnx/test_utility_funs.py" \
+    --ignore "$top_dir/test/onnx/test_pytorch_onnx_caffe2.py" \
+    --ignore "$top_dir/test/onnx/test_pytorch_onnx_shape_inference.py" \
+    --ignore "$top_dir/test/onnx/test_pytorch_onnx_onnxruntime_cuda.py" \
+    --ignore "$top_dir/test/onnx/test_pytorch_onnx_caffe2_quantized.py" \
+    "${test_paths[@]}"
+
   pytest "${args[@]}" \
     "$top_dir/test/onnx/test_pytorch_onnx_onnxruntime.py::TestONNXRuntime_opset7" \
     "$top_dir/test/onnx/test_pytorch_onnx_onnxruntime.py::TestONNXRuntime_opset8" \
@@ -77,6 +77,7 @@
     "$top_dir/test/onnx/test_pytorch_onnx_caffe2_quantized.py" \
     "$top_dir/test/onnx/test_pytorch_onnx_shape_inference.py"
 fi
+
 if [[ "$BUILD_ENVIRONMENT" == *ort_test2* ]]; then
   # Update the loop for new opsets
   for i in $(seq 10 14); do