File size: 2,308 Bytes
2ffbcc3 446f0f1 2ffbcc3 446f0f1 2ffbcc3 ee81159 d12f14b 2ffbcc3 d12f14b 2ffbcc3 a181675 2ffbcc3 ee81159 25e5dc9 | 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 50 51 | import os
from fastapi import FastAPI
import subprocess
import wandb
from huggingface_hub import HfApi
TOKEN = os.environ.get("DATACOMP_TOKEN")
API = HfApi(token=TOKEN)
wandb_api_key = os.environ.get('wandb_api_key')
wandb.login(key=wandb_api_key)
random_num = 10.0
subset = 'frac-1over64'
experiment_name = f"datacomp/ImageNetTraining{random_num}-{subset}"
app = FastAPI()
@app.get("/")
def start_train():
os.system("echo '#### pwd'")
os.system("pwd")
os.system("echo '#### ls'")
os.system("ls")
# Create a place to put the output.
os.system("echo 'Creating results output repository in case it does not exist yet...'")
try:
API.create_repo(repo_id=f"{experiment_name}", repo_type="dataset",)
os.system(f"echo 'Created results output repository {experiment_name}'")
except:
os.system("echo 'Already there; skipping.'")
pass
# Mark that training is happening so any refresh of the Space doesn't start training again.
#space_variables = API.get_space_variables(repo_id=experiment_name)
#os.system("echo 'Here are the space variables'")
#for key, value in space_variables.items():
# os.system(f"echo '{key}: {value}'")
#if 'STATUS' not in space_variables or space_variables['STATUS'].value != 'COMPUTING':
os.system("echo 'Beginning processing.'")
# API.add_space_variable(repo_id=experiment_name, key='STATUS', value='COMPUTING')
# Handles CUDA OOM errors.
os.system(f"export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True")
os.system("echo 'Okay, trying training.'")
os.system(f"cd pytorch-image-models; ./train.sh 4 --dataset hfds/datacomp/imagenet-1k-random-{random_num}-{subset} --log-wandb --experiment {experiment_name} --model seresnet34 --sched cosine --epochs 150 --warmup-epochs 5 --lr 0.4 --reprob 0.5 --remode pixel --batch-size 256 --amp -j 4")
os.system("echo 'Done'.")
# Mark that we're not computing anymore
# API.add_space_variable(repo_id=experiment_name, key='STATUS', value='NOT_COMPUTING')
os.system("ls")
# Upload output to repository
os.system("echo 'trying to upload...'")
API.upload_folder(folder_path="/app", repo_id=f"{experiment_name}", repo_type="dataset",)
# API.pause_space(experiment_name)
return {"Completed": "!"} |