1
1
#!/usr/bin/env python3
2
- # Downloads domain library packages from channel
2
+ # Downloads domain pytorch and library packages from channel
3
3
# And backs them up to S3
4
4
# Do not use unless you know what you are doing
5
+ # Usage: python backup_conda.py --version 1.6.0
5
6
6
7
import conda .api
7
8
import boto3
8
9
from typing import List , Optional
9
10
import urllib
10
11
import os
11
12
import hashlib
13
+ import argparse
12
14
13
15
S3 = boto3 .resource ('s3' )
14
16
BUCKET = S3 .Bucket ('pytorch-backup' )
@@ -23,11 +25,13 @@ def compute_md5(path:str) -> str:
23
25
def download_conda_package (package :str , version :Optional [str ] = None , depends :Optional [str ] = None , channel :Optional [str ] = None ) -> List [str ]:
24
26
packages = conda .api .SubdirData .query_all (package , channels = [channel ] if channel is not None else None , subdirs = _known_subdirs )
25
27
rc = []
28
+
26
29
for pkg in packages :
27
30
if version is not None and pkg .version != version :
28
31
continue
29
32
if depends is not None and depends not in pkg .depends :
30
33
continue
34
+
31
35
print (f"Downloading { pkg .url } ..." )
32
36
os .makedirs (pkg .subdir , exist_ok = True )
33
37
fname = f"{ pkg .subdir } /{ pkg .fn } "
@@ -50,6 +54,18 @@ def upload_to_s3(prefix: str, fnames: List[str]) -> None:
50
54
51
55
52
56
if __name__ == "__main__" :
57
+ parser = argparse .ArgumentParser ()
58
+ parser .add_argument (
59
+ "--version" ,
60
+ help = "PyTorch Version to backup" ,
61
+ type = str ,
62
+ required = True
63
+ )
64
+ options = parser .parse_args ()
65
+ rc = download_conda_package ("pytorch" , channel = "pytorch" , version = options .version )
66
+ upload_to_s3 (f"v{ options .version } /conda" , rc )
67
+
53
68
for libname in ["torchvision" , "torchaudio" , "torchtext" ]:
54
- rc = download_conda_package (libname , channel = "pytorch" , depends = "pytorch 1.9.0" )
55
- upload_to_s3 ("v1.9.0-rc4/conda" , rc )
69
+ print (f"processing { libname } " )
70
+ rc = download_conda_package (libname , channel = "pytorch" , depends = f"pytorch { options .version } " )
71
+ upload_to_s3f (f"v{ options .version } /conda" , rc )
0 commit comments