anima_closeout v19: the bed's NaN was AUTOCAST_DTYPE. utils/common.py defines it as None and train.py sets it at :287 (common.AUTOCAST_DTYPE = config['model']['dtype']) BEFORE importing any model module — models/*.py do `from utils.common import AUTOCAST_DTYPE` and bake the value into their @torch .autocast decorators at class-definition time. The bed never set it, so every layer ran under autocast(dtype=None), which resolves to FP16 on cuda (verified: fast_dtype == float16), and the bf16-trained 2B DiT overflowed to NaN — the 'DETERMINISM FAILED' assert was just nan != nan. Bed now sets bf16 immediately after importing utils.common with an assert that no model module is loaded yet, and eval_arm raises a real numerics error on any non-finite loss instead of misreporting determinism.
Browse files- colab/anima_closeout.ipynb +17 -1
colab/anima_closeout.ipynb
CHANGED
|
@@ -935,7 +935,7 @@
|
|
| 935 |
"# arm. Reuses the fork's eval cache (latents + text embeds) and the fork's\n",
|
| 936 |
"# own transformer + llm_adapter call path (mirrored from\n",
|
| 937 |
"# cosmos_predict2.py InitialLayer/LLMAdapterLayer).\n",
|
| 938 |
-
"import json, os, sys, time\n",
|
| 939 |
"sys.path.insert(0, \".\") # fork root (cwd)\n",
|
| 940 |
"import utils.common # bind fork utils BEFORE ComfyUI\n",
|
| 941 |
"sys.path.append(\"submodules/ComfyUI\")\n",
|
|
@@ -949,6 +949,17 @@
|
|
| 949 |
"import torch\n",
|
| 950 |
"import pyarrow.parquet as pq\n",
|
| 951 |
"\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 952 |
"CFG = json.load(open(os.environ[\"VB_CONFIG\"]))\n",
|
| 953 |
"QUANTILES = [0.1, 0.3, 0.5, 0.7, 0.9]\n",
|
| 954 |
"DEV = \"cuda\"\n",
|
|
@@ -1168,6 +1179,11 @@
|
|
| 1168 |
" results[\"arms\"][name] = {\"loss_by_quantile\": per_q,\n",
|
| 1169 |
" \"loss_mean\": sum(per_q.values()) / len(per_q),\n",
|
| 1170 |
" \"lesion\": lesion}\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1171 |
" print(f\"[{name}] mean {results['arms'][name]['loss_mean']:.6f} \"\n",
|
| 1172 |
" f\"({(time.time() - t0) / 60:.1f} min)\", flush=True)\n",
|
| 1173 |
"\n",
|
|
|
|
| 935 |
"# arm. Reuses the fork's eval cache (latents + text embeds) and the fork's\n",
|
| 936 |
"# own transformer + llm_adapter call path (mirrored from\n",
|
| 937 |
"# cosmos_predict2.py InitialLayer/LLMAdapterLayer).\n",
|
| 938 |
+
"import json, math, os, sys, time\n",
|
| 939 |
"sys.path.insert(0, \".\") # fork root (cwd)\n",
|
| 940 |
"import utils.common # bind fork utils BEFORE ComfyUI\n",
|
| 941 |
"sys.path.append(\"submodules/ComfyUI\")\n",
|
|
|
|
| 949 |
"import torch\n",
|
| 950 |
"import pyarrow.parquet as pq\n",
|
| 951 |
"\n",
|
| 952 |
+
"# EXACTLY train.py:287, and it MUST happen before any model module is\n",
|
| 953 |
+
"# imported: models/*.py do `from utils.common import AUTOCAST_DTYPE`, so\n",
|
| 954 |
+
"# their @torch.autocast('cuda', dtype=AUTOCAST_DTYPE) decorators bake the\n",
|
| 955 |
+
"# value at class-definition time. Left at its None default it resolves to\n",
|
| 956 |
+
"# FP16 on cuda, and a bf16-trained 2B DiT overflows to NaN \u2014 which is\n",
|
| 957 |
+
"# exactly what an unset bed produced (loss nan, and the determinism assert\n",
|
| 958 |
+
"# then misfired because nan != nan).\n",
|
| 959 |
+
"utils.common.AUTOCAST_DTYPE = torch.bfloat16\n",
|
| 960 |
+
"assert \"models.cosmos_predict2\" not in sys.modules, \\\n",
|
| 961 |
+
" \"a model module was imported before AUTOCAST_DTYPE was set\"\n",
|
| 962 |
+
"\n",
|
| 963 |
"CFG = json.load(open(os.environ[\"VB_CONFIG\"]))\n",
|
| 964 |
"QUANTILES = [0.1, 0.3, 0.5, 0.7, 0.9]\n",
|
| 965 |
"DEV = \"cuda\"\n",
|
|
|
|
| 1179 |
" results[\"arms\"][name] = {\"loss_by_quantile\": per_q,\n",
|
| 1180 |
" \"loss_mean\": sum(per_q.values()) / len(per_q),\n",
|
| 1181 |
" \"lesion\": lesion}\n",
|
| 1182 |
+
" # a non-finite loss is a NUMERICS failure, not a determinism failure \u2014\n",
|
| 1183 |
+
" # say so, instead of letting nan != nan trip the assert below\n",
|
| 1184 |
+
" assert all(math.isfinite(v) for v in per_q.values()), (\n",
|
| 1185 |
+
" f\"{name}: non-finite loss {per_q} \u2014 the model is producing NaN/inf. \"\n",
|
| 1186 |
+
" \"First suspect: AUTOCAST_DTYPE (must be bf16 BEFORE models import).\")\n",
|
| 1187 |
" print(f\"[{name}] mean {results['arms'][name]['loss_mean']:.6f} \"\n",
|
| 1188 |
" f\"({(time.time() - t0) / 60:.1f} min)\", flush=True)\n",
|
| 1189 |
"\n",
|