|
10 | 10 |
|
11 | 11 | gpu_arch_ver = os.getenv("MATRIX_GPU_ARCH_VERSION")
|
12 | 12 | gpu_arch_type = os.getenv("MATRIX_GPU_ARCH_TYPE")
|
13 |
| -# use installation env variable to tell if it is nightly channel |
14 |
| -installation_str = os.getenv("MATRIX_INSTALLATION") |
| 13 | +channel = os.getenv("MATRIX_CHANNEL") |
| 14 | +stable_version = os.getenv("MATRIX_STABLE_VERSION") |
| 15 | +package_type = os.getenv("MATRIX_PACKAGE_TYPE") |
| 16 | + |
15 | 17 | is_cuda_system = gpu_arch_type == "cuda"
|
16 | 18 | SCRIPT_DIR = Path(__file__).parent
|
17 | 19 | NIGHTLY_ALLOWED_DELTA = 3
|
|
31 | 33 | },
|
32 | 34 | ]
|
33 | 35 |
|
| 36 | +def check_version(package: str) -> None: |
| 37 | + # only makes sense to check nightly package where dates are known |
| 38 | + if channel == "nightly": |
| 39 | + check_nightly_binaries_date(options.package) |
| 40 | + else: |
| 41 | + if not torch.__version__.startswith(stable_version): |
| 42 | + raise RuntimeError( |
| 43 | + f"Torch version mismatch, expected {stable_version} for channel {channel}. But its {torch.__version__}" |
| 44 | + ) |
| 45 | + |
34 | 46 | def check_nightly_binaries_date(package: str) -> None:
|
35 | 47 | from datetime import datetime, timedelta
|
36 | 48 | format_dt = '%Y%m%d'
|
@@ -58,6 +70,7 @@ def check_nightly_binaries_date(package: str) -> None:
|
58 | 70 | def test_cuda_runtime_errors_captured() -> None:
|
59 | 71 | cuda_exception_missed=True
|
60 | 72 | try:
|
| 73 | + print("Testing test_cuda_runtime_errors_captured") |
61 | 74 | torch._assert_async(torch.tensor(0, device="cuda"))
|
62 | 75 | torch._assert_async(torch.tensor(0 + 0j, device="cuda"))
|
63 | 76 | except RuntimeError as e:
|
@@ -95,29 +108,73 @@ def smoke_test_cuda(package: str) -> None:
|
95 | 108 | print(f"torch cudnn: {torch.backends.cudnn.version()}")
|
96 | 109 | print(f"cuDNN enabled? {torch.backends.cudnn.enabled}")
|
97 | 110 |
|
98 |
| - # This check has to be run last, since its messing up CUDA runtime |
| 111 | + # torch.compile is available only on Linux and python 3.8-3.10 |
| 112 | + if (sys.platform == "linux" or sys.platform == "linux2") and sys.version_info < (3, 11, 0): |
| 113 | + smoke_test_compile() |
| 114 | + |
99 | 115 | test_cuda_runtime_errors_captured()
|
100 | 116 |
|
101 | 117 |
|
102 | 118 | def smoke_test_conv2d() -> None:
|
103 | 119 | import torch.nn as nn
|
104 | 120 |
|
105 |
| - print("Calling smoke_test_conv2d") |
| 121 | + print("Testing smoke_test_conv2d") |
106 | 122 | # With square kernels and equal stride
|
107 | 123 | m = nn.Conv2d(16, 33, 3, stride=2)
|
108 | 124 | # non-square kernels and unequal stride and with padding
|
109 | 125 | m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))
|
110 | 126 | # non-square kernels and unequal stride and with padding and dilation
|
111 |
| - m = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1)) |
| 127 | + basic_conv = nn.Conv2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1)) |
112 | 128 | input = torch.randn(20, 16, 50, 100)
|
113 |
| - output = m(input) |
| 129 | + output = basic_conv(input) |
| 130 | + |
114 | 131 | if is_cuda_system:
|
115 | 132 | print("Testing smoke_test_conv2d with cuda")
|
116 | 133 | conv = nn.Conv2d(3, 3, 3).cuda()
|
117 | 134 | x = torch.randn(1, 3, 24, 24).cuda()
|
118 | 135 | with torch.cuda.amp.autocast():
|
119 | 136 | out = conv(x)
|
120 | 137 |
|
| 138 | + supported_dtypes = [torch.float16, torch.float32, torch.float64] |
| 139 | + for dtype in supported_dtypes: |
| 140 | + print(f"Testing smoke_test_conv2d with cuda for {dtype}") |
| 141 | + conv = basic_conv.to(dtype).cuda() |
| 142 | + input = torch.randn(20, 16, 50, 100, device="cuda").type(dtype) |
| 143 | + output = conv(input) |
| 144 | + |
| 145 | +def smoke_test_linalg() -> None: |
| 146 | + print("Testing smoke_test_linalg") |
| 147 | + A = torch.randn(5, 3) |
| 148 | + U, S, Vh = torch.linalg.svd(A, full_matrices=False) |
| 149 | + U.shape, S.shape, Vh.shape |
| 150 | + torch.dist(A, U @ torch.diag(S) @ Vh) |
| 151 | + |
| 152 | + U, S, Vh = torch.linalg.svd(A) |
| 153 | + U.shape, S.shape, Vh.shape |
| 154 | + torch.dist(A, U[:, :3] @ torch.diag(S) @ Vh) |
| 155 | + |
| 156 | + A = torch.randn(7, 5, 3) |
| 157 | + U, S, Vh = torch.linalg.svd(A, full_matrices=False) |
| 158 | + torch.dist(A, U @ torch.diag_embed(S) @ Vh) |
| 159 | + |
| 160 | + if is_cuda_system: |
| 161 | + supported_dtypes = [torch.float32, torch.float64] |
| 162 | + for dtype in supported_dtypes: |
| 163 | + print(f"Testing smoke_test_linalg with cuda for {dtype}") |
| 164 | + A = torch.randn(20, 16, 50, 100, device="cuda").type(dtype) |
| 165 | + torch.linalg.svd(A) |
| 166 | + |
| 167 | +def smoke_test_compile() -> None: |
| 168 | + supported_dtypes = [torch.float16, torch.float32, torch.float64] |
| 169 | + def foo(x: torch.Tensor) -> torch.Tensor: |
| 170 | + return torch.sin(x) + torch.cos(x) |
| 171 | + for dtype in supported_dtypes: |
| 172 | + print(f"Testing smoke_test_compile for {dtype}") |
| 173 | + x = torch.rand(3, 3, device="cuda").type(dtype) |
| 174 | + x_eager = foo(x) |
| 175 | + x_pt2 = torch.compile(foo)(x) |
| 176 | + print(torch.allclose(x_eager, x_pt2)) |
| 177 | + |
121 | 178 |
|
122 | 179 | def smoke_test_modules():
|
123 | 180 | for module in MODULES:
|
@@ -146,15 +203,13 @@ def main() -> None:
|
146 | 203 | )
|
147 | 204 | options = parser.parse_args()
|
148 | 205 | print(f"torch: {torch.__version__}")
|
| 206 | + check_version(options.package) |
149 | 207 | smoke_test_conv2d()
|
| 208 | + smoke_test_linalg() |
150 | 209 |
|
151 | 210 | if options.package == "all":
|
152 | 211 | smoke_test_modules()
|
153 | 212 |
|
154 |
| - # only makes sense to check nightly package where dates are known |
155 |
| - if installation_str.find("nightly") != -1: |
156 |
| - check_nightly_binaries_date(options.package) |
157 |
| - |
158 | 213 | smoke_test_cuda(options.package)
|
159 | 214 |
|
160 | 215 |
|
|
0 commit comments