File size: 2,362 Bytes
3f4bb1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Fetch Git LFS blobs for GR00T-WholeBodyControl without git-lfs installed.
#
# The checkout stores the GEAR planner weights as 132-byte LFS pointers. GitHub
# serves the real blobs from media.githubusercontent.com, so each pointer is
# read for its sha256 and size, downloaded, verified, and swapped in place.
# A file whose hash does not match is left untouched.
#
#   ./scripts/fetch_gear_lfs.sh            # planner + walk policy
#   ./scripts/fetch_gear_lfs.sh <path>...  # specific repo-relative paths
set -uo pipefail

REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../third-party/GR00T-WholeBodyControl" && pwd)"
BRANCH="${GEAR_LFS_BRANCH:-main}"
BASE="https://media.githubusercontent.com/media/NVlabs/GR00T-WholeBodyControl/$BRANCH"

DEFAULT_PATHS=(
  "motionbricks/out/G1-clip.ckpt"
  "motionbricks/out/motionbricks_root/version_1/checkpoints/model-step=2000000.ckpt"
  "motionbricks/out/motionbricks_pose/version_1/checkpoints/model-step=2000000.ckpt"
  "motionbricks/out/motionbricks_vqvae/version_1/checkpoints/model-step=2000000.ckpt"
  "decoupled_wbc/sim2mujoco/resources/robots/g1/policy/GR00T-WholeBodyControl-Walk.onnx"
  "decoupled_wbc/sim2mujoco/resources/robots/g1/policy/GR00T-WholeBodyControl-Balance.onnx"
)

if [[ $# -gt 0 ]]; then
  PATHS=("$@")
else
  PATHS=("${DEFAULT_PATHS[@]}")
fi

fail=0
for rel in "${PATHS[@]}"; do
  file="$REPO/$rel"
  if [[ ! -f "$file" ]]; then
    echo "skip (missing): $rel"
    continue
  fi
  # A real blob is far larger than a pointer and has no version line.
  if ! head -c 64 "$file" | grep -q 'git-lfs.github.com/spec'; then
    echo "ok (already real, $(stat -c%s "$file") bytes): $rel"
    continue
  fi
  oid="$(awk -F: '/^oid sha256:/ {print $2}' "$file")"
  want="$(awk '/^size / {print $2}' "$file")"
  if [[ -z "$oid" || -z "$want" ]]; then
    echo "FAIL (unreadable pointer): $rel"
    fail=1
    continue
  fi

  tmp="$(mktemp)"
  echo "fetch $rel ($want bytes)"
  if ! curl -sfL -o "$tmp" "$BASE/$rel"; then
    echo "FAIL (download): $rel"
    rm -f "$tmp"
    fail=1
    continue
  fi
  got="$(sha256sum "$tmp" | awk '{print $1}')"
  size="$(stat -c%s "$tmp")"
  if [[ "$got" != "$oid" ]]; then
    echo "FAIL (sha256 $got != $oid): $rel"
    rm -f "$tmp"
    fail=1
    continue
  fi
  mv "$tmp" "$file"
  chmod 644 "$file"
  echo "  verified $size bytes"
done

exit "$fail"