Skip to content

Commit a754b40

Browse files
authored
Refactor conda backup script (#1350)
* Refacto conda backup * Fix space * Minor style
1 parent b2ec12f commit a754b40

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

s3_management/backup_conda.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env python3
2-
# Downloads domain library packages from channel
2+
# Downloads domain pytorch and library packages from channel
33
# And backs them up to S3
44
# Do not use unless you know what you are doing
5+
# Usage: python backup_conda.py --version 1.6.0
56

67
import conda.api
78
import boto3
89
from typing import List, Optional
910
import urllib
1011
import os
1112
import hashlib
13+
import argparse
1214

1315
S3 = boto3.resource('s3')
1416
BUCKET = S3.Bucket('pytorch-backup')
@@ -23,11 +25,13 @@ def compute_md5(path:str) -> str:
2325
def download_conda_package(package:str, version:Optional[str] = None, depends:Optional[str] = None, channel:Optional[str] = None) -> List[str]:
2426
packages = conda.api.SubdirData.query_all(package, channels = [channel] if channel is not None else None, subdirs = _known_subdirs)
2527
rc = []
28+
2629
for pkg in packages:
2730
if version is not None and pkg.version != version:
2831
continue
2932
if depends is not None and depends not in pkg.depends:
3033
continue
34+
3135
print(f"Downloading {pkg.url}...")
3236
os.makedirs(pkg.subdir, exist_ok = True)
3337
fname = f"{pkg.subdir}/{pkg.fn}"
@@ -50,6 +54,18 @@ def upload_to_s3(prefix: str, fnames: List[str]) -> None:
5054

5155

5256
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+
5368
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

Comments
 (0)