Download check_force_range.py from syCen/action-worldmodel-bench: direct link, hf CLI and curl.
- Browser
- Download file 3.7 kB
-
https://huggingface.co/datasets/syCen/action-worldmodel-bench/resolve/main/check_force_range.py
- Command line
-
hf download hf://datasets/syCen/action-worldmodel-bench/check_force_range.py
-
curl -L -o check_force_range.py https://huggingface.co/datasets/syCen/action-worldmodel-bench/resolve/main/check_force_range.py
3.7 kB
| """ | |
| check_force_range.py | |
| Scan ALL clips and report the RAW (std-normalized, pre-clip) force abs-max per | |
| clip, so you know exactly how many clips have extreme forces (>10, >15, etc). | |
| This does NOT depend on the loss ranking -- it reads the actual data magnitudes. | |
| Reports per-clip absmax (normalized by active std, BEFORE force_clip), sorted, | |
| plus a histogram of how many clips exceed each threshold. | |
| Run: | |
| python examples/wanvideo/model_training/check_force_range.py \ | |
| --clips ... --stats ... --source_root ... | |
| """ | |
| import argparse, os, sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| import numpy as np | |
| from tqdm import tqdm | |
| # load stats + clips directly, replicate the dataloader normalization WITHOUT clip | |
| import json | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--clips", required=True) | |
| ap.add_argument("--stats", required=True) | |
| ap.add_argument("--source_root", required=True) | |
| args = ap.parse_args() | |
| stats = json.load(open(args.stats)) | |
| # force per-channel active std (the normalization the dataloader uses) | |
| std = np.array(stats.get("force_ch_active_std", | |
| stats.get("force_ch_std"))) # (6,) | |
| clips = json.load(open(args.clips))["clips"] | |
| rows = [] | |
| for i, c in enumerate(tqdm(clips, desc="clips")): | |
| # resolve force npy paths for this clip | |
| ep = c["episode"] if isinstance(c, dict) and "episode" in c else "" | |
| fpaths = None | |
| for k in ("force_paths", "force", "force_npy"): | |
| if isinstance(c, dict) and k in c: | |
| fpaths = c[k]; break | |
| if fpaths is None and "frame_indices" in c: | |
| base = os.path.join("modalities", "force") | |
| fpaths = [os.path.join(base, f"{idx:06d}.npy") for idx in c["frame_indices"]] | |
| if fpaths is None: | |
| continue | |
| clip_absmax = 0.0 | |
| per_ch_absmax = np.zeros(6) | |
| n_loaded = 0 | |
| for fp in fpaths: | |
| # force_paths are relative to source_root/episode | |
| full = fp | |
| if not os.path.isabs(full): | |
| full = os.path.join(args.source_root, ep, fp) | |
| if not os.path.exists(full): | |
| continue | |
| fp = full | |
| n_loaded += 1 | |
| f = np.load(fp).astype(np.float64) # (6,H,W) | |
| fn = f / std[:, None, None] # normalize, NO clip | |
| a = np.abs(fn) | |
| clip_absmax = max(clip_absmax, a.max()) | |
| per_ch_absmax = np.maximum(per_ch_absmax, a.reshape(6, -1).max(1)) | |
| if i == 0: | |
| print(f"[debug] clip 0: episode={ep!r}, " | |
| f"{len(fpaths)} paths, {n_loaded} loaded, " | |
| f"example full path:\n " | |
| f"{os.path.join(args.source_root, ep, fpaths[0])}") | |
| rows.append((i, clip_absmax, per_ch_absmax)) | |
| rows.sort(key=lambda r: -r[1]) | |
| print("\n" + "="*72) | |
| print("ALL clips sorted by normalized force abs-max (BEFORE clip):") | |
| print(f"{'clip':>4s} {'absmax':>8s} per-channel absmax [Lfx Lfy Lfz Rfx Rfy Rfz]") | |
| print("-"*72) | |
| for i, am, pc in rows: | |
| pcs = " ".join(f"{v:4.1f}" for v in pc) | |
| print(f"{i:4d} {am:8.2f} [{pcs}]") | |
| absmaxes = np.array([r[1] for r in rows]) | |
| print("="*72) | |
| for thr in [5, 8, 10, 12, 15, 20]: | |
| n = (absmaxes > thr).sum() | |
| print(f" clips with force absmax > {thr:2d}: {n}/{len(absmaxes)}") | |
| print(f"\n overall max across all clips: {absmaxes.max():.2f}") | |
| print(f" p50={np.percentile(absmaxes,50):.2f} " | |
| f"p90={np.percentile(absmaxes,90):.2f} " | |
| f"p99={np.percentile(absmaxes,99):.2f}") | |
| if __name__ == "__main__": | |
| main() |