55import argparse
66import torch
77
8-
9-
108gpu_arch_ver = os .getenv ("GPU_ARCH_VER" )
119gpu_arch_type = os .getenv ("GPU_ARCH_TYPE" )
1210# use installation env variable to tell if it is nightly channel
1311installation_str = os .getenv ("INSTALLATION" )
1412is_cuda_system = gpu_arch_type == "cuda"
1513SCRIPT_DIR = Path (__file__ ).parent
14+ NIGHTLY_ALLOWED_DELTA = 3
1615
1716# helper function to return the conda installed packages
1817# and return package we are insterseted in
@@ -35,32 +34,31 @@ def get_anaconda_output_for_package(pkg_name_str):
3534
3635
3736def check_nightly_binaries_date (package : str ) -> None :
37+ from datetime import datetime , timedelta
38+ format_dt = '%Y%m%d'
39+
3840 torch_str = torch .__version__
3941 date_t_str = re .findall ("dev\d+" , torch .__version__ )
42+ date_t_delta = datetime .now () - datetime .strptime (date_t_str .lstrip ("dev" ), format_dt )
43+ if date_t_delta .days >= NIGHTLY_ALLOWED_DELTA :
44+ raise RuntimeError (
45+ f"the binaries are from { date_t_str } and are more than { NIGHTLY_ALLOWED_DELTA } days old!"
46+ )
4047
4148 if (package == "all" ):
4249 ta_str = torchaudio .__version__
4350 tv_str = torchvision .__version__
4451 date_ta_str = re .findall ("dev\d+" , torchaudio .__version__ )
4552 date_tv_str = re .findall ("dev\d+" , torchvision .__version__ )
53+ date_ta_delta = datetime .now () - datetime .strptime (date_ta_str .lstrip ("dev" ), format_dt )
54+ date_tv_delta = datetime .now () - datetime .strptime (date_tv_str .lstrip ("dev" ), format_dt )
4655
4756 # check that the above three lists are equal and none of them is empty
48- if not date_t_str or not date_t_str == date_ta_str == date_tv_str :
57+ if date_ta_delta . days > NIGHTLY_ALLOWED_DELTA or date_tv_delta . days > NIGHTLY_ALLOWED_DELTA :
4958 raise RuntimeError (
50- f"Expected torch, torchaudio, torchvision to be the same date . But they are from { date_t_str } , { date_ta_str } , { date_tv_str } respectively"
59+ f"Expected torchaudio, torchvision to be less then { NIGHTLY_ALLOWED_DELTA } days . But they are from { date_ta_str } , { date_tv_str } respectively"
5160 )
5261
53- # check that the date is recent, at this point, date_torch_str is not empty
54- binary_date_str = date_t_str [0 ][3 :]
55- from datetime import datetime
56-
57- binary_date_obj = datetime .strptime (binary_date_str , "%Y%m%d" ).date ()
58- today_obj = datetime .today ().date ()
59- delta = today_obj - binary_date_obj
60- if delta .days >= 2 :
61- raise RuntimeError (
62- f"the binaries are from { binary_date_obj } and are more than 2 days old!"
63- )
6462
6563def smoke_test_cuda (package : str ) -> None :
6664 if not torch .cuda .is_available () and is_cuda_system :
@@ -76,6 +74,8 @@ def smoke_test_cuda(package: str) -> None:
7674 print (f"cuDNN enabled? { torch .backends .cudnn .enabled } " )
7775
7876 if (package == 'all' ):
77+ import torchaudio
78+ import torchvision
7979 if installation_str .find ("nightly" ) != - 1 :
8080 # just print out cuda version, as version check were already performed during import
8181 print (f"torchvision cuda: { torch .ops .torchvision ._cuda_version ()} " )
@@ -165,6 +165,7 @@ def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None:
165165
166166
167167def smoke_test_torchaudio () -> None :
168+ import torchaudio
168169 import torchaudio .compliance .kaldi # noqa: F401
169170 import torchaudio .datasets # noqa: F401
170171 import torchaudio .functional # noqa: F401
@@ -184,20 +185,18 @@ def main() -> None:
184185 choices = ["all" , "torchonly" ],
185186 default = "all" ,
186187 )
187-
188+ options = parser . parse_args ()
188189 print (f"torch: { torch .__version__ } " )
190+
189191 smoke_test_cuda (options .package )
190192 smoke_test_conv2d ()
191193
192194 # only makes sense to check nightly package where dates are known
193195 if installation_str .find ("nightly" ) != - 1 :
194- check_nightly_binaries_date ()
196+ check_nightly_binaries_date (options . package )
195197
196198 if options .package == "all" :
197199 import torchaudio
198- # the following import would invoke
199- # _check_cuda_version()
200- # via torchvision.extension._check_cuda_version()
201200 import torchvision
202201 print (f"torchvision: { torchvision .__version__ } " )
203202 print (f"torchaudio: { torchaudio .__version__ } " )
0 commit comments