meg's picture
meg HF staff
Upload folder using huggingface_hub
44ac0b8 verified
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)
REPO_ID = f"datacomp/imagenet-1k-random-20.0-frac-1over64"
app = FastAPI()
@app.get("/")
def start_train():
os.system("echo 'Space started!'")
os.system("echo pwd")
os.system("pwd")
os.system("echo ls")
os.system("ls")
#space_variables = API.get_space_variables(repo_id=REPO_ID)
#if 'STATUS' not in space_variables or space_variables['STATUS'] != 'COMPUTING':
os.system("echo 'Beginning processing.'")
# API.add_space_variable(repo_id=REPO_ID, key='STATUS', value='COMPUTING')
# Handles CUDA OOM errors.
os.system(f"export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True")
os.system("export CUDA_LAUNCH_BLOCKING=1")
os.system("echo 'Okay, trying training.'")
os.system(f"cd pytorch-image-models; ./train.sh 4 --dataset hfds/{REPO_ID} --log-wandb --experiment {REPO_ID} --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 ls")
os.system("ls")
os.system("echo 'trying to upload...'")
API.upload_folder(folder_path="/app", repo_id=f"{REPO_ID}", repo_type="dataset",)
# API.add_space_variable(repo_id=REPO_ID, key='STATUS', value='NOT_COMPUTING')
#API.pause_space(f"{REPO_ID}")
return {"Completed": "!"}