forked from kduxin/firelang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wandb_config.template.py
49 lines (39 loc) · 1.35 KB
/
wandb_config.template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from typing import Union
from pathlib import Path
import os
import getpass
import wandb
wandb_dir = f"/tmp/firelang_wandb_{getpass.getuser()}"
os.makedirs(wandb_dir, exist_ok=True)
settings = {
"WANDB_ENTITY": "allen", # replace this with your WANDB account name
"WANDB_DIR": wandb_dir,
# ----- cloud -----
"WANDB_API_KEY": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", # replace this with your own WANDB API KEY
"WANDB_PROJECT": "firelang", # you can change this to the name you like
"WANDB_BASE_URL": "https://api.wandb.ai/",
}
api = None
def config():
for k, v in settings.items():
os.environ[k] = v
global api
api = wandb.Api()
def download_wandb_file(runid: str, path) -> Union[str, Path]:
if api is None:
config()
run = api.run(runid)
file = run.file(path).download(f"{wandb_dir}/download-{runid}", replace=True)
print(f"Downloaded file at wandb://{runid}/{path}")
return file.name
def download_wandb_files(runid: str, path) -> Union[str, Path]:
if api is None:
config()
run = api.run(runid)
files = run.files()
save_dir = f"{wandb_dir}/download-{runid}"
for file in files:
if file.name.startswith(path):
file.download(save_dir, replace=True)
print(f"Downloaded file at wandb://{runid}/{file.name}")
return f"{save_dir}/{path}"