Download ops/sync_state.py from dragonlimited/dragon-harness: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/dragonlimited/dragon-harness/resolve/main/ops/sync_state.py
- Command line
-
hf download hf://dragonlimited/dragon-harness/ops/sync_state.py
-
curl -L -o sync_state.py https://huggingface.co/dragonlimited/dragon-harness/resolve/main/ops/sync_state.py
1.8 kB
| """Push working state to Hugging Face so a box relaunch cannot lose it. | |
| The container root is an overlay filesystem - /home/marimo does NOT survive a relaunch. | |
| Everything that matters therefore lives in dragonlimited/dragon-state as well as locally. | |
| python sync_state.py one pass | |
| python sync_state.py --watch loop, pushing every 5 minutes | |
| """ | |
| import argparse, json, os, time, pathlib | |
| import huggingface_hub as hh | |
| TOKEN=os.environ["HF_TOKEN_BOOT"] | |
| REPO="dragonlimited/dragon-state" | |
| W=pathlib.Path("/home/marimo/dragon_fsds") | |
| api=hh.HfApi(token=TOKEN) | |
| MANIFEST=json.load(open(W/"state_manifest.json")) | |
| def push(entry, label): | |
| src=W/entry | |
| if not src.exists(): return False | |
| try: | |
| api.upload_file(path_or_fileobj=str(src), path_in_repo=f"state/{entry}", | |
| repo_id=REPO, repo_type="model", | |
| commit_message=f"state: {entry}") | |
| return True | |
| except Exception as e: | |
| print(f" FAIL {label} {entry}: {type(e).__name__}", flush=True) | |
| return False | |
| def one_pass(verbose=True): | |
| ok=fail=0 | |
| for group, items in MANIFEST.items(): | |
| for it in items: | |
| if push(it, group): ok+=1 | |
| else: fail+=1 | |
| if verbose: | |
| print(f" pushed {ok}, skipped/failed {fail} {time.strftime('%H:%M:%S')}", flush=True) | |
| return ok | |
| if __name__=="__main__": | |
| ap=argparse.ArgumentParser(); ap.add_argument("--watch", action="store_true") | |
| ap.add_argument("--every", type=int, default=300) | |
| a=ap.parse_args() | |
| if a.watch: | |
| print(f"watching, pushing every {a.every}s", flush=True) | |
| while True: | |
| try: one_pass() | |
| except Exception as e: print("pass failed:", e, flush=True) | |
| time.sleep(a.every) | |
| else: | |
| one_pass() | |