3
3
import torch
4
4
import torchvision
5
5
import torchaudio
6
+ import pathlib
6
7
7
8
gpu_arch_ver = os .getenv ('GPU_ARCH_VER' )
8
9
gpu_arch_type = os .getenv ('GPU_ARCH_TYPE' )
9
- is_cuda_system = gpu_arch_type == " cuda"
10
+ is_cuda_system = gpu_arch_type == ' cuda'
10
11
11
12
def smoke_test_cuda () -> None :
12
13
if (not torch .cuda .is_available () and is_cuda_system ):
13
- print (f"Expected CUDA { gpu_arch_ver } . However CUDA is not loaded." )
14
- sys .exit (1 )
14
+ raise RuntimeError (f'Expected CUDA { gpu_arch_ver } . However CUDA is not loaded.' )
15
15
if (torch .cuda .is_available ()):
16
16
if (torch .version .cuda != gpu_arch_ver ):
17
- print (f"Wrong CUDA version. Loaded: { torch .version .cuda } Expected: { gpu_arch_ver } " )
18
- sys .exit (1 )
19
- y = torch .randn ([3 ,5 ]).cuda ()
20
- print (f"torch cuda: { torch .version .cuda } " )
17
+ raise RuntimeError (f'Wrong CUDA version. Loaded: { torch .version .cuda } Expected: { gpu_arch_ver } ' )
18
+ print (f'torch cuda: { torch .version .cuda } ' )
21
19
#todo add cudnn version validation
22
- print (f" torch cudnn: { torch .backends .cudnn .version ()} " )
20
+ print (f' torch cudnn: { torch .backends .cudnn .version ()} ' )
23
21
24
22
def smoke_test_conv2d () -> None :
25
23
import torch .nn as nn
26
- print (f" Calling smoke_test_conv2d" )
24
+ print (' Calling smoke_test_conv2d' )
27
25
# With square kernels and equal stride
28
26
m = nn .Conv2d (16 , 33 , 3 , stride = 2 )
29
27
# non-square kernels and unequal stride and with padding
@@ -33,29 +31,28 @@ def smoke_test_conv2d() -> None:
33
31
input = torch .randn (20 , 16 , 50 , 100 )
34
32
output = m (input )
35
33
if (is_cuda_system ):
36
- print (f" Testing smoke_test_conv2d with cuda" )
34
+ print (' Testing smoke_test_conv2d with cuda' )
37
35
conv = nn .Conv2d (3 , 3 , 3 ).cuda ()
38
36
x = torch .randn (1 , 3 , 24 , 24 ).cuda ()
39
37
with torch .cuda .amp .autocast ():
40
38
out = conv (x )
41
- print (out .sum ())
42
39
43
40
def smoke_test_torchvision () -> None :
44
- import torchvision .datasets as dset
45
- import torchvision .transforms
46
- from torchvision .io import read_file , decode_jpeg , decode_png
47
41
print ('Is torchvision useable?' , all (x is not None for x in [torch .ops .image .decode_png , torch .ops .torchvision .roi_align ]))
48
- img_jpg = read_file ('./test/smoke_test/assets/rgb_pytorch.jpg' )
49
- img_jpg_nv = decode_jpeg (img_jpg )
50
- img_png = read_file ('./test/smoke_test/assets/rgb_pytorch.png' )
51
- img__png_nv = decode_png (img_png )
52
42
53
- def smoke_test_vision_resnet50_classify () -> None :
43
+ def smoke_test_torchvision_read_decode () -> None :
44
+ from torchvision .io import decode_image , read_image ,
45
+ img_jpg = read_image (str (pathlib .Path (__file__ ).parent / 'assets' / 'rgb_pytorch.jpg' ))
46
+ img_jpg_nv = decode_image (img_jpg )
47
+ img_png = read_image (str (pathlib .Path (__file__ ).parent / 'assets' / 'rgb_pytorch.png' ))
48
+ assert img_png .ndim == 3 and img_png .numel () > 100
49
+ img_png_nv = decode_image (img_png )
50
+
51
+ def smoke_test_torchvision_resnet50_classify () -> None :
54
52
from torchvision .io import read_image
55
53
from torchvision .models import resnet50 , ResNet50_Weights
56
54
57
- img = read_image ("./test/smoke_test/assets/dog2.jpg" )
58
-
55
+ img = read_image (str (pathlib .Path (__file__ ).parent / 'assets' / 'dog2.jpg' ))
59
56
# Step 1: Initialize model with the best available weights
60
57
weights = ResNet50_Weights .DEFAULT
61
58
model = resnet50 (weights = weights )
@@ -71,12 +68,11 @@ def smoke_test_vision_resnet50_classify() -> None:
71
68
prediction = model (batch ).squeeze (0 ).softmax (0 )
72
69
class_id = prediction .argmax ().item ()
73
70
score = prediction [class_id ].item ()
74
- category_name = weights .meta [" categories" ][class_id ]
75
- expected_category = " German shepherd"
76
- print (f" { category_name } : { 100 * score :.1f} %" )
71
+ category_name = weights .meta [' categories' ][class_id ]
72
+ expected_category = ' German shepherd'
73
+ print (f' { category_name } : { 100 * score :.1f} %' )
77
74
if (category_name != expected_category ):
78
- print (f"Failed ResNet50 classify { category_name } Expected: { expected_category } " )
79
- sys .exit (1 )
75
+ raise RuntimeError (f'Failed ResNet50 classify { category_name } Expected: { expected_category } ' )
80
76
81
77
82
78
def smoke_test_torchaudio () -> None :
@@ -92,14 +88,15 @@ def smoke_test_torchaudio() -> None:
92
88
93
89
def main () -> None :
94
90
#todo add torch, torchvision and torchaudio tests
95
- print (f" torch: { torch .__version__ } " )
96
- print (f" torchvision: { torchvision .__version__ } " )
97
- print (f" torchaudio: { torchaudio .__version__ } " )
91
+ print (f' torch: { torch .__version__ } ' )
92
+ print (f' torchvision: { torchvision .__version__ } ' )
93
+ print (f' torchaudio: { torchaudio .__version__ } ' )
98
94
smoke_test_cuda ()
99
95
smoke_test_conv2d ()
100
- smoke_test_torchvision ()
101
96
smoke_test_torchaudio ()
102
- smoke_test_vision_resnet50_classify ()
97
+ smoke_test_torchvision ()
98
+ smoke_test_torchvision_read_decode ()
99
+ smoke_test_torchvision_resnet50_classify ()
103
100
104
- if __name__ == " __main__" :
101
+ if __name__ == ' __main__' :
105
102
main ()
0 commit comments