Mehdi commited on
Commit Β·
5fa3ac9
1
Parent(s): 2c3748a
fix: verify Hub write access before training, fallback to user namespace
Browse files115 unmodified lines11611711811912012186 unmodified lines208209210211212213214215216217218219220221222115 unmodified linestoken = os.environ["HF_TOKEN"]# ββ Data: SQuAD β production prompt format ββββββββββββββββββββββββββββprint("[data] loading SQuADβ¦")ds = load_dataset("squad", split="train")86 unmodified linesmerged = PeftModel.from_pretrained(base, "/tmp/adapter")merged = merged.merge_and_unload()print(f"[push] uploading to {HUB_REPO}β¦")merged.push_to_hub(HUB_REPO, token=token, private=False)tokenizer.push_to_hub(HUB_REPO, token=token)HfApi(token=token).upload_file(path_or_fileobj=MODEL_CARD.encode(),path_in_repo="README.md",repo_id=HUB_REPO,)print(f"[done] https://huggingface.co/{HUB_REPO}")@app.local_entrypoint()115 unmodified lines11611711811912012112212312412512612712812913013113213313413513686 unmodified lines223224225226227228229230231232233234235236237115 unmodified linestoken = os.environ["HF_TOKEN"]# ββ Resolve a writable repo BEFORE burning GPU time ββββββββββββββββββfrom huggingface_hub import create_repofrom huggingface_hub.utils import HfHubHTTPErrorapi = HfApi(token=token)try:create_repo(HUB_REPO, token=token, exist_ok=True)hub_repo = HUB_REPOexcept HfHubHTTPError:user = api.whoami()["name"]hub_repo = f"{user}/{HUB_REPO.split('/')[-1]}"create_repo(hub_repo, token=token, exist_ok=True)print(f"[push] no write access to {HUB_REPO}, falling back to {hub_repo}")print(f"[push] target repo: {hub_repo}")# ββ Data: SQuAD β production prompt format ββββββββββββββββββββββββββββprint("[data] loading SQuADβ¦")ds = load_dataset("squad", split="train")86 unmodified linesmerged = PeftModel.from_pretrained(base, "/tmp/adapter")merged = merged.merge_and_unload()print(f"[push] uploading to {hub_repo}β¦")merged.push_to_hub(hub_repo, token=token, private=False)tokenizer.push_to_hub(hub_repo, token=token)api.upload_file(path_or_fileobj=MODEL_CARD.replace(HUB_REPO, hub_repo).encode(),path_in_repo="README.md",repo_id=hub_repo,)print(f"[done] https://huggingface.co/{hub_repo}")@app.local_entrypoint()
finetune/train_modal.py+22-7