Upload code/train.py with huggingface_hub
Browse files13 unmodified lines14151617181920246 unmodified lines26726826927027127227327427527627727813 unmodified linesfrom datetime import timedeltadef setup_ddp():dist.init_process_group(backend="nccl", timeout=timedelta(minutes=30))rank = dist.get_rank()local_rank = int(os.environ["LOCAL_RANK"])world_size = dist.get_world_size()246 unmodified linesckpt_path = f"{WORK}/{CKPT_SUBFOLDER}/ckpt_latest.pt"# Step 1: Only Rank 0 downloads the checkpoint from Hugging Faceif IS_MAIN:try:log(f"📥 Checking and downloading latest checkpoint from {CKPT_REPO}...")with_retry(hf_hub_download, CKPT_REPO, f"{CKPT_SUBFOLDER}/ckpt_latest.pt", repo_type="model",local_dir=WORK, token=HF_TOKEN)except Exception as e:log(f"No checkpoint found on HF — starting fresh. ({type(e).__name__})")# Step 2: Synchronize all processes so file is 100% written to diskif world_size > 1:13 unmodified lines14151617181920246 unmodified lines26726826927027127227327427527627727827928028113 unmodified linesfrom datetime import timedeltadef setup_ddp():dist.init_process_group(backend="nccl", timeout=timedelta(minutes=60))rank = dist.get_rank()local_rank = int(os.environ["LOCAL_RANK"])world_size = dist.get_world_size()246 unmodified linesckpt_path = f"{WORK}/{CKPT_SUBFOLDER}/ckpt_latest.pt"# Step 1: Only Rank 0 downloads the checkpoint from Hugging Faceif IS_MAIN:if os.path.exists(ckpt_path) and os.path.getsize(ckpt_path) > 5 * (1024**3):log(f"✅ Checkpoint already present locally ({os.path.getsize(ckpt_path)/(1024**3):.2f} GB). Skipping download!")else:try:log(f"📥 Checking and downloading latest checkpoint from {CKPT_REPO}...")with_retry(hf_hub_download, CKPT_REPO, f"{CKPT_SUBFOLDER}/ckpt_latest.pt", repo_type="model",local_dir=WORK, token=HF_TOKEN)except Exception as e:log(f"No checkpoint found on HF — starting fresh. ({type(e).__name__})")# Step 2: Synchronize all processes so file is 100% written to diskif world_size > 1:
code/train.py+10-7