FTG64 commited on
Commit
4dd2a98
·
verified ·
1 Parent(s): 1513ab8

code: deterministic option; checkpoint-eval job

Browse files
code/scripts/chunk_eval.py CHANGED
@@ -267,8 +267,16 @@ def run_task(task: dict) -> dict:
267
  from lerobot.utils.random_utils import set_seed
268
 
269
  torch.set_num_threads(1)
270
- torch.backends.cudnn.benchmark = True # same backend settings as lerobot-eval
271
- torch.backends.cuda.matmul.allow_tf32 = True
 
 
 
 
 
 
 
 
272
  set_seed(1000)
273
 
274
  cond = Condition(**task["condition"])
@@ -355,6 +363,7 @@ def main() -> None:
355
  parser.add_argument("--workers", type=int, default=min(8, os.cpu_count() or 1))
356
  parser.add_argument("--device", default="cuda")
357
  parser.add_argument("--videos-per-condition", type=int, default=0)
 
358
  parser.add_argument("--out", required=True, type=Path)
359
  parser.add_argument("--hub-repo", default=None, help="dataset repo to sync results to, e.g. user/act-chunking-study")
360
  parser.add_argument("--sync-every", type=int, default=16, help="sync to the Hub after this many finished tasks")
@@ -401,6 +410,7 @@ def main() -> None:
401
  "n_seeds": n,
402
  "n_envs": min(args.n_envs, n),
403
  "n_videos": args.videos_per_condition if i == 0 else 0,
 
404
  "out_path": str(out_path),
405
  }
406
  )
@@ -410,6 +420,7 @@ def main() -> None:
410
  meta = {
411
  "grid": args.grid,
412
  "seeds": args.seeds,
 
413
  "checkpoint": args.checkpoint_label or args.checkpoint,
414
  "torch": torch.__version__,
415
  "device_name": torch.cuda.get_device_name(0) if torch.cuda.is_available() else args.device,
 
267
  from lerobot.utils.random_utils import set_seed
268
 
269
  torch.set_num_threads(1)
270
+ torch.backends.cuda.matmul.allow_tf32 = True # as in lerobot-eval
271
+ if task["deterministic"]:
272
+ # Fixed kernels, so reruns of a condition give identical episodes. The cuBLAS setting
273
+ # must be in place before this worker first touches CUDA, which happens in _load().
274
+ os.environ.setdefault("CUBLAS_WORKSPACE_CONFIG", ":4096:8")
275
+ torch.backends.cudnn.benchmark = False
276
+ torch.backends.cudnn.deterministic = True
277
+ torch.use_deterministic_algorithms(True, warn_only=True)
278
+ else:
279
+ torch.backends.cudnn.benchmark = True # as in lerobot-eval
280
  set_seed(1000)
281
 
282
  cond = Condition(**task["condition"])
 
363
  parser.add_argument("--workers", type=int, default=min(8, os.cpu_count() or 1))
364
  parser.add_argument("--device", default="cuda")
365
  parser.add_argument("--videos-per-condition", type=int, default=0)
366
+ parser.add_argument("--deterministic", action="store_true", help="deterministic GPU kernels (reproducible reruns)")
367
  parser.add_argument("--out", required=True, type=Path)
368
  parser.add_argument("--hub-repo", default=None, help="dataset repo to sync results to, e.g. user/act-chunking-study")
369
  parser.add_argument("--sync-every", type=int, default=16, help="sync to the Hub after this many finished tasks")
 
410
  "n_seeds": n,
411
  "n_envs": min(args.n_envs, n),
412
  "n_videos": args.videos_per_condition if i == 0 else 0,
413
+ "deterministic": args.deterministic,
414
  "out_path": str(out_path),
415
  }
416
  )
 
420
  meta = {
421
  "grid": args.grid,
422
  "seeds": args.seeds,
423
+ "deterministic": args.deterministic,
424
  "checkpoint": args.checkpoint_label or args.checkpoint,
425
  "torch": torch.__version__,
426
  "device_name": torch.cuda.get_device_name(0) if torch.cuda.is_available() else args.device,
code/scripts/jobs/eval_checkpoints.sh ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # HF Jobs script for the Day 2 milestone and a GPU-noise check.
3
+ #
4
+ # 1. Our checkpoints at 25k/50k/75k/100k steps: full chunk, zero delay, seeds 1000-1199.
5
+ # 2. The official checkpoint on seeds 1000-1499, the same 500 seeds as its published eval_info.json.
6
+ # 3. Noise floor: the same lerobot-eval command twice (seeds 1000-1024). If the summed rewards
7
+ # differ between the two runs, GPU nondeterminism is confirmed.
8
+ # 4. The same harness command twice with --deterministic. This checks whether fixed kernels make
9
+ # reruns identical.
10
+ #
11
+ # Upload scripts/ to the dataset repo as code/scripts/, then submit from the repo root:
12
+ # hf jobs run --flavor l4x1 --timeout 90m --secrets HF_TOKEN --name act-ckpt-eval \
13
+ # huggingface/lerobot-gpu:latest bash -c "$(cat scripts/jobs/eval_checkpoints.sh)"
14
+ set -euo pipefail
15
+ export PYTHONUNBUFFERED=1
16
+ cd /lerobot
17
+ REPO=FTG64/act-chunking-study
18
+ MODEL=FTG64/act_aloha_transfer_cube
19
+ STUDY=/tmp/study
20
+ WORKERS=7
21
+
22
+ (while true; do echo "[mem $(date +%H:%M:%S)] $(free -m | awk '/Mem:/ {print $3 " MB used of " $2 " MB"}')"; sleep 60; done) &
23
+ MEM_PID=$!
24
+ trap 'kill $MEM_PID 2>/dev/null || true' EXIT
25
+
26
+ hf download "$REPO" --repo-type dataset --include "code/*" --local-dir "$STUDY" > /dev/null
27
+ CODE="$STUDY/code/scripts"
28
+ full_mode() { # label policy_dir seeds [extra harness args...]
29
+ local label=$1 policy=$2 seeds=$3; shift 3
30
+ python "$CODE/chunk_eval.py" --checkpoint "$policy" --checkpoint-label "$label" --grid validation \
31
+ --only full_d00_m0 --seeds "$seeds" --block 25 --n-envs 5 --workers "$WORKERS" \
32
+ --out "/tmp/$label" --hub-repo "$REPO" "$@" | grep -E "tasks to run|finished"
33
+ }
34
+
35
+ for step in 025000 050000 075000 100000; do
36
+ echo "== ours, checkpoint $step"
37
+ hf download "$MODEL" --revision "$step" --include "checkpoints/$step/pretrained_model/*" --local-dir /tmp/ours > /dev/null
38
+ full_mode "ckpt_ours_$step" "/tmp/ours/checkpoints/$step/pretrained_model" 1000:1200
39
+ done
40
+
41
+ echo "== official checkpoint, seeds 1000-1499"
42
+ python src/lerobot/processor/migrate_policy_normalization.py \
43
+ --pretrained-path lerobot/act_aloha_sim_transfer_cube_human --output-dir /tmp/official > /tmp/migrate.log 2>&1
44
+ full_mode ckpt_official /tmp/official 1000:1500
45
+
46
+ echo "== noise floor: identical lerobot-eval runs"
47
+ for i in 1 2; do
48
+ lerobot-eval --policy.path=/tmp/official --env.type=aloha --env.task=AlohaTransferCube-v0 \
49
+ --eval.n_episodes=25 --eval.batch_size=5 --eval.use_async_envs=false --policy.device=cuda --seed=1000 \
50
+ --output_dir="/tmp/noise_floor/lerobot_run$i" > "/tmp/noise_floor_lerobot_$i.log" 2>&1 &
51
+ done
52
+ wait
53
+ echo "== determinism: identical harness runs with --deterministic"
54
+ for i in 1 2; do
55
+ python "$CODE/chunk_eval.py" --checkpoint /tmp/official --checkpoint-label official --grid validation \
56
+ --only full_d00_m0 --seeds 1000:1025 --block 25 --n-envs 5 --workers 1 --deterministic \
57
+ --out "/tmp/noise_floor/harness_det_run$i" > "/tmp/noise_floor_harness_$i.log" 2>&1 &
58
+ done
59
+ wait
60
+ python - <<'EOF'
61
+ import json
62
+ from pathlib import Path
63
+
64
+ root = Path("/tmp/noise_floor")
65
+ def lerobot(i):
66
+ m = json.loads((root / f"lerobot_run{i}" / "eval_info.json").read_text())["per_task"][0]["metrics"]
67
+ return list(zip(m["successes"], m["sum_rewards"]))
68
+ def harness(i):
69
+ eps = json.loads(next((root / f"harness_det_run{i}" / "full_d00_m0").glob("*.json")).read_text())["episodes"]
70
+ return [(e["success"], e["sum_reward"]) for e in sorted(eps, key=lambda e: e["seed"])]
71
+ summary = {}
72
+ for name, load in (("lerobot_eval_default", lerobot), ("harness_deterministic", harness)):
73
+ a, b = load(1), load(2)
74
+ summary[name] = {"n": len(a), "same_outcome": sum(x[0] == y[0] for x, y in zip(a, b)),
75
+ "same_sum_reward": sum(x[1] == y[1] for x, y in zip(a, b))}
76
+ print(name, summary[name])
77
+ (root / "summary.json").write_text(json.dumps(summary, indent=1))
78
+ EOF
79
+ hf upload "$REPO" /tmp/noise_floor results/noise_floor --repo-type dataset > /dev/null
80
+ echo "== done"
code/scripts/jobs/run_grid.sh ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # HF Jobs script: run scripts/chunk_eval.py for one checkpoint and sync results to the dataset repo.
3
+ #
4
+ # Settings come from environment variables passed with `hf jobs run -e KEY=VALUE`:
5
+ # CKPT "official" (the official Hub checkpoint, converted in the job) or
6
+ # "hub:<repo>@<revision>:<subfolder>" (e.g. hub:FTG64/act_aloha_transfer_cube@025000:checkpoints/025000/pretrained_model)
7
+ # LABEL short name recorded in the results and used for the output folder (results/<RUN>)
8
+ # RUN output folder name inside results/ of the dataset repo
9
+ # GRID validation | core ONLY optional space-separated condition names
10
+ # SEEDS start:stop WORKERS / NENVS / BLOCK parallelism settings
11
+ # VIDEOS videos per condition (default 0)
12
+ #
13
+ # Submit from the repo root after uploading scripts/ to the dataset repo as code/scripts/, e.g.:
14
+ # hf jobs run --flavor l4x1 --timeout 3h --secrets HF_TOKEN --name act-grid \
15
+ # -e CKPT=official -e LABEL=official -e RUN=core_official -e GRID=core -e SEEDS=1000:1200 \
16
+ # huggingface/lerobot-gpu:latest bash -c "$(cat scripts/jobs/run_grid.sh)"
17
+ set -euo pipefail
18
+ export PYTHONUNBUFFERED=1
19
+ cd /lerobot
20
+ REPO=FTG64/act-chunking-study
21
+ STUDY=/tmp/study
22
+ : "${CKPT:?}" "${LABEL:?}" "${RUN:?}" "${GRID:?}" "${SEEDS:?}"
23
+ WORKERS=${WORKERS:-4}; NENVS=${NENVS:-5}; BLOCK=${BLOCK:-25}; VIDEOS=${VIDEOS:-0}; ONLY=${ONLY:-}
24
+
25
+ (while true; do echo "[mem $(date +%H:%M:%S)] $(free -m | awk '/Mem:/ {print $3 " MB used of " $2 " MB"}')"; sleep 60; done) &
26
+ MEM_PID=$!
27
+ trap 'kill $MEM_PID 2>/dev/null || true' EXIT
28
+
29
+ hf download "$REPO" --repo-type dataset --include "code/*" --local-dir "$STUDY" > /dev/null
30
+ if [ "$CKPT" = "official" ]; then
31
+ python src/lerobot/processor/migrate_policy_normalization.py \
32
+ --pretrained-path lerobot/act_aloha_sim_transfer_cube_human --output-dir /tmp/policy > /tmp/migrate.log 2>&1
33
+ POLICY=/tmp/policy
34
+ else
35
+ spec=${CKPT#hub:}; repo=${spec%%@*}; rest=${spec#*@}; rev=${rest%%:*}; sub=${rest#*:}
36
+ hf download "$repo" --revision "$rev" --include "$sub/*" --local-dir /tmp/policy_dl > /dev/null
37
+ POLICY=/tmp/policy_dl/$sub
38
+ fi
39
+ echo "== policy ready: $LABEL ($POLICY)"
40
+
41
+ only_args=()
42
+ if [ -n "$ONLY" ]; then only_args=(--only $ONLY); fi # word-splitting intended
43
+ python "$STUDY/code/scripts/chunk_eval.py" --checkpoint "$POLICY" --checkpoint-label "$LABEL" --grid "$GRID" \
44
+ "${only_args[@]}" --seeds "$SEEDS" --block "$BLOCK" --n-envs "$NENVS" --workers "$WORKERS" \
45
+ --videos-per-condition "$VIDEOS" --out "/tmp/$RUN" --hub-repo "$REPO"
46
+ echo "== done: results/$RUN in $REPO"