File size: 2,049 Bytes
20689d3 3cd4c9d 20689d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | """Revert the MiniMax-H3 Space to the known-good baseline commit.
Usage:
set HF_TOKEN=hf_xxx (token with write access to the Space)
python revert_to_baseline.py
What it does:
1. Clones the Space repo (source only — model weights are fetched at runtime).
2. Fetches and hard-resets to the pinned baseline commit.
3. Force-pushes that commit to the Space's main branch (--force-with-lease,
so it refuses if the remote moved unexpectedly).
The baseline commit is pinned below. Change TARGET only if you intend to roll
forward to a different known-good commit.
"""
import os
import subprocess
import tempfile
REPO = "observantdistressed/minimax-h3"
TARGET = "cded1e52839f650000ccd8aefa2026cbadb61a0d"
def run(cmd, cwd=None):
print("+", " ".join(cmd), flush=True)
# Disable the (misconfigured) git credential manager and any interactive prompt. Auth is carried
# in the remote URL (token as both user and password), so git uses it directly with no prompt.
env = dict(os.environ, GIT_TERMINAL_PROMPT="0")
if cmd and cmd[0] == "git":
cmd = cmd[:1] + ["-c", "credential.helper="] + cmd[1:]
subprocess.run(cmd, cwd=cwd, check=True, env=env)
def revert():
token = os.environ.get("HF_TOKEN")
if not token:
raise SystemExit(
"HF_TOKEN is not set. Export a token with write access to the Space:\n"
" Windows: set HF_TOKEN=hf_xxx\n"
" Linux/mac: export HF_TOKEN=hf_xxx"
)
# Token as both user and password in the URL — HF accepts the token as the password.
url = f"https://{token}:{token}@huggingface.co/spaces/{REPO}"
with tempfile.TemporaryDirectory() as tmp:
run(["git", "clone", "--depth", "1", url, tmp])
run(["git", "-C", tmp, "fetch", "origin", TARGET])
run(["git", "-C", tmp, "reset", "--hard", TARGET])
run(["git", "-C", tmp, "push", "--force-with-lease", "origin", f"{TARGET}:main"])
print(f"Reverted {REPO} to {TARGET}")
if __name__ == "__main__":
revert()
|