1
1
import os
2
+ import re
2
3
import sys
3
4
import torch
5
+ # the following import would invoke
6
+ # _check_cuda_version()
7
+ # via torchvision.extension._check_cuda_version()
4
8
import torchvision
5
9
import torchaudio
6
10
from pathlib import Path
7
11
8
12
gpu_arch_ver = os .getenv ("GPU_ARCH_VER" )
9
13
gpu_arch_type = os .getenv ("GPU_ARCH_TYPE" )
14
+ # use installation env variable to tell if it is nightly channel
15
+ installation_str = os .getenv ("INSTALLATION" )
10
16
is_cuda_system = gpu_arch_type == "cuda"
11
17
SCRIPT_DIR = Path (__file__ ).parent
12
18
19
+ # helper function to return the conda list output, e.g.
20
+ # torchaudio 0.13.0.dev20220922 py39_cu102 pytorch-nightly
21
+ def get_anaconda_output_for_package (pkg_name_str ):
22
+ import subprocess as sp
23
+
24
+ # ignore the header row:
25
+ # Name Version Build Channel
26
+ cmd = 'conda list -f ' + pkg_name_str
27
+ output = sp .getoutput (cmd )
28
+ # Get the last line only
29
+ return output .strip ().split ('\n ' )[- 1 ]
30
+
31
+ def check_nightly_binaries_date () -> None :
32
+ torch_str = torch .__version__
33
+ ta_str = torchaudio .__version__
34
+ tv_str = torchvision .__version__
35
+
36
+ date_t_str = re .findall ('dev\d+' , torch .__version__ )
37
+ date_ta_str = re .findall ('dev\d+' , torchaudio .__version__ )
38
+ date_tv_str = re .findall ('dev\d+' , torchvision .__version__ )
39
+
40
+ # check that the above three lists are equal and none of them is empty
41
+ if not date_t_str or not date_t_str == date_ta_str == date_tv_str :
42
+ raise RuntimeError (f"Expected torch, torchaudio, torchvision to be the same date. But they are from { date_t_str } , { date_ta_str } , { date_tv_str } respectively" )
43
+
44
+ # check that the date is recent, at this point, date_torch_str is not empty
45
+ binary_date_str = date_t_str [0 ][3 :]
46
+ from datetime import datetime
47
+
48
+ binary_date_obj = datetime .strptime (binary_date_str , '%Y%m%d' ).date ()
49
+ today_obj = datetime .today ().date ()
50
+ delta = today_obj - binary_date_obj
51
+ if delta .days >= 2 :
52
+ raise RuntimeError (f"the binaries are from { binary_date_obj } and are more than 2 days old!" )
53
+
54
+
13
55
def smoke_test_cuda () -> None :
14
56
if (not torch .cuda .is_available () and is_cuda_system ):
15
57
raise RuntimeError (f"Expected CUDA { gpu_arch_ver } . However CUDA is not loaded." )
@@ -19,6 +61,19 @@ def smoke_test_cuda() -> None:
19
61
print (f"torch cuda: { torch .version .cuda } " )
20
62
# todo add cudnn version validation
21
63
print (f"torch cudnn: { torch .backends .cudnn .version ()} " )
64
+ print (f"cuDNN enabled? { torch .backends .cudnn .enabled } " )
65
+
66
+ if installation_str .find ('nightly' ) != - 1 :
67
+ # just print out cuda version, as version check were already performed during import
68
+ print (f"torchvision cuda: { torch .ops .torchvision ._cuda_version ()} " )
69
+ print (f"torchaudio cuda: { torch .ops .torchaudio .cuda_version ()} " )
70
+ else :
71
+ # torchaudio runtime added the cuda verison check on 09/23/2022 via
72
+ # https://github.com/pytorch/audio/pull/2707
73
+ # so relying on anaconda output for pytorch-test and pytorch channel
74
+ torchaudio_allstr = get_anaconda_output_for_package (torchaudio .__name__ )
75
+ if is_cuda_system and 'cu' + str (gpu_arch_ver ).replace ("." , "" ) not in torchaudio_allstr :
76
+ raise RuntimeError (f"CUDA version issue. Loaded: { torchaudio_allstr } Expected: { gpu_arch_ver } " )
22
77
23
78
def smoke_test_conv2d () -> None :
24
79
import torch .nn as nn
@@ -95,6 +150,11 @@ def main() -> None:
95
150
print (f"torchvision: { torchvision .__version__ } " )
96
151
print (f"torchaudio: { torchaudio .__version__ } " )
97
152
smoke_test_cuda ()
153
+
154
+ # only makes sense to check nightly package where dates are known
155
+ if installation_str .find ('nightly' ) != - 1 :
156
+ check_nightly_binaries_date ()
157
+
98
158
smoke_test_conv2d ()
99
159
smoke_test_torchaudio ()
100
160
smoke_test_torchvision ()
0 commit comments