meg's picture
meg HF staff
Upload folder using huggingface_hub
0260398 verified
import os
import gradio as gr
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 = f"10.0"
subset = f"frac-1over4"
experiment_name = f"ImageNetTraining10.0-frac-1over4"
experiment_repo = f"datacomp/ImageNetTraining10.0-frac-1over4"
def start_train(status_box):
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"datacomp/ImageNetTraining10.0-frac-1over4", repo_type="dataset",)
os.system(f"echo 'Created results output repository datacomp/ImageNetTraining10.0-frac-1over4'")
except:
os.system("echo 'Already there; skipping.'")
pass
os.system("echo 'Beginning processing.'")
# Handles CUDA OOM errors.
os.system(f"export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True")
os.system("echo 'Okay, trying training.'")
API.add_space_variable(repo_id=experiment_repo, key="STATUS", value="TRAINING")
os.system(f"cd pytorch-image-models; ./train.sh 4 --dataset hfds/datacomp/imagenet-1k-random-10.0-frac-1over4 --log-wandb --wandb-project ImageNetTraining10.0-frac-1over4 --experiment ImageNetTraining10.0-frac-1over4 --model seresnet34 --sched cosine --epochs 150 --warmup-epochs 5 --lr 0.4 --reprob 0.5 --remode pixel --batch-size 256 --amp -j 4")
API.add_space_variable(repo_id=experiment_repo, key="STATUS", value="IDLE")
os.system("echo 'Done'.")
os.system("ls")
# Upload output to repository
os.system("echo 'trying to upload...'")
API.upload_folder(folder_path="/app", repo_id=f"datacomp/ImageNetTraining10.0-frac-1over4", repo_type="dataset",)
API.pause_space(experiment_repo)
def run():
with gr.Blocks() as app:
gr.Markdown(f"Randomization: 10.0")
gr.Markdown(f"Subset: frac-1over4")
status_box = gr.Textbox()
#space_variables = API.get_space_variables(repo_id=experiment_repo)
#if 'STATUS' not in space_variables or space_variables['STATUS'].value != 'TRAINING':
# API.add_space_variable(repo_id=experiment_repo, key="STATUS", value="IDLE")
# status_box.value = "Status: Idle"
start = gr.Button("Start")
start.click(start_train, inputs=status_box, outputs=status_box)
#else:
# status_box.value = "Status: Training"
app.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == '__main__':
run()