fridge_m setup: chunked_runner + run_gen_chunk + check_mismatch + push_watchdog
Browse files- fridge_m/_setup/scripts/check_mismatch.py +129 -0
- fridge_m/_setup/scripts/chunked_runner.sh +132 -0
- fridge_m/_setup/scripts/final_flush.py +85 -0
- fridge_m/_setup/scripts/push_watchdog.py +133 -0
- fridge_m/_setup/scripts/run_gen_chunk.py +378 -0
- fridge_m/_setup/scripts/smoke_gen.sh +111 -0
- fridge_m/_setup/scripts/stop_after_chunk_6.sh +44 -0
- fridge_m/_setup/scripts/stop_at_300.sh +52 -0
fridge_m/_setup/scripts/check_mismatch.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Assert per-traj T (h5 qpos length) == exo_mp4_frames == wrist_mp4_frames
|
| 2 |
+
for every traj in a chunk's sim dir. Exit 0 if clean, 1 with a per-traj
|
| 3 |
+
report otherwise.
|
| 4 |
+
|
| 5 |
+
This is the primary lock-contention canary for the chunked pipeline. If
|
| 6 |
+
this exits non-zero, treat it as a build-stopping bug (NOT a "drop these
|
| 7 |
+
trajs and continue") — fix the upstream sim before launching gen on this
|
| 8 |
+
chunk.
|
| 9 |
+
"""
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import re
|
| 14 |
+
import subprocess
|
| 15 |
+
import sys
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
|
| 18 |
+
import h5py
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
_EXO_RE = re.compile(r"^episode_(\d{8})_exo_camera_1_robot_rgb(?P<suffix>_batch_(\d+)_of_(\d+)(?:_[A-Za-z0-9_]+)?)\.mp4$")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def mp4_frame_count(path: Path) -> int:
|
| 25 |
+
out = subprocess.run(
|
| 26 |
+
[
|
| 27 |
+
"ffprobe", "-v", "error",
|
| 28 |
+
"-select_streams", "v:0",
|
| 29 |
+
"-count_frames",
|
| 30 |
+
"-show_entries", "stream=nb_read_frames",
|
| 31 |
+
"-of", "default=nokey=1:noprint_wrappers=1",
|
| 32 |
+
str(path),
|
| 33 |
+
],
|
| 34 |
+
capture_output=True, text=True, check=False,
|
| 35 |
+
)
|
| 36 |
+
if out.returncode != 0:
|
| 37 |
+
return -1
|
| 38 |
+
s = out.stdout.strip()
|
| 39 |
+
return int(s) if s.isdigit() else -1
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def main():
|
| 43 |
+
p = argparse.ArgumentParser()
|
| 44 |
+
p.add_argument("--sim_dir", required=True)
|
| 45 |
+
args = p.parse_args()
|
| 46 |
+
sim_dir = Path(args.sim_dir)
|
| 47 |
+
|
| 48 |
+
if not sim_dir.exists():
|
| 49 |
+
print(f"ERROR: sim_dir does not exist: {sim_dir}", file=sys.stderr)
|
| 50 |
+
sys.exit(1)
|
| 51 |
+
|
| 52 |
+
# Enumerate trajs from the exo mp4s (lock-safe, doesn't touch h5).
|
| 53 |
+
items = [] # (shard, ep_idx, suffix, h5_path)
|
| 54 |
+
h5_cache: dict[Path, h5py.File] = {}
|
| 55 |
+
try:
|
| 56 |
+
for f in sorted(sim_dir.iterdir()):
|
| 57 |
+
if not f.is_file():
|
| 58 |
+
continue
|
| 59 |
+
m = _EXO_RE.match(f.name)
|
| 60 |
+
if not m:
|
| 61 |
+
continue
|
| 62 |
+
ep = int(m.group(1))
|
| 63 |
+
suffix = m.group("suffix")
|
| 64 |
+
shard = m.group(3)
|
| 65 |
+
total = m.group(4)
|
| 66 |
+
h5_path = sim_dir / f"trajectories_batch_{shard}_of_{total}_cam_rand.h5"
|
| 67 |
+
items.append((shard, ep, suffix, h5_path))
|
| 68 |
+
|
| 69 |
+
if not items:
|
| 70 |
+
print(f"WARN: no trajs found in {sim_dir}; treating as clean (empty chunk).")
|
| 71 |
+
sys.exit(0)
|
| 72 |
+
|
| 73 |
+
print(f"checking {len(items)} trajs in {sim_dir}")
|
| 74 |
+
mismatches = []
|
| 75 |
+
for shard, ep, suffix, h5_path in items:
|
| 76 |
+
exo_mp4 = sim_dir / f"episode_{ep:08d}_exo_camera_1_robot_rgb{suffix}.mp4"
|
| 77 |
+
wrist_mp4 = sim_dir / f"episode_{ep:08d}_wrist_camera_robot_rgb{suffix}.mp4"
|
| 78 |
+
if not exo_mp4.exists() or not wrist_mp4.exists():
|
| 79 |
+
mismatches.append((shard, ep, "missing_mp4", "-", "-", "-"))
|
| 80 |
+
continue
|
| 81 |
+
if h5_path not in h5_cache:
|
| 82 |
+
if not h5_path.exists():
|
| 83 |
+
mismatches.append((shard, ep, "missing_h5", str(h5_path), "-", "-"))
|
| 84 |
+
continue
|
| 85 |
+
h5_cache[h5_path] = h5py.File(h5_path, "r")
|
| 86 |
+
f = h5_cache[h5_path]
|
| 87 |
+
traj_key = None
|
| 88 |
+
# Trajs in the h5 are named traj_<idx>; idx is the per-shard local index
|
| 89 |
+
# (not the global ep id). The cleanest map is "exo mp4 list ordered by ep
|
| 90 |
+
# matches the traj_N list ordered by N". Both are produced in sync by
|
| 91 |
+
# the writer.
|
| 92 |
+
shard_eps = sorted([e for s, e, *_ in items if s == shard])
|
| 93 |
+
try:
|
| 94 |
+
local_idx = shard_eps.index(ep)
|
| 95 |
+
traj_key = f"traj_{local_idx}"
|
| 96 |
+
except ValueError:
|
| 97 |
+
mismatches.append((shard, ep, "ep_not_in_shard_list", "-", "-", "-"))
|
| 98 |
+
continue
|
| 99 |
+
if traj_key not in f:
|
| 100 |
+
mismatches.append((shard, ep, "h5_traj_missing", traj_key, "-", "-"))
|
| 101 |
+
continue
|
| 102 |
+
qpos = f[traj_key].get("obs/agent/qpos")
|
| 103 |
+
if qpos is None:
|
| 104 |
+
mismatches.append((shard, ep, "qpos_missing", traj_key, "-", "-"))
|
| 105 |
+
continue
|
| 106 |
+
T = int(qpos.shape[0])
|
| 107 |
+
ef = mp4_frame_count(exo_mp4)
|
| 108 |
+
wf = mp4_frame_count(wrist_mp4)
|
| 109 |
+
if not (T == ef == wf):
|
| 110 |
+
mismatches.append((shard, ep, "len_mismatch", T, ef, wf))
|
| 111 |
+
|
| 112 |
+
if not mismatches:
|
| 113 |
+
print(f"OK: all {len(items)} trajs in {sim_dir} have T == exo == wrist")
|
| 114 |
+
sys.exit(0)
|
| 115 |
+
print(f"\nMISMATCH ({len(mismatches)}/{len(items)}):")
|
| 116 |
+
print(f"{'shard':5s} {'ep':>10s} {'kind':<22s} {'T':>6s} {'exo':>6s} {'wrist':>6s}")
|
| 117 |
+
for shard, ep, kind, T, ef, wf in mismatches:
|
| 118 |
+
print(f"{shard:5s} {ep:>10d} {kind:<22s} {str(T):>6s} {str(ef):>6s} {str(wf):>6s}")
|
| 119 |
+
sys.exit(1)
|
| 120 |
+
finally:
|
| 121 |
+
for f in h5_cache.values():
|
| 122 |
+
try:
|
| 123 |
+
f.close()
|
| 124 |
+
except Exception:
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if __name__ == "__main__":
|
| 129 |
+
main()
|
fridge_m/_setup/scripts/chunked_runner.sh
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Sequential-per-chunk fridge_m pipeline orchestrator for viscam3 (4x RTX 3090).
|
| 3 |
+
#
|
| 4 |
+
# Per chunk:
|
| 5 |
+
# 1. Launch 4 sim shards on GPUs 0-3, writing to sim_chunks/chunk_NNN/.
|
| 6 |
+
# 2. Wait for all 4 sim shards to exit (releases h5 locks).
|
| 7 |
+
# 3. Run check_mismatch.py on the chunk; abort on mismatch.
|
| 8 |
+
# 4. Run run_gen_chunk.py on the chunk using ALL 4 GPUs (since on viscam3 we
|
| 9 |
+
# can't afford to dedicate any GPU to a concurrent next-chunk sim).
|
| 10 |
+
# 5. Move on to next chunk.
|
| 11 |
+
#
|
| 12 |
+
# Env vars (with defaults):
|
| 13 |
+
# ROOT -> /scr/ravenh/fridge_m
|
| 14 |
+
# NUM_CHUNKS -> 12 (chunk yields ~45 trajs each so 12 * 45 ~= 540 trajs)
|
| 15 |
+
# SAMPLES_PER_HOUSE-> 3
|
| 16 |
+
# SEED_BASE -> 30000 (sim seed = SEED_BASE + chunk_idx*100 + shard)
|
| 17 |
+
# GPUS -> "0,1,2,3"
|
| 18 |
+
# START_CHUNK -> 1 (set higher to resume; existing dirs are skipped)
|
| 19 |
+
# STOP_AT_TRAJS -> 500 (orchestrator exits once #trajs in sim_chunks >= this)
|
| 20 |
+
#
|
| 21 |
+
set -uo pipefail
|
| 22 |
+
|
| 23 |
+
ROOT="${ROOT:-/scr/ravenh/fridge_m}"
|
| 24 |
+
NUM_CHUNKS="${NUM_CHUNKS:-12}"
|
| 25 |
+
SAMPLES_PER_HOUSE="${SAMPLES_PER_HOUSE:-3}"
|
| 26 |
+
SEED_BASE="${SEED_BASE:-30000}"
|
| 27 |
+
GPUS="${GPUS:-0,1,2,3}"
|
| 28 |
+
START_CHUNK="${START_CHUNK:-1}"
|
| 29 |
+
STOP_AT_TRAJS="${STOP_AT_TRAJS:-500}"
|
| 30 |
+
|
| 31 |
+
REPO_MOLMO=/svl/u/ravenh/renderscale/molmospaces
|
| 32 |
+
SIM_CHUNKS="$ROOT/sim_chunks"
|
| 33 |
+
GEN_CHUNKS="$ROOT/gen_chunks"
|
| 34 |
+
SCRATCH_GEN="$ROOT/_workdir_gen"
|
| 35 |
+
LOGS="$ROOT/logs"
|
| 36 |
+
SCRIPTS="$ROOT/scripts"
|
| 37 |
+
mkdir -p "$SIM_CHUNKS" "$GEN_CHUNKS" "$SCRATCH_GEN" "$LOGS"
|
| 38 |
+
|
| 39 |
+
CONDA_SH=/svl/u/ravenh/miniconda3/etc/profile.d/conda.sh
|
| 40 |
+
# Inherit the conda env from the parent shell (mlspaces).
|
| 41 |
+
source "$CONDA_SH"
|
| 42 |
+
conda activate mlspaces
|
| 43 |
+
|
| 44 |
+
# data_gen_fridge_m.sh passes `--camera_extrinsics scripts/datagen/picked_camera_extrinsics.json`
|
| 45 |
+
# (a relative path that run_pipeline.py opens directly), so all sim shards must
|
| 46 |
+
# run with cwd=$REPO_MOLMO. Without this, every shard dies with FileNotFoundError
|
| 47 |
+
# and the orchestrator burns through chunks at ~30s/chunk doing nothing.
|
| 48 |
+
cd "$REPO_MOLMO"
|
| 49 |
+
|
| 50 |
+
# Tee everything to the runner log.
|
| 51 |
+
exec > >(stdbuf -oL tee -a "$LOGS/chunked_runner.log") 2>&1
|
| 52 |
+
|
| 53 |
+
echo "=========================================="
|
| 54 |
+
echo "[chunked_runner] start $(date -Iseconds)"
|
| 55 |
+
echo " ROOT=$ROOT NUM_CHUNKS=$NUM_CHUNKS SPH=$SAMPLES_PER_HOUSE SEED_BASE=$SEED_BASE"
|
| 56 |
+
echo " GPUS=$GPUS START_CHUNK=$START_CHUNK STOP_AT_TRAJS=$STOP_AT_TRAJS"
|
| 57 |
+
echo "=========================================="
|
| 58 |
+
|
| 59 |
+
count_sim_trajs() {
|
| 60 |
+
# globs across all chunks
|
| 61 |
+
find "$SIM_CHUNKS" -maxdepth 2 -name 'episode_*_exo_camera_1_robot_rgb*.mp4' 2>/dev/null | wc -l
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
for ((n=START_CHUNK; n<=NUM_CHUNKS; n++)); do
|
| 65 |
+
CHUNK_DIR="$SIM_CHUNKS/chunk_$(printf '%03d' $n)"
|
| 66 |
+
GEN_DIR="$GEN_CHUNKS/chunk_$(printf '%03d' $n)"
|
| 67 |
+
CHUNK_SCRATCH="$SCRATCH_GEN/chunk_$(printf '%03d' $n)"
|
| 68 |
+
mkdir -p "$CHUNK_DIR" "$GEN_DIR" "$CHUNK_SCRATCH"
|
| 69 |
+
|
| 70 |
+
current=$(count_sim_trajs)
|
| 71 |
+
echo ""
|
| 72 |
+
echo "=== chunk $n / $NUM_CHUNKS (current_sim_trajs=$current target=$STOP_AT_TRAJS) ==="
|
| 73 |
+
if [ "$current" -ge "$STOP_AT_TRAJS" ]; then
|
| 74 |
+
echo "[chunked_runner] target reached; exiting outer loop."
|
| 75 |
+
break
|
| 76 |
+
fi
|
| 77 |
+
|
| 78 |
+
# --- Step 1: launch 4 sim shards on GPUs 0-3, write to chunk dir ---
|
| 79 |
+
echo "[chunked_runner] step1: launching 4 sim shards -> $CHUNK_DIR"
|
| 80 |
+
declare -a SIM_PIDS=()
|
| 81 |
+
for s in 1 2 3 4; do
|
| 82 |
+
GPU=$((s - 1))
|
| 83 |
+
SEED=$((SEED_BASE + n*100 + s))
|
| 84 |
+
LOG="$LOGS/sim_chunk_$(printf '%03d' $n)_shard_${s}.log"
|
| 85 |
+
CUDA_VISIBLE_DEVICES=$GPU OUTPUT_DIR="$CHUNK_DIR" SAMPLES_PER_HOUSE="$SAMPLES_PER_HOUSE" \
|
| 86 |
+
nohup bash "$REPO_MOLMO/scripts/datagen/data_gen_fridge_m.sh" "$s" 4 "$SEED" \
|
| 87 |
+
> "$LOG" 2>&1 &
|
| 88 |
+
SIM_PIDS+=($!)
|
| 89 |
+
echo " shard $s/4 GPU=$GPU SEED=$SEED PID=$! log=$LOG"
|
| 90 |
+
done
|
| 91 |
+
|
| 92 |
+
# --- Step 2: wait for all 4 sim shards to exit ---
|
| 93 |
+
echo "[chunked_runner] step2: waiting for sim shards to exit..."
|
| 94 |
+
for pid in "${SIM_PIDS[@]}"; do
|
| 95 |
+
if ! wait "$pid"; then
|
| 96 |
+
echo "[chunked_runner] WARN: sim shard PID $pid exited non-zero"
|
| 97 |
+
fi
|
| 98 |
+
done
|
| 99 |
+
echo "[chunked_runner] all sim shards for chunk $n exited"
|
| 100 |
+
|
| 101 |
+
# --- Step 3: check mismatch ---
|
| 102 |
+
echo "[chunked_runner] step3: check_mismatch.py on chunk $n"
|
| 103 |
+
if ! python "$SCRIPTS/check_mismatch.py" --sim_dir "$CHUNK_DIR"; then
|
| 104 |
+
echo "[chunked_runner] FATAL: mismatch in chunk $n -> aborting orchestrator. Inspect $CHUNK_DIR before continuing."
|
| 105 |
+
exit 2
|
| 106 |
+
fi
|
| 107 |
+
|
| 108 |
+
# --- Step 4: gen on all 4 GPUs (sequential per chunk) ---
|
| 109 |
+
CHUNK_TRAJ_COUNT=$(find "$CHUNK_DIR" -maxdepth 1 -name 'episode_*_exo_camera_1_robot_rgb*.mp4' 2>/dev/null | wc -l)
|
| 110 |
+
echo "[chunked_runner] step4: gen on chunk $n ($CHUNK_TRAJ_COUNT trajs) using GPUs=$GPUS"
|
| 111 |
+
SEQ_OFFSET=$((n*100))
|
| 112 |
+
if ! python "$SCRIPTS/run_gen_chunk.py" \
|
| 113 |
+
--sim_src "$CHUNK_DIR" \
|
| 114 |
+
--out_dir "$GEN_DIR" \
|
| 115 |
+
--scratch "$CHUNK_SCRATCH" \
|
| 116 |
+
--gpus "$GPUS" \
|
| 117 |
+
--seq_offset "$SEQ_OFFSET" 2>&1 | stdbuf -oL tee "$LOGS/gen_chunk_$(printf '%03d' $n).log"; then
|
| 118 |
+
echo "[chunked_runner] WARN: gen chunk $n exited non-zero (some trajs may have failed; continuing)"
|
| 119 |
+
fi
|
| 120 |
+
echo "[chunked_runner] step4: gen chunk $n done"
|
| 121 |
+
|
| 122 |
+
# Free per-chunk scratch tmps to save disk (depth + inf_tmp are reproducible).
|
| 123 |
+
rm -rf "$CHUNK_SCRATCH/_inf_tmp" 2>/dev/null || true
|
| 124 |
+
done
|
| 125 |
+
|
| 126 |
+
final_sim=$(count_sim_trajs)
|
| 127 |
+
final_gen=$(find "$GEN_CHUNKS" -maxdepth 2 -name 'generated_episode_*_exo_camera_1*.mp4' 2>/dev/null | wc -l)
|
| 128 |
+
echo ""
|
| 129 |
+
echo "=========================================="
|
| 130 |
+
echo "[chunked_runner] DONE $(date -Iseconds)"
|
| 131 |
+
echo " final_sim_trajs=$final_sim final_gen_trajs=$final_gen"
|
| 132 |
+
echo "=========================================="
|
fridge_m/_setup/scripts/final_flush.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Final HF flush for the fridge_m chunked run on viscam3.
|
| 2 |
+
|
| 3 |
+
Uploads:
|
| 4 |
+
- /scr/ravenh/fridge_m/sim_chunks -> Ravenh97/sim_data:fridge_m (INCL. h5)
|
| 5 |
+
- /scr/ravenh/fridge_m/gen_chunks -> Ravenh97/generated_video:fridge_m
|
| 6 |
+
- /scr/ravenh/fridge_m/prompts -> Ravenh97/generated_video:fridge_m/prompts (setup record)
|
| 7 |
+
- /scr/ravenh/fridge_m/scripts -> Ravenh97/sim_data:fridge_m/scripts (setup record)
|
| 8 |
+
|
| 9 |
+
Patches DEFAULT_REQUEST_TIMEOUT=300 because commits with hundreds of files (esp.
|
| 10 |
+
the h5 batch) hit the default 10s ReadTimeout otherwise.
|
| 11 |
+
"""
|
| 12 |
+
from __future__ import annotations
|
| 13 |
+
|
| 14 |
+
import time
|
| 15 |
+
import huggingface_hub.constants as _hf_constants
|
| 16 |
+
_hf_constants.DEFAULT_REQUEST_TIMEOUT = 600 # extra-generous for the h5-heavy push
|
| 17 |
+
|
| 18 |
+
from huggingface_hub import HfApi # noqa: E402
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
SCRATCH_PATTERNS = [
|
| 22 |
+
"_workdir/**", "_workdir_gen/**", "_shard/**", "_inf_tmp/**",
|
| 23 |
+
"_depth_logs/**", "_depth/**",
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def push(folder, repo_id, path_in_repo, msg, ignore_patterns):
|
| 28 |
+
api = HfApi()
|
| 29 |
+
api.create_repo(repo_id, repo_type="dataset", exist_ok=True)
|
| 30 |
+
t0 = time.time()
|
| 31 |
+
print(f"[final_flush] -> {repo_id}:{path_in_repo} (folder={folder})", flush=True)
|
| 32 |
+
print(f"[final_flush] ignore_patterns={ignore_patterns}", flush=True)
|
| 33 |
+
api.upload_folder(
|
| 34 |
+
folder_path=str(folder),
|
| 35 |
+
repo_id=repo_id,
|
| 36 |
+
repo_type="dataset",
|
| 37 |
+
path_in_repo=path_in_repo,
|
| 38 |
+
ignore_patterns=ignore_patterns,
|
| 39 |
+
commit_message=msg,
|
| 40 |
+
)
|
| 41 |
+
print(f"[final_flush] OK in {time.time()-t0:.1f}s", flush=True)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
# 1. sim_chunks (INCL. h5 files this time — durable backup)
|
| 46 |
+
push(
|
| 47 |
+
folder="/scr/ravenh/fridge_m/sim_chunks",
|
| 48 |
+
repo_id="Ravenh97/sim_data",
|
| 49 |
+
path_in_repo="fridge_m",
|
| 50 |
+
msg="fridge_m viscam3 FINAL flush at 300 trajs (incl. h5)",
|
| 51 |
+
ignore_patterns=SCRATCH_PATTERNS,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# 2. gen_chunks (mp4s + prompts + _logs; no h5 to worry about here)
|
| 55 |
+
push(
|
| 56 |
+
folder="/scr/ravenh/fridge_m/gen_chunks",
|
| 57 |
+
repo_id="Ravenh97/generated_video",
|
| 58 |
+
path_in_repo="fridge_m",
|
| 59 |
+
msg="fridge_m viscam3 FINAL flush at 300 trajs",
|
| 60 |
+
ignore_patterns=SCRATCH_PATTERNS,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# 3. prompts setup record (small; tells future readers what scene prompts were used)
|
| 64 |
+
push(
|
| 65 |
+
folder="/scr/ravenh/fridge_m/prompts",
|
| 66 |
+
repo_id="Ravenh97/generated_video",
|
| 67 |
+
path_in_repo="fridge_m/_setup/prompts",
|
| 68 |
+
msg="fridge_m setup: prompts.json",
|
| 69 |
+
ignore_patterns=[],
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# 4. scripts setup record (so anyone can reproduce the chunked pipeline)
|
| 73 |
+
push(
|
| 74 |
+
folder="/scr/ravenh/fridge_m/scripts",
|
| 75 |
+
repo_id="Ravenh97/sim_data",
|
| 76 |
+
path_in_repo="fridge_m/_setup/scripts",
|
| 77 |
+
msg="fridge_m setup: chunked_runner + run_gen_chunk + check_mismatch + push_watchdog",
|
| 78 |
+
ignore_patterns=[],
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
print("[final_flush] DONE", flush=True)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
main()
|
fridge_m/_setup/scripts/push_watchdog.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HF push watchdog for fridge_m sim and gen chunked layouts.
|
| 2 |
+
|
| 3 |
+
Polls a root dir, counts finalized trajs by globbing the exo-camera mp4
|
| 4 |
+
pattern (lock-safe — never opens h5), and pushes to a HF subfolder every
|
| 5 |
+
`--push_every` new trajs, up to `--max_target`. Skips *.h5 files during
|
| 6 |
+
incremental pushes (too large to re-upload often); h5s get pushed once at
|
| 7 |
+
the final flush.
|
| 8 |
+
|
| 9 |
+
Patches `huggingface_hub.constants.DEFAULT_REQUEST_TIMEOUT=300` before
|
| 10 |
+
importing HfApi so that commits with hundreds of files don't hit the
|
| 11 |
+
default 10s ReadTimeout.
|
| 12 |
+
"""
|
| 13 |
+
from __future__ import annotations
|
| 14 |
+
|
| 15 |
+
import argparse
|
| 16 |
+
import os
|
| 17 |
+
import sys
|
| 18 |
+
import time
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
|
| 21 |
+
import huggingface_hub.constants as _hf_constants
|
| 22 |
+
_hf_constants.DEFAULT_REQUEST_TIMEOUT = 300
|
| 23 |
+
|
| 24 |
+
from huggingface_hub import HfApi # noqa: E402
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def count_finalized(root: Path, kind: str) -> int:
|
| 28 |
+
"""Count finalized trajs across chunked subdirs by globbing the exo-camera mp4.
|
| 29 |
+
|
| 30 |
+
kind = 'sim' counts `episode_*_exo_camera_1_robot_rgb*.mp4`.
|
| 31 |
+
kind = 'gen' counts `generated_episode_*_exo_camera_1*.mp4`.
|
| 32 |
+
"""
|
| 33 |
+
if not root.exists():
|
| 34 |
+
return 0
|
| 35 |
+
if kind == "sim":
|
| 36 |
+
pat = "**/episode_*_exo_camera_1_robot_rgb*.mp4"
|
| 37 |
+
elif kind == "gen":
|
| 38 |
+
pat = "**/generated_episode_*_exo_camera_1*.mp4"
|
| 39 |
+
else:
|
| 40 |
+
raise ValueError(kind)
|
| 41 |
+
return sum(1 for _ in root.rglob(pat.replace("**/", "")) if True) + 0 # placeholder
|
| 42 |
+
# NB: replaced with proper rglob below
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def count_finalized_v2(root: Path, kind: str) -> int:
|
| 46 |
+
if not root.exists():
|
| 47 |
+
return 0
|
| 48 |
+
if kind == "sim":
|
| 49 |
+
return len(list(root.rglob("episode_*_exo_camera_1_robot_rgb*.mp4")))
|
| 50 |
+
elif kind == "gen":
|
| 51 |
+
return len(list(root.rglob("generated_episode_*_exo_camera_1*.mp4")))
|
| 52 |
+
else:
|
| 53 |
+
raise ValueError(kind)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def main():
|
| 57 |
+
p = argparse.ArgumentParser()
|
| 58 |
+
p.add_argument("--root", required=True, help="local dir to push (rglob'd)")
|
| 59 |
+
p.add_argument("--repo_id", required=True, help="HF dataset repo, e.g. Ravenh97/sim_data")
|
| 60 |
+
p.add_argument("--path_in_repo", required=True, help="subfolder in repo to push under, e.g. fridge_m/sim")
|
| 61 |
+
p.add_argument("--kind", choices=["sim", "gen"], required=True)
|
| 62 |
+
p.add_argument("--push_every", type=int, default=50)
|
| 63 |
+
p.add_argument("--max_target", type=int, default=1000)
|
| 64 |
+
p.add_argument("--idle_exit_seconds", type=int, default=7200,
|
| 65 |
+
help="exit cleanly if traj count has not increased for this long AND >= max_target")
|
| 66 |
+
p.add_argument("--poll_seconds", type=int, default=60)
|
| 67 |
+
args = p.parse_args()
|
| 68 |
+
|
| 69 |
+
root = Path(args.root)
|
| 70 |
+
api = HfApi()
|
| 71 |
+
try:
|
| 72 |
+
api.create_repo(args.repo_id, repo_type="dataset", exist_ok=True)
|
| 73 |
+
except Exception as exc:
|
| 74 |
+
print(f"[push_watchdog] create_repo warning: {exc}", flush=True)
|
| 75 |
+
|
| 76 |
+
last_pushed = 0
|
| 77 |
+
last_count = -1
|
| 78 |
+
last_change_t = time.time()
|
| 79 |
+
print(
|
| 80 |
+
f"[push_watchdog] root={root} repo={args.repo_id}:{args.path_in_repo} kind={args.kind} "
|
| 81 |
+
f"push_every={args.push_every} max_target={args.max_target}",
|
| 82 |
+
flush=True,
|
| 83 |
+
)
|
| 84 |
+
while True:
|
| 85 |
+
n = count_finalized_v2(root, args.kind)
|
| 86 |
+
if n != last_count:
|
| 87 |
+
print(f"[push_watchdog] count={n} last_pushed={last_pushed} target={args.max_target}", flush=True)
|
| 88 |
+
last_count = n
|
| 89 |
+
last_change_t = time.time()
|
| 90 |
+
# Threshold: push at multiples of push_every once we've passed that threshold.
|
| 91 |
+
threshold = ((n // args.push_every) * args.push_every)
|
| 92 |
+
if threshold > last_pushed and threshold > 0:
|
| 93 |
+
try:
|
| 94 |
+
t0 = time.time()
|
| 95 |
+
print(f"[push_watchdog] pushing at threshold {threshold} (count={n})...", flush=True)
|
| 96 |
+
api.upload_folder(
|
| 97 |
+
folder_path=str(root),
|
| 98 |
+
repo_id=args.repo_id,
|
| 99 |
+
repo_type="dataset",
|
| 100 |
+
path_in_repo=args.path_in_repo,
|
| 101 |
+
ignore_patterns=["*.h5", "_workdir/**", "_workdir_gen/**", "_shard/**", "_inf_tmp/**", "_depth_logs/**", "_depth/**"],
|
| 102 |
+
commit_message=f"fridge_m {args.kind} push at {threshold} trajs",
|
| 103 |
+
)
|
| 104 |
+
last_pushed = threshold
|
| 105 |
+
print(f"[push_watchdog] push at {threshold} OK in {time.time()-t0:.1f}s", flush=True)
|
| 106 |
+
except Exception as exc:
|
| 107 |
+
print(f"[push_watchdog] push at {threshold} FAILED: {exc}", flush=True)
|
| 108 |
+
# Final flush: when count >= max_target, do one more push that INCLUDES h5 files.
|
| 109 |
+
if n >= args.max_target and last_pushed >= ((args.max_target // args.push_every) * args.push_every):
|
| 110 |
+
print(f"[push_watchdog] doing FINAL flush (incl. h5) at count={n}...", flush=True)
|
| 111 |
+
try:
|
| 112 |
+
t0 = time.time()
|
| 113 |
+
api.upload_folder(
|
| 114 |
+
folder_path=str(root),
|
| 115 |
+
repo_id=args.repo_id,
|
| 116 |
+
repo_type="dataset",
|
| 117 |
+
path_in_repo=args.path_in_repo,
|
| 118 |
+
ignore_patterns=["_workdir/**", "_workdir_gen/**", "_shard/**", "_inf_tmp/**", "_depth_logs/**", "_depth/**"],
|
| 119 |
+
commit_message=f"fridge_m {args.kind} FINAL flush at {n} trajs (incl. h5)",
|
| 120 |
+
)
|
| 121 |
+
print(f"[push_watchdog] FINAL flush OK in {time.time()-t0:.1f}s; exiting.", flush=True)
|
| 122 |
+
except Exception as exc:
|
| 123 |
+
print(f"[push_watchdog] FINAL flush FAILED: {exc}", flush=True)
|
| 124 |
+
sys.exit(0)
|
| 125 |
+
# Idle exit (only after target reached so we don't kill the watchdog prematurely).
|
| 126 |
+
if n >= args.max_target and (time.time() - last_change_t) > args.idle_exit_seconds:
|
| 127 |
+
print(f"[push_watchdog] idle {args.idle_exit_seconds}s past target; exiting.", flush=True)
|
| 128 |
+
sys.exit(0)
|
| 129 |
+
time.sleep(args.poll_seconds)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
if __name__ == "__main__":
|
| 133 |
+
main()
|
fridge_m/_setup/scripts/run_gen_chunk.py
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Single-pass gen orchestrator for one fridge_m chunk.
|
| 2 |
+
|
| 3 |
+
Adapted from Sim2RealGen_Video_Model/run_fridge_7.py for chunked layout:
|
| 4 |
+
- SIM_SRC, OUT_DIR, SCRATCH are CLI args (per-chunk).
|
| 5 |
+
- PROMPTS_JSON points at the local fridge_m prompts (kitchen, white/gray
|
| 6 |
+
wall, light yellow/white/gray floor, single stainless steel fridge).
|
| 7 |
+
- Single pass (no watch loop). Returns 0 only if all queued items produced
|
| 8 |
+
both ext1 and wrist generated mp4s; non-zero if any fail.
|
| 9 |
+
- Caller (chunked_runner.sh) is responsible for ensuring sim shards have
|
| 10 |
+
exited before invoking this — otherwise depth_methods.py acquires h5
|
| 11 |
+
shared locks while sim writers hold exclusive locks (the silent-data-loss
|
| 12 |
+
bug documented in datagen_pipeline_fridge_m.md gotcha #6).
|
| 13 |
+
"""
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import argparse
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
import re
|
| 20 |
+
import shutil
|
| 21 |
+
import subprocess
|
| 22 |
+
import sys
|
| 23 |
+
import time
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
REPO = Path("/svl/u/ravenh/renderscale/Sim2RealGen_Video_Model")
|
| 28 |
+
LORA = REPO / "lora_ckpts/Wan2.1-Fun-V1.1-1.3B-DualControl-3View-PrevFrame_minimal_lora/step-4740.safetensors"
|
| 29 |
+
PROMPTS_JSON = Path("/scr/ravenh/fridge_m/prompts/prompts.json")
|
| 30 |
+
|
| 31 |
+
# Layout: 4 shards per chunk, shared output dir, suffix `_cam_rand`.
|
| 32 |
+
# data_gen_fridge_m.sh defaults TOTAL_SHARDS=4 and SHARDS 1..4.
|
| 33 |
+
SHARDS = [
|
| 34 |
+
(f"b{i}", "", f"trajectories_batch_{i}_of_4_cam_rand.h5", f"_batch_{i}_of_4_cam_rand")
|
| 35 |
+
for i in (1, 2, 3, 4)
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
_EXO_RGB_RE = re.compile(
|
| 39 |
+
r"^episode_(\d{8})_exo_camera_1_robot_rgb(?P<suffix>_batch_\d+_of_\d+(?:_[A-Za-z0-9_]+)?)\.mp4$"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _load_prompts() -> tuple[list[str], str]:
|
| 44 |
+
d = json.loads(PROMPTS_JSON.read_text())
|
| 45 |
+
return d["scenes"], d["fixed_prefix"]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def make_prompt(seq_idx: int, scenes: list[str], fixed_prefix: str) -> str:
|
| 49 |
+
s = scenes[seq_idx % len(scenes)]
|
| 50 |
+
return f"Video of a real {s}. {fixed_prefix}"
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def make_seed(seq_idx: int) -> int:
|
| 54 |
+
return 1000 + seq_idx * 13
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def list_trajs_from_disk(src_dir: Path, mp4_suffix: str) -> list[int]:
|
| 58 |
+
if not src_dir.exists():
|
| 59 |
+
return []
|
| 60 |
+
ids: list[int] = []
|
| 61 |
+
for f in src_dir.iterdir():
|
| 62 |
+
if not f.is_file():
|
| 63 |
+
continue
|
| 64 |
+
m = _EXO_RGB_RE.match(f.name)
|
| 65 |
+
if m and m.group("suffix") == mp4_suffix:
|
| 66 |
+
ids.append(int(m.group(1)))
|
| 67 |
+
return sorted(ids)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def build_queue(sim_src: Path, target: int) -> list[tuple]:
|
| 71 |
+
queue: list[tuple] = []
|
| 72 |
+
for shard_id, _shard_rel_dir, h5_name, mp4_suffix in SHARDS:
|
| 73 |
+
idxs = list_trajs_from_disk(sim_src, mp4_suffix)
|
| 74 |
+
for idx in idxs:
|
| 75 |
+
ext_rgb = sim_src / f"episode_{idx:08d}_exo_camera_1_robot_rgb{mp4_suffix}.mp4"
|
| 76 |
+
wrist_rgb = sim_src / f"episode_{idx:08d}_wrist_camera_robot_rgb{mp4_suffix}.mp4"
|
| 77 |
+
if not (ext_rgb.exists() and wrist_rgb.exists()):
|
| 78 |
+
continue
|
| 79 |
+
queue.append((shard_id, h5_name, mp4_suffix, idx))
|
| 80 |
+
if target > 0 and len(queue) >= target:
|
| 81 |
+
return queue
|
| 82 |
+
return queue
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def shard_scratch_dir(scratch: Path, shard_id: str) -> Path:
|
| 86 |
+
return scratch / "_shard" / shard_id
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def shard_depth_root(scratch: Path, shard_id: str) -> Path:
|
| 90 |
+
return scratch / "_depth" / shard_id
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def _prepare_shard_workdir(
|
| 94 |
+
scratch: Path, sim_src: Path, shard_id: str, h5_name: str, mp4_suffix: str, episodes: list[int]
|
| 95 |
+
) -> Path:
|
| 96 |
+
work = shard_scratch_dir(scratch, shard_id)
|
| 97 |
+
work.mkdir(parents=True, exist_ok=True)
|
| 98 |
+
src_h5 = sim_src / h5_name
|
| 99 |
+
link_h5 = work / h5_name
|
| 100 |
+
if not link_h5.exists() and src_h5.exists():
|
| 101 |
+
link_h5.symlink_to(src_h5)
|
| 102 |
+
for idx in episodes:
|
| 103 |
+
for cam in ("exo_camera_1", "wrist_camera"):
|
| 104 |
+
fn = f"episode_{idx:08d}_{cam}_robot_rgb{mp4_suffix}.mp4"
|
| 105 |
+
src_mp4 = sim_src / fn
|
| 106 |
+
if not src_mp4.exists():
|
| 107 |
+
continue
|
| 108 |
+
dst = work / fn
|
| 109 |
+
if not dst.exists():
|
| 110 |
+
dst.symlink_to(src_mp4)
|
| 111 |
+
return work
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def launch_depth_for_shard_async(
|
| 115 |
+
scratch: Path,
|
| 116 |
+
sim_src: Path,
|
| 117 |
+
shard_id: str,
|
| 118 |
+
h5_name: str,
|
| 119 |
+
mp4_suffix: str,
|
| 120 |
+
episodes: list[int],
|
| 121 |
+
) -> subprocess.Popen | None:
|
| 122 |
+
work = shard_scratch_dir(scratch, shard_id)
|
| 123 |
+
if (work / "_depth_done").exists():
|
| 124 |
+
return None
|
| 125 |
+
_prepare_shard_workdir(scratch, sim_src, shard_id, h5_name, mp4_suffix, episodes)
|
| 126 |
+
out_root = shard_depth_root(scratch, shard_id)
|
| 127 |
+
out_root.mkdir(parents=True, exist_ok=True)
|
| 128 |
+
log = scratch / "_depth_logs" / f"{shard_id}.log"
|
| 129 |
+
log.parent.mkdir(parents=True, exist_ok=True)
|
| 130 |
+
cmd = [
|
| 131 |
+
sys.executable, str(REPO / "scripts/depth_methods.py"),
|
| 132 |
+
"--sim_dir", str(work),
|
| 133 |
+
"--out_root", str(out_root),
|
| 134 |
+
"--methods", "h5_v4",
|
| 135 |
+
"--method_label", "h5_v4",
|
| 136 |
+
"--use_raw_pct",
|
| 137 |
+
"--raw_pct", "1,99",
|
| 138 |
+
"--inv_clip", "1,20",
|
| 139 |
+
"--inv_map", "log",
|
| 140 |
+
"--depth_size", "416,240",
|
| 141 |
+
"--episodes", ",".join(str(i) for i in episodes),
|
| 142 |
+
]
|
| 143 |
+
print(f"[depth-bg] {shard_id}: launching depth_methods.py for {len(episodes)} episodes (log {log})",
|
| 144 |
+
flush=True)
|
| 145 |
+
lf = open(log, "w")
|
| 146 |
+
popen = subprocess.Popen(cmd, stdout=lf, stderr=subprocess.STDOUT)
|
| 147 |
+
popen._log_handle = lf
|
| 148 |
+
popen._shard_id = shard_id
|
| 149 |
+
return popen
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def is_shard_depth_done(scratch: Path, shard_id: str) -> bool:
|
| 153 |
+
return (shard_scratch_dir(scratch, shard_id) / "_depth_done").exists()
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def output_paths(out_dir: Path, traj_idx: int, mp4_suffix: str) -> tuple[Path, Path]:
|
| 157 |
+
out_ext = out_dir / f"generated_episode_{traj_idx:08d}_exo_camera_1{mp4_suffix}.mp4"
|
| 158 |
+
out_wrist = out_dir / f"generated_episode_{traj_idx:08d}_wrist_camera{mp4_suffix}.mp4"
|
| 159 |
+
return out_ext, out_wrist
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def already_done(out_dir: Path, item) -> bool:
|
| 163 |
+
_shard_id, _h5_name, mp4_suffix, idx = item
|
| 164 |
+
out_ext, out_wrist = output_paths(out_dir, idx, mp4_suffix)
|
| 165 |
+
return out_ext.exists() and out_wrist.exists()
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def launch_inference(
|
| 169 |
+
scratch: Path,
|
| 170 |
+
out_dir: Path,
|
| 171 |
+
scenes: list[str],
|
| 172 |
+
fixed_prefix: str,
|
| 173 |
+
gpu: int,
|
| 174 |
+
seq_idx: int,
|
| 175 |
+
item,
|
| 176 |
+
) -> subprocess.Popen:
|
| 177 |
+
shard_id, _h5_name, mp4_suffix, idx = item
|
| 178 |
+
depth_root = shard_depth_root(scratch, shard_id) / "h5_v4" / f"episode_{idx:08d}"
|
| 179 |
+
ext_depth = depth_root / "ext1" / "depth" / "original_depth.mp4"
|
| 180 |
+
ext_mask = depth_root / "ext1" / "mask" / "rgb_robot.mp4"
|
| 181 |
+
wrist_depth = depth_root / "wrist" / "depth" / "original_depth.mp4"
|
| 182 |
+
wrist_mask = depth_root / "wrist" / "mask" / "rgb_robot.mp4"
|
| 183 |
+
for p in (ext_depth, ext_mask, wrist_depth, wrist_mask):
|
| 184 |
+
if not p.exists():
|
| 185 |
+
raise RuntimeError(f"missing depth/mask file: {p}")
|
| 186 |
+
|
| 187 |
+
work = scratch / "_inf_tmp" / f"{shard_id}_ep{idx:08d}"
|
| 188 |
+
if work.exists():
|
| 189 |
+
shutil.rmtree(work)
|
| 190 |
+
work.mkdir(parents=True, exist_ok=True)
|
| 191 |
+
|
| 192 |
+
prompt = make_prompt(seq_idx, scenes, fixed_prefix)
|
| 193 |
+
seed = make_seed(seq_idx)
|
| 194 |
+
|
| 195 |
+
prompts_dir = out_dir / "prompts"
|
| 196 |
+
prompts_dir.mkdir(parents=True, exist_ok=True)
|
| 197 |
+
(prompts_dir / f"episode_{idx:08d}{mp4_suffix}.txt").write_text(
|
| 198 |
+
f"prompt: {prompt}\nseed: {seed}\nshard: {shard_id}\nseq_idx: {seq_idx}\n"
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
log_dir = out_dir / "_logs"
|
| 202 |
+
log_dir.mkdir(parents=True, exist_ok=True)
|
| 203 |
+
log = log_dir / f"{shard_id}_ep{idx:08d}.log"
|
| 204 |
+
|
| 205 |
+
env = {**os.environ, "CUDA_VISIBLE_DEVICES": str(gpu), "DIFFSYNTH_SKIP_DOWNLOAD": "true"}
|
| 206 |
+
cmd = [
|
| 207 |
+
sys.executable, str(REPO / "sim2realgen/inference_long_video.py"),
|
| 208 |
+
"--views",
|
| 209 |
+
f"ext1:{ext_depth}:{ext_mask}",
|
| 210 |
+
f"wrist:{wrist_depth}:{wrist_mask}",
|
| 211 |
+
"--prompt", prompt,
|
| 212 |
+
"--lora_path", str(LORA),
|
| 213 |
+
"--height", "240", "--width", "416",
|
| 214 |
+
"--clip_length", "81",
|
| 215 |
+
"--num_inference_steps", "30",
|
| 216 |
+
"--cfg_scale", "5.0",
|
| 217 |
+
"--seed", str(seed),
|
| 218 |
+
"--output_dir", str(work),
|
| 219 |
+
]
|
| 220 |
+
lf = open(log, "w")
|
| 221 |
+
popen = subprocess.Popen(cmd, cwd=str(REPO), env=env, stdout=lf, stderr=subprocess.STDOUT)
|
| 222 |
+
popen._log_handle = lf
|
| 223 |
+
popen._work_dir = work
|
| 224 |
+
popen._gpu = gpu
|
| 225 |
+
popen._item = item
|
| 226 |
+
popen._seq_idx = seq_idx
|
| 227 |
+
return popen
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def finalize(popen, out_dir: Path) -> str:
|
| 231 |
+
rc = popen.poll()
|
| 232 |
+
popen._log_handle.close()
|
| 233 |
+
shard_id, _h5_name, mp4_suffix, idx = popen._item
|
| 234 |
+
work = popen._work_dir
|
| 235 |
+
if rc != 0:
|
| 236 |
+
return f"FAIL rc={rc} {shard_id} ep{idx:08d}"
|
| 237 |
+
out_ext, out_wrist = output_paths(out_dir, idx, mp4_suffix)
|
| 238 |
+
src_ext = work / "generated_ext1.mp4"
|
| 239 |
+
src_wrist = work / "generated_wrist.mp4"
|
| 240 |
+
if not (src_ext.exists() and src_wrist.exists()):
|
| 241 |
+
return f"FAIL no_outputs {shard_id} ep{idx:08d}"
|
| 242 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 243 |
+
shutil.move(str(src_ext), str(out_ext))
|
| 244 |
+
shutil.move(str(src_wrist), str(out_wrist))
|
| 245 |
+
shutil.rmtree(work, ignore_errors=True)
|
| 246 |
+
return f"OK {shard_id} ep{idx:08d} (gpu={popen._gpu} seq={popen._seq_idx})"
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def main():
|
| 250 |
+
p = argparse.ArgumentParser()
|
| 251 |
+
p.add_argument("--sim_src", required=True)
|
| 252 |
+
p.add_argument("--out_dir", required=True)
|
| 253 |
+
p.add_argument("--scratch", required=True)
|
| 254 |
+
p.add_argument("--gpus", default="0,1,2,3")
|
| 255 |
+
p.add_argument("--target", type=int, default=0,
|
| 256 |
+
help="Max queue length (0 = all available). Useful for early-exit smoke runs.")
|
| 257 |
+
p.add_argument("--seq_offset", type=int, default=0,
|
| 258 |
+
help="Add this to every seq_idx so prompts/seeds vary across chunks.")
|
| 259 |
+
args = p.parse_args()
|
| 260 |
+
|
| 261 |
+
sim_src = Path(args.sim_src)
|
| 262 |
+
out_dir = Path(args.out_dir)
|
| 263 |
+
scratch = Path(args.scratch)
|
| 264 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 265 |
+
scratch.mkdir(parents=True, exist_ok=True)
|
| 266 |
+
gpus = [int(x) for x in args.gpus.split(",") if x.strip()]
|
| 267 |
+
|
| 268 |
+
scenes, fixed_prefix = _load_prompts()
|
| 269 |
+
t0 = time.time()
|
| 270 |
+
|
| 271 |
+
queue = build_queue(sim_src, args.target)
|
| 272 |
+
print(f"queue length: {len(queue)} (sim_src={sim_src})", flush=True)
|
| 273 |
+
if not queue:
|
| 274 |
+
print("empty queue; nothing to do.", flush=True)
|
| 275 |
+
return 0
|
| 276 |
+
|
| 277 |
+
eps_per_shard: dict[str, tuple[str, str, list[int]]] = {}
|
| 278 |
+
for shard_id, h5_name, mp4_suffix, idx in queue:
|
| 279 |
+
if shard_id not in eps_per_shard:
|
| 280 |
+
eps_per_shard[shard_id] = (h5_name, mp4_suffix, [])
|
| 281 |
+
eps_per_shard[shard_id][2].append(idx)
|
| 282 |
+
print(f"shards: {[(s, len(v[2])) for s, v in eps_per_shard.items()]}", flush=True)
|
| 283 |
+
|
| 284 |
+
depth_procs: dict[str, subprocess.Popen] = {}
|
| 285 |
+
failed_depth_shards: set[str] = set()
|
| 286 |
+
depth_attempts: dict[str, int] = {}
|
| 287 |
+
MAX_DEPTH_ATTEMPTS = 3
|
| 288 |
+
|
| 289 |
+
def spawn_depth(shard_id: str):
|
| 290 |
+
h5_name, mp4_suffix, eps = eps_per_shard[shard_id]
|
| 291 |
+
eps_sorted = sorted(set(eps))
|
| 292 |
+
p = launch_depth_for_shard_async(scratch, sim_src, shard_id, h5_name, mp4_suffix, eps_sorted)
|
| 293 |
+
if p is not None:
|
| 294 |
+
depth_procs[shard_id] = p
|
| 295 |
+
depth_attempts[shard_id] = depth_attempts.get(shard_id, 0) + 1
|
| 296 |
+
else:
|
| 297 |
+
print(f"[depth-bg done] {shard_id} (already had _depth_done marker)", flush=True)
|
| 298 |
+
|
| 299 |
+
for shard_id in eps_per_shard:
|
| 300 |
+
spawn_depth(shard_id)
|
| 301 |
+
|
| 302 |
+
def reap_depth():
|
| 303 |
+
for shard_id, p in list(depth_procs.items()):
|
| 304 |
+
rc = p.poll()
|
| 305 |
+
if rc is None:
|
| 306 |
+
continue
|
| 307 |
+
p._log_handle.close()
|
| 308 |
+
del depth_procs[shard_id]
|
| 309 |
+
if rc == 0:
|
| 310 |
+
(shard_scratch_dir(scratch, shard_id) / "_depth_done").touch()
|
| 311 |
+
print(f"[depth-bg done] {shard_id} rc=0", flush=True)
|
| 312 |
+
continue
|
| 313 |
+
attempts = depth_attempts.get(shard_id, 1)
|
| 314 |
+
if attempts < MAX_DEPTH_ATTEMPTS:
|
| 315 |
+
print(f"[depth-bg retry {attempts}/{MAX_DEPTH_ATTEMPTS}] {shard_id} rc={rc}", flush=True)
|
| 316 |
+
spawn_depth(shard_id)
|
| 317 |
+
else:
|
| 318 |
+
failed_depth_shards.add(shard_id)
|
| 319 |
+
print(f"[depth-bg FAIL] {shard_id} rc={rc} after {attempts} attempts", flush=True)
|
| 320 |
+
|
| 321 |
+
in_flight: dict[int, subprocess.Popen] = {}
|
| 322 |
+
cursor = 0
|
| 323 |
+
n_ok = n_skip = n_fail = 0
|
| 324 |
+
while cursor < len(queue) or in_flight or depth_procs:
|
| 325 |
+
reap_depth()
|
| 326 |
+
# Skip already-done items.
|
| 327 |
+
while cursor < len(queue) and already_done(out_dir, queue[cursor]):
|
| 328 |
+
n_skip += 1
|
| 329 |
+
cursor += 1
|
| 330 |
+
# Skip items whose shard failed depth.
|
| 331 |
+
while cursor < len(queue) and queue[cursor][0] in failed_depth_shards:
|
| 332 |
+
print(f"[skip-depth-fail] cursor={cursor} {queue[cursor][0]} ep{queue[cursor][3]:08d}",
|
| 333 |
+
flush=True)
|
| 334 |
+
n_fail += 1
|
| 335 |
+
cursor += 1
|
| 336 |
+
# Dispatch onto free GPUs.
|
| 337 |
+
for gpu in gpus:
|
| 338 |
+
if gpu in in_flight or cursor >= len(queue):
|
| 339 |
+
continue
|
| 340 |
+
item = queue[cursor]
|
| 341 |
+
if not is_shard_depth_done(scratch, item[0]):
|
| 342 |
+
break
|
| 343 |
+
try:
|
| 344 |
+
popen = launch_inference(
|
| 345 |
+
scratch, out_dir, scenes, fixed_prefix, gpu, cursor + args.seq_offset, item,
|
| 346 |
+
)
|
| 347 |
+
in_flight[gpu] = popen
|
| 348 |
+
print(f"[launch gpu={gpu}] cursor={cursor} {item[0]} ep{item[3]:08d}", flush=True)
|
| 349 |
+
except Exception as exc:
|
| 350 |
+
print(f"[launch FAIL] {item}: {exc}", flush=True)
|
| 351 |
+
n_fail += 1
|
| 352 |
+
cursor += 1
|
| 353 |
+
progressed = False
|
| 354 |
+
for gpu, popen in list(in_flight.items()):
|
| 355 |
+
if popen.poll() is None:
|
| 356 |
+
continue
|
| 357 |
+
msg = finalize(popen, out_dir)
|
| 358 |
+
print(f"[done gpu={gpu}] {msg}", flush=True)
|
| 359 |
+
if msg.startswith("OK"):
|
| 360 |
+
n_ok += 1
|
| 361 |
+
else:
|
| 362 |
+
n_fail += 1
|
| 363 |
+
del in_flight[gpu]
|
| 364 |
+
progressed = True
|
| 365 |
+
if not progressed and (in_flight or depth_procs):
|
| 366 |
+
time.sleep(5)
|
| 367 |
+
|
| 368 |
+
dt = time.time() - t0
|
| 369 |
+
print(
|
| 370 |
+
f"\n== gen_chunk done sim_src={sim_src.name} out={out_dir.name} "
|
| 371 |
+
f"ok={n_ok} skip={n_skip} fail={n_fail} queue={len(queue)} elapsed={dt/60:.1f}min ==",
|
| 372 |
+
flush=True,
|
| 373 |
+
)
|
| 374 |
+
return 1 if n_fail else 0
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
if __name__ == "__main__":
|
| 378 |
+
sys.exit(main())
|
fridge_m/_setup/scripts/smoke_gen.sh
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Smoke-test the gen pipeline for fridge_m on a single trajectory.
|
| 3 |
+
#
|
| 4 |
+
# Usage: bash smoke_gen.sh <GPU_ID>
|
| 5 |
+
# GPU_ID: CUDA device for the inference (depth runs on the same GPU).
|
| 6 |
+
#
|
| 7 |
+
# Assumes:
|
| 8 |
+
# - sim output is in /scr/ravenh/fridge_m/smoke_sim/
|
| 9 |
+
# - prompts.json is at /scr/ravenh/fridge_m/prompts/prompts.json
|
| 10 |
+
#
|
| 11 |
+
# Outputs:
|
| 12 |
+
# - depth/mask mp4s under /scr/ravenh/fridge_m/smoke_gen/_depth/
|
| 13 |
+
# - generated_ext1.mp4, generated_wrist.mp4 under /scr/ravenh/fridge_m/smoke_gen/inf/
|
| 14 |
+
# - VRAM snapshots in /scr/ravenh/fridge_m/logs/smoke_gen_vram.csv
|
| 15 |
+
#
|
| 16 |
+
set -e
|
| 17 |
+
GPU="${1:-1}"
|
| 18 |
+
REPO=/svl/u/ravenh/renderscale/Sim2RealGen_Video_Model
|
| 19 |
+
SIM_DIR=/scr/ravenh/fridge_m/smoke_sim
|
| 20 |
+
GEN_BASE=/scr/ravenh/fridge_m/smoke_gen
|
| 21 |
+
DEPTH_OUT="$GEN_BASE/_depth"
|
| 22 |
+
INF_OUT="$GEN_BASE/inf"
|
| 23 |
+
LOG_DIR=/scr/ravenh/fridge_m/logs
|
| 24 |
+
LORA="$REPO/lora_ckpts/Wan2.1-Fun-V1.1-1.3B-DualControl-3View-PrevFrame_minimal_lora/step-4740.safetensors"
|
| 25 |
+
|
| 26 |
+
mkdir -p "$DEPTH_OUT" "$INF_OUT" "$LOG_DIR"
|
| 27 |
+
|
| 28 |
+
# Pick the first available exo-camera RGB mp4 (this is the unambiguous "traj finalized" signal).
|
| 29 |
+
EXO_MP4=$(ls "$SIM_DIR"/episode_*_exo_camera_1_robot_rgb*.mp4 2>/dev/null | head -1)
|
| 30 |
+
if [ -z "$EXO_MP4" ]; then
|
| 31 |
+
echo "ERROR: no exo-camera mp4 found in $SIM_DIR" >&2
|
| 32 |
+
exit 1
|
| 33 |
+
fi
|
| 34 |
+
EP=$(basename "$EXO_MP4" | sed -E 's/^episode_([0-9]{8})_.*/\1/')
|
| 35 |
+
echo "[smoke_gen] using episode $EP from $SIM_DIR (GPU=$GPU)"
|
| 36 |
+
|
| 37 |
+
source /svl/u/ravenh/miniconda3/etc/profile.d/conda.sh
|
| 38 |
+
conda activate mlspaces
|
| 39 |
+
|
| 40 |
+
# Background nvidia-smi VRAM polling (1s) until inference exits.
|
| 41 |
+
VRAM_CSV="$LOG_DIR/smoke_gen_vram.csv"
|
| 42 |
+
: > "$VRAM_CSV"
|
| 43 |
+
(
|
| 44 |
+
while :; do
|
| 45 |
+
ts=$(date +%s)
|
| 46 |
+
nvidia-smi --query-gpu=index,memory.used --format=csv,noheader,nounits \
|
| 47 |
+
| awk -v ts=$ts '{print ts","$0}' >> "$VRAM_CSV"
|
| 48 |
+
sleep 1
|
| 49 |
+
done
|
| 50 |
+
) &
|
| 51 |
+
VRAM_PID=$!
|
| 52 |
+
trap "kill $VRAM_PID 2>/dev/null || true" EXIT
|
| 53 |
+
|
| 54 |
+
# --- Step 1: depth_methods.py ---
|
| 55 |
+
echo "[smoke_gen] step 1/2 depth_methods.py"
|
| 56 |
+
t0=$(date +%s)
|
| 57 |
+
CUDA_VISIBLE_DEVICES="$GPU" python "$REPO/scripts/depth_methods.py" \
|
| 58 |
+
--sim_dir "$SIM_DIR" \
|
| 59 |
+
--out_root "$DEPTH_OUT" \
|
| 60 |
+
--methods h5_v4 \
|
| 61 |
+
--method_label h5_v4 \
|
| 62 |
+
--use_raw_pct \
|
| 63 |
+
--raw_pct 1,99 \
|
| 64 |
+
--inv_clip 1,20 \
|
| 65 |
+
--inv_map log \
|
| 66 |
+
--depth_size 416,240 \
|
| 67 |
+
--episodes "$EP" \
|
| 68 |
+
2>&1 | tee "$LOG_DIR/smoke_gen_depth.log"
|
| 69 |
+
t1=$(date +%s)
|
| 70 |
+
echo "[smoke_gen] depth_methods.py done in $((t1-t0))s"
|
| 71 |
+
|
| 72 |
+
DEPTH_ROOT="$DEPTH_OUT/h5_v4/episode_$EP"
|
| 73 |
+
EXT_DEPTH="$DEPTH_ROOT/ext1/depth/original_depth.mp4"
|
| 74 |
+
EXT_MASK="$DEPTH_ROOT/ext1/mask/rgb_robot.mp4"
|
| 75 |
+
WRIST_DEPTH="$DEPTH_ROOT/wrist/depth/original_depth.mp4"
|
| 76 |
+
WRIST_MASK="$DEPTH_ROOT/wrist/mask/rgb_robot.mp4"
|
| 77 |
+
for p in "$EXT_DEPTH" "$EXT_MASK" "$WRIST_DEPTH" "$WRIST_MASK"; do
|
| 78 |
+
[ -f "$p" ] || { echo "ERROR: missing $p" >&2; exit 1; }
|
| 79 |
+
done
|
| 80 |
+
|
| 81 |
+
# --- Step 2: inference_long_video.py ---
|
| 82 |
+
# Pick the first prompt from prompts.json + fixed prefix.
|
| 83 |
+
PROMPT=$(python -c "import json,sys; d=json.load(open('/scr/ravenh/fridge_m/prompts/prompts.json')); print(f'Video of a real {d[\"scenes\"][0]}. ' + d['fixed_prefix'])")
|
| 84 |
+
echo "[smoke_gen] prompt: $PROMPT" | head -c 400
|
| 85 |
+
echo ""
|
| 86 |
+
echo "$PROMPT" > "$INF_OUT/prompt.txt"
|
| 87 |
+
|
| 88 |
+
echo "[smoke_gen] step 2/2 inference_long_video.py"
|
| 89 |
+
t2=$(date +%s)
|
| 90 |
+
cd "$REPO"
|
| 91 |
+
DIFFSYNTH_SKIP_DOWNLOAD=true CUDA_VISIBLE_DEVICES="$GPU" python "$REPO/sim2realgen/inference_long_video.py" \
|
| 92 |
+
--views \
|
| 93 |
+
"ext1:$EXT_DEPTH:$EXT_MASK" \
|
| 94 |
+
"wrist:$WRIST_DEPTH:$WRIST_MASK" \
|
| 95 |
+
--prompt "$PROMPT" \
|
| 96 |
+
--lora_path "$LORA" \
|
| 97 |
+
--height 240 --width 416 \
|
| 98 |
+
--clip_length 81 \
|
| 99 |
+
--num_inference_steps 30 \
|
| 100 |
+
--cfg_scale 5.0 \
|
| 101 |
+
--seed 1000 \
|
| 102 |
+
--output_dir "$INF_OUT" \
|
| 103 |
+
2>&1 | tee "$LOG_DIR/smoke_gen_inf.log"
|
| 104 |
+
t3=$(date +%s)
|
| 105 |
+
echo "[smoke_gen] inference done in $((t3-t2))s; total step2 wall=$((t3-t2))s"
|
| 106 |
+
echo "[smoke_gen] outputs: $(ls -la $INF_OUT/*.mp4 2>/dev/null)"
|
| 107 |
+
|
| 108 |
+
# Peak VRAM
|
| 109 |
+
echo "[smoke_gen] peak VRAM (MiB) per GPU during run:"
|
| 110 |
+
awk -F, '{vram[$2]=($3>vram[$2]?$3:vram[$2])} END{for (g in vram) printf " GPU%s peak=%dMiB\n", g, vram[g]}' "$VRAM_CSV"
|
| 111 |
+
echo "[smoke_gen] DONE depth=$((t1-t0))s inf=$((t3-t2))s total=$((t3-t0))s"
|
fridge_m/_setup/scripts/stop_after_chunk_6.sh
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Watches chunked_runner.log for the chunk-7 launch line and stops the runner
|
| 3 |
+
# before chunk 7 sim shards do any real work. Chunks 1..6 will be fully sim+gen
|
| 4 |
+
# complete (the runner is sequential per chunk, so by the time the chunk-7 start
|
| 5 |
+
# line appears, chunk 6's gen has fully finished).
|
| 6 |
+
|
| 7 |
+
set -uo pipefail
|
| 8 |
+
|
| 9 |
+
RUNNER_PID=${RUNNER_PID:-542661}
|
| 10 |
+
LOG=/scr/ravenh/fridge_m/logs/chunked_runner.log
|
| 11 |
+
STOP_AFTER_CHUNK=${STOP_AFTER_CHUNK:-6}
|
| 12 |
+
|
| 13 |
+
NEXT=$((STOP_AFTER_CHUNK + 1))
|
| 14 |
+
echo "[stop_watcher] watching $LOG for chunk-$NEXT launch (= chunks 1..$STOP_AFTER_CHUNK fully done); runner_pid=$RUNNER_PID"
|
| 15 |
+
|
| 16 |
+
stdbuf -oL tail -n 1000 -F "$LOG" 2>/dev/null \
|
| 17 |
+
| stdbuf -oL grep -E --line-buffered "^=== chunk $NEXT / " \
|
| 18 |
+
| while IFS= read -r line; do
|
| 19 |
+
ts=$(date -Iseconds)
|
| 20 |
+
echo "[stop_watcher] TRIGGER at $ts: $line"
|
| 21 |
+
echo "[stop_watcher] SIGTERMing runner_pid=$RUNNER_PID"
|
| 22 |
+
kill -TERM "$RUNNER_PID" 2>/dev/null || true
|
| 23 |
+
sleep 1
|
| 24 |
+
echo "[stop_watcher] killing any newly-launched chunk-$NEXT sim shards (still in startup)"
|
| 25 |
+
pkill -TERM -f 'data_gen_fridge_m\.sh' 2>/dev/null || true
|
| 26 |
+
pkill -TERM -f 'run_pipeline_no_clip\.py' 2>/dev/null || true
|
| 27 |
+
sleep 5
|
| 28 |
+
pkill -KILL -f 'data_gen_fridge_m\.sh' 2>/dev/null || true
|
| 29 |
+
pkill -KILL -f 'run_pipeline_no_clip\.py' 2>/dev/null || true
|
| 30 |
+
# Remove the aborted chunk-N dir if it has 0 finalized trajs.
|
| 31 |
+
aborted="/scr/ravenh/fridge_m/sim_chunks/chunk_$(printf '%03d' $NEXT)"
|
| 32 |
+
if [ -d "$aborted" ]; then
|
| 33 |
+
n=$(ls "$aborted"/episode_*_exo_camera_1_robot_rgb*.mp4 2>/dev/null | wc -l)
|
| 34 |
+
echo "[stop_watcher] aborted chunk dir $aborted finalized=$n"
|
| 35 |
+
if [ "$n" = "0" ]; then
|
| 36 |
+
rm -rf "$aborted"
|
| 37 |
+
rm -rf "/scr/ravenh/fridge_m/gen_chunks/chunk_$(printf '%03d' $NEXT)"
|
| 38 |
+
rm -rf "/scr/ravenh/fridge_m/_workdir_gen/chunk_$(printf '%03d' $NEXT)"
|
| 39 |
+
echo "[stop_watcher] removed empty $aborted and matching gen/scratch dirs"
|
| 40 |
+
fi
|
| 41 |
+
fi
|
| 42 |
+
echo "[stop_watcher] DONE at $(date -Iseconds); parent should run final HF flush next"
|
| 43 |
+
exit 0
|
| 44 |
+
done
|
fridge_m/_setup/scripts/stop_at_300.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Watches chunked_runner.log for a chunk-start line where current_sim_trajs >= 300.
|
| 3 |
+
# When it fires, SIGTERMs the chunked_runner and any newly-launched sim shards
|
| 4 |
+
# (which are still in startup at this point per the chunked_runner's step1 -> step2
|
| 5 |
+
# transition window — no rollouts in flight yet). Prior chunks (1..N-1) are fully
|
| 6 |
+
# sim+gen complete because the runner is sequential per chunk.
|
| 7 |
+
#
|
| 8 |
+
# After the kill, removes the aborted chunk's sim dir (empty/partial; safer than
|
| 9 |
+
# pushing partial mp4s to HF) and signals the parent script to handle final HF flush.
|
| 10 |
+
|
| 11 |
+
set -uo pipefail
|
| 12 |
+
|
| 13 |
+
RUNNER_PID=${RUNNER_PID:-542661}
|
| 14 |
+
LOG=/scr/ravenh/fridge_m/logs/chunked_runner.log
|
| 15 |
+
THRESHOLD=${THRESHOLD:-300}
|
| 16 |
+
|
| 17 |
+
echo "[stop_watcher] watching $LOG for current_sim_trajs >= $THRESHOLD; runner_pid=$RUNNER_PID"
|
| 18 |
+
|
| 19 |
+
stdbuf -oL tail -n 1000 -F "$LOG" 2>/dev/null \
|
| 20 |
+
| stdbuf -oL grep -E -o 'current_sim_trajs=[0-9]+' \
|
| 21 |
+
| while IFS= read -r line; do
|
| 22 |
+
n=$(echo "$line" | cut -d= -f2)
|
| 23 |
+
if [ "$n" -ge "$THRESHOLD" ]; then
|
| 24 |
+
ts=$(date -Iseconds)
|
| 25 |
+
echo "[stop_watcher] TRIGGER at $ts: current_sim_trajs=$n >= $THRESHOLD"
|
| 26 |
+
echo "[stop_watcher] SIGTERMing runner_pid=$RUNNER_PID"
|
| 27 |
+
kill -TERM "$RUNNER_PID" 2>/dev/null || true
|
| 28 |
+
sleep 1
|
| 29 |
+
echo "[stop_watcher] killing any newly-launched sim shards (still in startup)"
|
| 30 |
+
pkill -TERM -f 'data_gen_fridge_m\.sh' 2>/dev/null || true
|
| 31 |
+
pkill -TERM -f 'run_pipeline_no_clip\.py' 2>/dev/null || true
|
| 32 |
+
sleep 5
|
| 33 |
+
pkill -KILL -f 'data_gen_fridge_m\.sh' 2>/dev/null || true
|
| 34 |
+
pkill -KILL -f 'run_pipeline_no_clip\.py' 2>/dev/null || true
|
| 35 |
+
# Identify the aborted chunk and clean it up if it has no finalized trajs.
|
| 36 |
+
latest_dir=$(ls -d /scr/ravenh/fridge_m/sim_chunks/chunk_*/ 2>/dev/null | tail -1)
|
| 37 |
+
if [ -n "$latest_dir" ]; then
|
| 38 |
+
latest_count=$(ls "$latest_dir"episode_*_exo_camera_1_robot_rgb*.mp4 2>/dev/null | wc -l)
|
| 39 |
+
echo "[stop_watcher] latest sim chunk: $latest_dir (finalized=$latest_count)"
|
| 40 |
+
if [ "$latest_count" = "0" ]; then
|
| 41 |
+
echo "[stop_watcher] removing empty aborted chunk $latest_dir"
|
| 42 |
+
rm -rf "$latest_dir"
|
| 43 |
+
# also drop the matching gen_chunks empty dir
|
| 44 |
+
base=$(basename "$latest_dir")
|
| 45 |
+
rm -rf "/scr/ravenh/fridge_m/gen_chunks/$base"
|
| 46 |
+
rm -rf "/scr/ravenh/fridge_m/_workdir_gen/$base"
|
| 47 |
+
fi
|
| 48 |
+
fi
|
| 49 |
+
echo "[stop_watcher] DONE at $(date -Iseconds); parent should run final HF flush next"
|
| 50 |
+
exit 0
|
| 51 |
+
fi
|
| 52 |
+
done
|