AbstractPhil commited on
Commit
18621b4
·
verified ·
1 Parent(s): dae9733

anima_closeout v16: stop deriving cache directory names. v15 built the AR dir as ar_frames_{ar}x{f} but bucket_suffix (dataset.py:60-70) joins 2-tuples with an UNDERSCORE (ar_frames_0.630_1) and 4-tuples with 'x' (cache_0.630x400x640x1). The bed now WALKS the cache root, discovering every 'latents' and 'text_embeddings_*' dir (uncond_* excluded by prefix), and joins on image_spec, which is globally unique — so no directory-naming convention can break it again. Verified on a synthetic cache built by the fork's own ParquetCache with names from the fork's own bucket_suffix: 3 AR/size bucket pairs, shuffled latents, uncond + iteration_order decoys -> 24/24 rows correctly paired, each image exactly once.

Browse files
Files changed (1) hide show
  1. colab/anima_closeout.ipynb +44 -30
colab/anima_closeout.ipynb CHANGED
@@ -966,10 +966,26 @@
966
  "# (dataset.py:312), so we join on image_spec and iterate in sorted spec\n",
967
  "# order, which also makes the bed reproducible run-to-run.\n",
968
  "cache_root = CFG[\"eval_cache_dir\"]\n",
969
- "size_dirs = sorted(d for d in os.listdir(cache_root)\n",
970
- " if d.startswith(\"cache_\")\n",
971
- " and os.path.isdir(os.path.join(cache_root, d)))\n",
972
- "assert size_dirs, f\"no cache_* size-bucket dirs under {cache_root}\"\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973
  "\n",
974
  "def read_cache(d):\n",
975
  " shards = sorted(p for p in os.listdir(d)\n",
@@ -1000,40 +1016,38 @@
1000
  "\n",
1001
  "LAT = [\"latents\"]\n",
1002
  "TE = [\"prompt_embeds\", \"attn_mask\", \"t5_input_ids\", \"t5_attn_mask\"]\n",
 
 
 
 
 
 
 
 
 
 
 
1003
  "rows = []\n",
1004
- "for sd in size_dirs:\n",
1005
- " parts = sd[len(\"cache_\"):].split(\"x\") # {ar}x{w}x{h}x{frames}\n",
1006
- " ar_dir = os.path.join(cache_root, f\"ar_frames_{parts[0]}x{parts[-1]}\")\n",
1007
- " assert os.path.isdir(ar_dir), (\n",
1008
- " f\"{sd}: expected AR-bucket dir {ar_dir} \u2014 text embeddings are \"\n",
1009
- " \"cached per AR bucket, not per size bucket\")\n",
1010
- " te_names = sorted(d for d in os.listdir(ar_dir)\n",
1011
- " if d.startswith(\"text_embeddings_\"))\n",
1012
- " assert len(te_names) == 1, \\\n",
1013
- " f\"{ar_dir}: expected one text_embeddings_* cache, found {te_names}\"\n",
1014
- " lat = by_spec(read_cache(os.path.join(cache_root, sd, \"latents\")),\n",
1015
- " \"latents\")\n",
1016
- " te = by_spec(read_cache(os.path.join(ar_dir, te_names[0])),\n",
1017
- " \"text embedding\")\n",
1018
  " for c in LAT:\n",
1019
- " _s = next(iter(lat.values()))[0].schema.names\n",
1020
- " assert c + \"__shape\" in _s, (sd, _s[:8])\n",
1021
- " for c in TE:\n",
1022
- " _s = next(iter(te.values()))[0].schema.names\n",
1023
- " assert c + \"__shape\" in _s, (ar_dir, _s[:8])\n",
1024
- " _missing = [s for s in lat if s not in te]\n",
1025
  " assert not _missing, (\n",
1026
- " f\"{sd}: {len(_missing)} latents have no text embedding for their \"\n",
1027
- " f\"image_spec (e.g. {_missing[:1]}) \u2014 caches are out of sync\")\n",
 
1028
  " for s in sorted(lat):\n",
1029
  " lt, lj = lat[s]\n",
1030
- " tt, tj = te[s]\n",
1031
  " r = {c: decol(lt, c, lj) for c in LAT}\n",
1032
  " r.update({c: decol(tt, c, tj) for c in TE})\n",
1033
  " rows.append(r)\n",
1034
- " print(f\" {sd}: {len(lat)} rows joined on image_spec \"\n",
1035
- " f\"(AR pool {len(te)})\", flush=True)\n",
1036
- "print(f\"eval cache rows: {len(rows)} from {len(size_dirs)} size bucket(s)\",\n",
1037
  " flush=True)\n",
1038
  "rows = rows[:int(os.environ.get(\"VB_MAX_ROWS\", \"512\"))]\n",
1039
  "assert rows\n",
 
966
  "# (dataset.py:312), so we join on image_spec and iterate in sorted spec\n",
967
  "# order, which also makes the bed reproducible run-to-run.\n",
968
  "cache_root = CFG[\"eval_cache_dir\"]\n",
969
+ "# DISCOVER both kinds of cache by walking the tree. Do NOT derive one\n",
970
+ "# directory name from the other: size buckets are\n",
971
+ "# cache_{ar:.3f}x{w}x{h}x{f} but AR buckets are ar_frames_{ar:.3f}_{f} \u2014\n",
972
+ "# 'x' vs '_' (bucket_suffix, dataset.py:60-70). image_spec is globally\n",
973
+ "# unique per image, so one map over every text-embedding cache joins any\n",
974
+ "# latents cache unambiguously, whatever the directories are called.\n",
975
+ "lat_dirs, te_dirs = [], []\n",
976
+ "for _dp, _dns, _ in os.walk(cache_root):\n",
977
+ " for _d in _dns:\n",
978
+ " if _d == \"latents\":\n",
979
+ " lat_dirs.append(os.path.join(_dp, _d))\n",
980
+ " elif _d.startswith(\"text_embeddings_\"): # excludes uncond_*\n",
981
+ " te_dirs.append(os.path.join(_dp, _d))\n",
982
+ "lat_dirs.sort(); te_dirs.sort()\n",
983
+ "print(\"latents caches: \",\n",
984
+ " [os.path.relpath(d, cache_root) for d in lat_dirs], flush=True)\n",
985
+ "print(\"text-embed caches:\",\n",
986
+ " [os.path.relpath(d, cache_root) for d in te_dirs], flush=True)\n",
987
+ "assert lat_dirs, f\"no latents cache under {cache_root}\"\n",
988
+ "assert te_dirs, f\"no text_embeddings_* cache under {cache_root}\"\n",
989
  "\n",
990
  "def read_cache(d):\n",
991
  " shards = sorted(p for p in os.listdir(d)\n",
 
1016
  "\n",
1017
  "LAT = [\"latents\"]\n",
1018
  "TE = [\"prompt_embeds\", \"attn_mask\", \"t5_input_ids\", \"t5_attn_mask\"]\n",
1019
+ "\n",
1020
+ "te_map = {}\n",
1021
+ "for d in te_dirs:\n",
1022
+ " tbs = read_cache(d)\n",
1023
+ " for c in TE:\n",
1024
+ " assert c + \"__shape\" in tbs[0].schema.names, \\\n",
1025
+ " (d, tbs[0].schema.names[:8])\n",
1026
+ " for s, loc in by_spec(tbs, \"text embedding\").items():\n",
1027
+ " te_map.setdefault(s, loc)\n",
1028
+ "print(f\"text embeddings: {len(te_map)} unique image_spec\", flush=True)\n",
1029
+ "\n",
1030
  "rows = []\n",
1031
+ "for d in lat_dirs:\n",
1032
+ " tbs = read_cache(d)\n",
 
 
 
 
 
 
 
 
 
 
 
 
1033
  " for c in LAT:\n",
1034
+ " assert c + \"__shape\" in tbs[0].schema.names, \\\n",
1035
+ " (d, tbs[0].schema.names[:8])\n",
1036
+ " lat = by_spec(tbs, \"latents\")\n",
1037
+ " _missing = [s for s in lat if s not in te_map]\n",
 
 
1038
  " assert not _missing, (\n",
1039
+ " f\"{os.path.relpath(d, cache_root)}: {len(_missing)} latents have \"\n",
1040
+ " f\"no text embedding for their image_spec (e.g. {_missing[:1]}) \u2014 \"\n",
1041
+ " \"caches are out of sync\")\n",
1042
  " for s in sorted(lat):\n",
1043
  " lt, lj = lat[s]\n",
1044
+ " tt, tj = te_map[s]\n",
1045
  " r = {c: decol(lt, c, lj) for c in LAT}\n",
1046
  " r.update({c: decol(tt, c, tj) for c in TE})\n",
1047
  " rows.append(r)\n",
1048
+ " print(f\" {os.path.relpath(d, cache_root)}: {len(lat)} rows joined \"\n",
1049
+ " \"on image_spec\", flush=True)\n",
1050
+ "print(f\"eval cache rows: {len(rows)} from {len(lat_dirs)} latents cache(s)\",\n",
1051
  " flush=True)\n",
1052
  "rows = rows[:int(os.environ.get(\"VB_MAX_ROWS\", \"512\"))]\n",
1053
  "assert rows\n",