Download bundle_from_hf.sh from cheatthegod/cmp-rollout-runtime: direct link, hf CLI and curl.
- Browser
- Download file 4.15 kB
-
https://huggingface.co/datasets/cheatthegod/cmp-rollout-runtime/resolve/main/bundle_from_hf.sh
- Command line
-
hf download hf://datasets/cheatthegod/cmp-rollout-runtime/bundle_from_hf.sh
-
curl -L -o bundle_from_hf.sh https://huggingface.co/datasets/cheatthegod/cmp-rollout-runtime/resolve/main/bundle_from_hf.sh
4.15 kB
| # 共享步骤:把渲染 bundle 从 HuggingFace 拉下来解包,并把 $BUNDLE 设好。 | |
| # | |
| # 用法(source,不要执行): | |
| # source "$(dirname "${BASH_SOURCE[0]}")/bundle_from_hf.sh" | |
| # 之后 $BUNDLE 就是 bundle 根目录。 | |
| # | |
| # ---- 为什么走 HF 而不是 OBS 的 code_dir | |
| # 本机 -> OBS 实测只有 0.13 MB/s(整池共享出口),0.38GB 的包要传 10 小时; | |
| # 同一个包推 HuggingFace 只用 17 秒。所以 code_dir 只放入口脚本,大包走 HF。 | |
| # 容器**到不了 hf.co**,只能用 hf-mirror。 | |
| # | |
| # ---- 为什么单独抽成一个文件 | |
| # 渲染入口和并发基准入口都要做这一整套(错开、重试、大小自检、解包)。 | |
| # 抄两份的话,下次只改一份 —— 而这一段恰恰是刚被 429 打爆、必须靠重试兜底的那段, | |
| # 两份之间漂移的代价就是"某个入口又没有重试"。 | |
| # | |
| # ---- 三个可覆盖的变量(2026-08-15 加,为了让 rollout 入口也能复用这一份) | |
| # RENDER_BUNDLE_FILE 归档在 HF repo 里的文件名,默认 render_bundle.tar.gz | |
| # RENDER_BUNDLE_SENTINEL 解包成功的判据文件,默认 plan.json | |
| # RENDER_BUNDLE_MIN_BYTES 大小自检下限,默认 1e6 | |
| # 默认值与改之前**完全一致**,渲染那条路一点没变。 | |
| # rollout 的包里没有 plan.json(它不渲染,不需要计划表),哨兵换成 py/bin/python3.13; | |
| # 包也大得多(2.5GB vs 0.37GB),下限相应提高,不然半截包也能"通过自检"。 | |
| if [[ -n "${RENDER_BUNDLE_REPO:-}" ]]; then | |
| BUNDLE="${RENDER_BUNDLE_DIR:-/cache/render_bundle}" | |
| SENT="${RENDER_BUNDLE_SENTINEL:-plan.json}" | |
| if [[ ! -e "$BUNDLE/$SENT" ]]; then | |
| mkdir -p "$BUNDLE" | |
| export HF_ENDPOINT="${HF_ENDPOINT:-https://hf-mirror.com}" | |
| export HF_HUB_DISABLE_XET=1 | |
| echo "[entry] 从 HF 拉渲染 bundle:${RENDER_BUNDLE_REPO}" | |
| python3 - <<PY | |
| import os, random, tarfile, time | |
| from huggingface_hub import hf_hub_download | |
| # ⚠️ 所有分片是**同时**起的,会在同一秒去抓同一个 374MB 文件, | |
| # hf-mirror 直接回 429 Too Many Requests。2026-08-15 实测:4 个分片里 | |
| # shard3 当场 Failed,而且原来这里没有任何重试 —— 一次 429 就报废一张卡的整批活。 | |
| # 分片一多只会更糟(5k 那批是 16 片)。两手都要:错开起跑 + 指数退避重试。 | |
| idx = int(os.environ.get("SHARD_INDEX", "0")) | |
| stagger = idx * 25 + random.uniform(0, 10) | |
| print("[entry] 错开起跑:分片 %d 等 %.0fs 再拉包" % (idx, stagger), flush=True) | |
| time.sleep(stagger) | |
| path, last = None, None | |
| for attempt in range(8): | |
| try: | |
| path = hf_hub_download(repo_id="${RENDER_BUNDLE_REPO}", repo_type="dataset", | |
| filename=os.environ.get("RENDER_BUNDLE_FILE", | |
| "render_bundle.tar.gz"), | |
| local_dir="/tmp/rbundle") | |
| break | |
| except Exception as exc: | |
| last = exc | |
| wait = min(20 * (2 ** attempt), 480) + random.uniform(0, 20) | |
| print("[entry] 第 %d/8 次拉包失败(%s),%.0fs 后重试:%s" | |
| % (attempt + 1, type(exc).__name__, wait, str(exc)[:200]), flush=True) | |
| time.sleep(wait) | |
| if path is None: | |
| raise SystemExit("[entry] FATAL 拉包 8 次全失败,最后一次:%s" % last) | |
| # 大小自检:hf_hub_download 断线时会把残缺文件当成功返回(权重那边吃过这个亏) | |
| size = os.path.getsize(path) | |
| print("[entry] 拉到 %.0f MB -> %s" % (size / 1e6, path), flush=True) | |
| if size < float(os.environ.get("RENDER_BUNDLE_MIN_BYTES", "1e6")): | |
| raise SystemExit("[entry] FATAL 包只有 %d 字节,明显是残缺文件" % size) | |
| with tarfile.open(path) as t: | |
| t.extractall("${BUNDLE}") | |
| print("[entry] 渲染 bundle 解包完成", flush=True) | |
| PY | |
| fi | |
| if [[ ! -e "$BUNDLE/$SENT" ]]; then | |
| echo "[entry] FATAL 解包后没有 $SENT,bundle 不完整"; exit 21 | |
| fi | |
| NB=$(find "$BUNDLE" -name '*.npz' | wc -l) | |
| echo "[entry] bundle 就位:$(du -sh "$BUNDLE" | cut -f1),轨迹 $NB 条" | |
| else | |
| # 没给 HF repo 就认为 bundle 是 code_dir 整包下发的,脚本自己住在里面 | |
| BUNDLE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | |
| fi | |
| export BUNDLE | |