[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7A3Y9098M35C48ES155D30P":3,"skill-same:01M7A3Y9098M35C48ES155D30P":96},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":40,"commitSha":41,"skillDirectory":42,"forksCount":43,"repositoryHtmlUrl":44,"repositoryHomepageUrl":6,"ownerHtmlUrl":45,"ownerBlogUrl":6,"ownerDescription":46,"updatedAt":47,"install":48,"resources":61},"01M7A3Y9098M35C48ES155D30P","cdf-anomalygen",null,"Use when running the CDF AnomalyGen pipeline over a defect dataset — mask placement, fine-tuning, synthetic defect-image generation (SDG), evaluation, quality refinement, and pseudo-labeling — even when the user names only one stage.","leemiracle\u002Fwork4ai","leemiracle","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F10385913?v=4","01M79YCHARF56CHMGGTECMZN8Z","lee","01M79YCHBY9VH2CJW4P65D3DHR",4,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: cdf-anomalygen\ndescription: >-\n  Use when running the CDF AnomalyGen pipeline over a defect dataset — mask placement,\n  fine-tuning, synthetic defect-image generation (SDG), evaluation, quality refinement, and\n  pseudo-labeling — even when the user names only one stage.\nlicense: Apache-2.0\ncompatibility: >-\n  Requires a CUDA GPU and the built env (native .venv or the Docker image); Hugging Face auth +\n  network access to download the model checkpoints.\nmetadata:\n  owner: NVIDIA\n  service: anomaly generation\n  version: 1.2.0\n  author: NVIDIA \u003Cnvidia@nvidia.com>\n  tags:\n      - physical-ai\n      - anomaly-generation\n      - cosmos\n      - fine-tuning\n  languages: [python]\n  frameworks: [pytorch, cosmos, diffusion]\n---\n\n# Skill: cdf-anomalygen\n\n## Purpose\n\nAnomalyGen fine-tunes the frozen **Cosmos** base into an **anomaly-generation** model: given a clean\nimage + defect mask, it paints a realistic defect into that region (synthetic data for detectors).\nPick a mode, collect its params, run the steps — **all commands from the repo root.**\n\n## When to Use This Skill\n\nUse for the CDF AnomalyGen pipeline over a defect dataset — any single stage (mask placement,\nfine-tuning, generation, evaluation, refinement, or pseudo-labeling) or the full run.\n\n- \"Run the AnomalyGen pipeline on phone_screen\"\n- \"Fine-tune an anomaly-generation model for PCB defects\"\n- \"Generate 25 synthetic PCB anomaly images\"\n- \"Place defect masks\", \"evaluate quality\", or \"pseudo-label the generated defects\"\n\nDo not use this skill for generic image generation, or for synthetic data that isn't defect images\nbuilt from the `{texture}\u002F{defect}` clean-image + defect-mask contract.\n\n## Prerequisites\n\n- A **CUDA GPU** and the project's built env (native `.venv` or the Docker image).\n- **Hugging Face auth** — run `hf auth login` — plus network access; the downloader fetches\n  the model checkpoints.\n- A **`dataset_dir`** in the Step 1 contract layout (clean images + `{defect}` masks; plus\n  `defect_spec.jsonl` **only when `mask_backend=amp`** — the default `amg` never reads it, and\n  nothing after Step 2 does either).\n\nPreflight the env + checkpoints (GPU, Python, CUDA\u002Ftorch, deps, HF auth, model checkpoints):\n\n```shell\nscripts\u002Fpreflight_env_ckpt.sh\n```\n\n**Read which group failed before reacting** — the summary separates them, and only one is fixed by\ndownloading:\n\n- *missing checkpoints* → `scripts\u002Fdownload_checkpoints.sh` (run `hf auth login` first).\n- *env \u002F Python \u002F deps* → rebuild the environment (`bash scripts\u002Fenv_setup.sh`, then activate it).\n\n**Third group — model access for mask placement (checked HERE, never mid-flow).** The default\n`mask_backend=amg` needs a vision model, and a run that discovers this at Step 2 has already spent\nthe user's time. A **VLM API is a base, a key and a model name** — and all three live in ONE place:\n**`~\u002F.anomalygen\u002Fendpoints.yaml`**, the model registry (nothing is built into the code; the template\nis `scripts\u002Fagentic_mask_generation_serving\u002Fendpoints.example.yaml`). It sits under `$HOME`, not in\nthe repo, so it works from any directory, serves every checkout, and is writable inside the\nread-only product containers. The moment inputs are locked with `mask_backend=amg` (the default), probe:\n\n```shell\n[ -f ~\u002F.anomalygen\u002Fendpoints.yaml ] && echo \"amg model: ~\u002F.anomalygen\u002Fendpoints.yaml present\" \\\n    || echo \"amg model: no ~\u002F.anomalygen\u002Fendpoints.yaml — NO model can resolve; copy scripts\u002Fagentic_mask_generation_serving\u002Fendpoints.example.yaml there\"\n```\n\n**The model resolves in the registry → use it.** That is the whole check: `--gen-model` and\n`--judge-model` are REQUIRED flags (there is no default model), and every name they carry must have\na registry entry (`model` + `base_url` + `key`) — the entry point refuses to start when one does\nnot; there is no environment fallback. A user's own OpenAI-compatible endpoint is the same case:\none `endpoints.yaml` entry with their documented base URL, their key, and their model name in\n`--gen-model`\u002F`--judge-model`.\n\n**Anything less → stop and ask the user now**, before Step 1 — unless the user's request already\nnames the model (e.g. \"use local Gemma\"): that IS the pick, act on it without re-asking. Three\noptions — whichever it is, set `AMG_MODEL` to the chosen name; the Step 2 command passes it to\nboth required flags:\n\n- **(a) supply an API** — one `endpoints.yaml` entry: a model name, a base and a key\n  (e.g. `AMG_MODEL=azure\u002Fopenai\u002Fgpt-6-astra`).\n- **(b) let the skill start the model service** — in a container, as a background process inside it;\n  on a dev host, from `scripts\u002Fagentic_mask_generation_serving\u002F`. Needs a GPU; the weights are a default checkpoint —\n  `scripts\u002Fdownload_checkpoints.sh gemma` fetches them and preflight verifies them (the group\n  argument fetches only this model; bare, the script fetches all eleven).\n  `mkdir -p ~\u002F.anomalygen && cp scripts\u002Fagentic_mask_generation_serving\u002Fendpoints.example.yaml ~\u002F.anomalygen\u002Fendpoints.yaml` wires it: the template's gemma entry already routes\n  `AMG_MODEL=nvidia\u002Fgoogle\u002Fgemma-4-31b-it` to `http:\u002F\u002Flocalhost:8902\u002Fv1`, and the run\n  carries `--beam-multi 4 --beam-pairwise --exemplar-captions --exemplar-visual-prompt --coverage-note` — the local model always pairs with the in-loop beam and the three information channels.\n  Bootstrap, lifecycle and the why: [`agentic-mask-generation.md`](references\u002Fagentic-mask-generation.md).\n- **(c) set `mask_backend=amp`** for this run.\n\nNever fall back silently. Whichever they pick, the run's own capability probe confirms the model can\ntake images and answer in JSON before Step 2 spends anything.\n\n## Inputs\n\nCollect the run's inputs from the user before starting. **If the `mode` or any input it requires is\nmissing, ask the user first — never guess a required input or silently fall back to its default.**\n\n**Lock the `mode` first** — it fixes which steps run and which inputs are required (ask for any not\nprovided):\n\n- **`full`** — train + generate, Steps **1 → 7**. Required: `name`, `dataset_dir`, `num_sdg`.\n- **`finetune_only`** — train only, Steps **1 → 3**. Required: `name`, `dataset_dir`, `num_sdg`. Here\n  `num_sdg` sizes only the validation set.\n- **`generation_only`** (a.k.a. `inference_only`) — generate from an existing checkpoint, Steps\n  **2, 4 → 7**. Required: `name`, `checkpoint`, `recipe`, `dataset_dir`, `num_sdg`. The checkpoint's\n  geometry stamp must equal `recipe`'s. A legacy checkpoint (trained before the stamp existed) has\n  none: pass its run-dir recipe copy and it is stamped from that recipe at load (generation only; it\n  cannot be resumed).\n\n`name` is required in every mode — an experiment label that names the recipe, run dir, logs and\nthe generated mask-set dirs. It is never a dataset location: where the data lives is `dataset_dir`,\nalways passed separately and never derived from `name`.\n\n**Optional in every mode** — all have working defaults, so ask only if the user raises them:\n`num_gpus` (`1`), `num_search_run` (`3`), `score` (`nn`), `task` (`texture_ft`),\n`base_seed` (`1`), `mask_backend` (`amg`), `legacy_fixed_size` (off), `per_clean_pairing` (`off`).\nAnything not listed as **Required** above is optional.\n\n`legacy_fixed_size` switches Step 3 to the legacy fixed-input-size training mechanism. It is off by\ndefault: every fine-tune uses the current variable-input-size mechanism unless the user **explicitly**\nasks for the legacy one (\"FT using the legacy fixed-size mechanism\", \"old fixed input size setting\",\n\"previous release FT mode\", etc.). Never infer it from the dataset, the image sizes, or KPI numbers,\nand never ask about it when the user has not raised it. When set, the run takes\n`job_name: anomalygen_texture_ft_legacy` — in the recipe and as `--job_name` to `set_pipeline_vars.sh`\n— so it never shares a run dir with a default run of the same `name`, and Step 3 appends the legacy\nblock to the recipe.\n\n`mask_backend` picks how Step 2 places masks: **`amg`** (default) — the agentic engine proposes,\nrefines and judge-accepts every mask, all defect types included; **`amp`** — the\nallocate → pair → place pipeline; no VLM beyond `text` ROIs. AMG\nneeds model access (preflight checks before spending); if the user cannot supply it and does not choose,\nstop and ask — never fall back silently.\n\nParameter tables (each mapped to its CLI arg) and the step map: [`inputs.md`](references\u002Finputs.md).\nConfirm the inputs, set the shared variables below, then run straight through — in `full`,\n`checkpoint` is derived after Step 3, so don't pass it.\n\n## Instructions\n\nRun the steps your `mode` selects (see **Inputs**), in order — each step's header notes when to skip it.\n\n> **A step is done only when its output exists on disk — not when its command is *launched*.** Every\n> step ends with a named gate (**dataset**, **amp**, **train**, …); run it before moving on. Never\n> treat starting a long job as a stopping point, nor proceed on a partial artifact. Gate commands and\n> the fix for each failure: [`references\u002Fverification.md`](references\u002Fverification.md).\n\nSet the shared variables every step below refers to. **Re-source this in each new shell** — variables\ndo not survive one — and read the values it echoes back (`${DATASET_DIR}`, `${VAL_DIR}`, `${GEN_DIR}`,\n`${OUT}`, `${RUN_DIR}`, `${LOG_DIR}`, …):\n\n```shell\nsource scripts\u002Fskill_utility\u002Fset_pipeline_vars.sh --name \u003Cname> --dataset_dir \u003Cdataset_dir> \\\n    --num_sdg \u003Cnum_sdg> [--num_gpus 1] [--num_search_run 3] [--task texture_ft] \\\n    [--job_name anomalygen_texture_ft_legacy]   # legacy_fixed_size only\nexport SCORE=\"\u003Cscore>\"  # repeat the confirmed choice in every shell; use nn when none was requested\n```\n\n**`--dataset_dir` is required and is never derived from `--name`.** The name is an experiment label; the\ndataset is a separate input that comes from the user. They differ in the normal case — a label of\n`uc1pega-opus5-e2e` over a dataset at `datasets\u002Fuc1pega` — so a name-derived path would be wrong far\nmore often than right, and wrong *silently*: the recipe's `dataset_path` is set separately, so the\nrecipe can point at the right dataset while `${DATASET_DIR}` hands Steps 5 and 6 a `--real_root` that\nscores against nothing. The script does **not** check that the path exists; gate **dataset** does, one\nstep later.\n\n**Every step's log goes under `${LOG_DIR}` (`results\u002F`), never the repo root.** Use\n`${LOG_DIR}\u002F\u003Cstep>_${NAME}.log`. The same goes for PID files — the launcher writes its own under `results\u002F`;\ndo not add one.\n\nThe steps below pipe through `tee` to keep the log and the console. **Run `set -o pipefail` first** —\nwithout it the pipeline's exit status is `tee`'s, so a step that died reports success:\n\n```shell\nset -o pipefail\n```\n\n`set_pipeline_vars.sh` **rejects** a `name`\u002F`task` outside `[A-Za-z0-9][A-Za-z0-9._-]*` and any non-integer count rather\nthan sanitizing them — both reach command lines below. Apply the same care to user-supplied paths\n(`dataset_dir`, `recipe`, `checkpoint`): quote every expansion. `texture_ft` is the only `task_type`\ntoday; a new task family adds one `${TASK}`→`${SCRIPTS}` line to that script plus a matching\n`task_type:` in the recipe.\n\nStep 3 sets `CKPT` and repoints `RECIPE` at the run-dir copy for Steps 4–7. **`generation_only` skips\nStep 3**, so set both yourself before Step 4 (use the user's `checkpoint` verbatim if given; `CKPT` and\n`RECIPE` must come from one run or class ids drift):\n\n```shell\nRUN_DIR=\u003Cexisting run dir>                      # only if it is not the ${RUN_DIR} already set above\nCKPT=\"${RUN_DIR}\u002Fcheckpoints\u002Fmodel\u002F$(cat \"${RUN_DIR}\u002Fcheckpoints\u002Fbest_checkpoint.txt\")\"\nRECIPE=\"${RUN_DIR}\u002Fexp_${TASK}_${NAME}.yaml\"    # run-dir copy — MUST match the checkpoint\n```\n\n### Step 1 — dataset (contract layout)\n\nAll modes need `dataset_dir` on disk in this layout — training and eval read the\n`anomaly_image\u002F`+`mask\u002F` pairs; both Step 2 backends read `clean_image\u002F` (AMG also samples those\nsame pairs as exemplars); `defect_spec.jsonl` has exactly one consumer, the AMP backend:\n\n```text\n{dataset_dir}\u002F{texture}\u002Fanomaly_image\u002F{defect}\u002F\u003Cname>.png   # defect image\n{dataset_dir}\u002F{texture}\u002Fmask\u002F{defect}\u002F\u003Cname>_mask.png       # binary mask (>=128 = defect); same stem + _mask\n{dataset_dir}\u002F{texture}\u002Fclean_image\u002F\u003Cname>.png              # clean images (Step 2 inputs — both backends)\n{dataset_dir}\u002F{texture}\u002Fcad_mask\u002F\u003Cclean_stem>.png           # cad\u002Fcad_tht only: one per clean image, no {defect} level\n{dataset_dir}\u002Fsemantic_segmentation_labels.json             # cad\u002Fcad_tht only: label map for those CAD masks\n{dataset_dir}\u002Fdefect_spec.jsonl                             # amp only: one row per {texture}+{defect}; sets spatial_dependency (free\u002Ftext\u002Fcad\u002Fcad_tht). amg never reads it — absent is normal\n```\n\nReady-made subjects:\n\n```shell\npython -m anomalygen.scripts.datasets.prepare_phone_screen_defect --output_dir \"${DATASET_DIR}\" --zip \u003Croboflow.zip>\n# --zip is required (the images are a manual Roboflow download); --masks_only asks for a dataset with no images.\n# also: prepare_pcb_defect, prepare_magnetic_tile_defect  (see anomalygen\u002Fscripts\u002Fdatasets\u002FREADME.md)\n```\n\nFor custom data, emit the same layout and list every `[texture, defect]` pair in the recipe's\n`anomaly_types`. Confirm the layout before proceeding — gate **dataset**.\n\n### Step 2 — mask placement\n\nTwo backends produce the same artifact (placed masks + `testcase.jsonl`); everything downstream is\nbackend-blind. Default is **AMG**; set `mask_backend=amp` for the classic pipeline.\n\nModel access was verified at **preflight** (third group). If preflight was skipped, run that\nprobe now — it must pass before anything below spends money.\n\nOne notice: if `defect_spec.jsonl` is present and declares `spatial_dependency`, tell the user —\n**AMG is the default and does not read that field** (it decides placement by looking at the board);\nto honour `free`\u002F`text`\u002F`cad` routing, run with `mask_backend=amp`. Do not change the default over\nit. A dataset with no `defect_spec.jsonl` at all is normal under `amg` — nothing in the pipeline\nreads it then, and the grep below is simply silent; under `amp` its absence is a **dataset** gate\nfailure.\n\n```shell\ngrep -l spatial_dependency \"${DEFECT_SPEC}\" >\u002Fdev\u002Fnull 2>&1 && echo   \"NOTE: spatial_dependency present but mask_backend=amg ignores it; use mask_backend=amp to honour it\"\n```\n\n#### AMG (default)\n\n**Reference** (model resolution, the model-service bootstrap, the capability probe, cost, resume, the\nrun's own deviation ledger): [`agentic-mask-generation.md`](references\u002Fagentic-mask-generation.md).\n\nOne run per output set, each sized by `--num-sdg` — the same request AMP answers, split across the\ntypes by the same rule (base each, remainder to the first types). **Both sets use `${NUM_SDG}`**, the\nsame convention as AMP, where `--num_sdg` sizes the validation and the generation set alike. The\ndeliverable is exactly `num_sdg` rows, so gate **amg** checks the number that was asked for:\n\n```shell\nAMG_MODE=validation; AMG_DIR=\"${VAL_DIR}\"; ALLOC=validation   # names the log, the out-dir, the split\n# then again:  AMG_MODE=generation AMG_DIR=\"${GEN_DIR}\" ALLOC=inference\n\npython -m anomalygen.scripts.agentic_mask_generation.generate \\\n    --dataset-path \"${DATASET_DIR}\" --anomaly-types \u003Ctexture>+\u003Cdefect> [...] \\\n    --gen-model \"${AMG_MODEL}\" --judge-model \"${AMG_MODEL}\" \\\n    --model-registry \"${AMG_REGISTRY:-$HOME\u002F.anomalygen\u002Fendpoints.yaml}\" \\\n    --num-sdg \"${NUM_SDG}\" --mode \"${ALLOC}\" \\\n    --visual-prompt auto --defect-library auto \\\n    --out-dir \"${AMG_DIR}\" 2>&1 | tee \"${LOG_DIR}\u002Famg_${AMG_MODE}_${NAME}.log\"\n```\n\n`--model-registry` is explicit, not left to the default, because Step 2 may run inside a container\nwhose `$HOME` is not the host's: the flag makes \"which registry answered\" a fact of the recorded\ncommand. Set `AMG_REGISTRY` to wherever the registry actually is (e.g. the path it was mounted at).\n\n**`--mode` is why the two sets are not interchangeable.** The generation set is `inference`: an even\nsplit, and a type may legitimately get 0 when `num_sdg` is below the type count. The validation set is\n`validation`: split in proportion to each type's real mask count, so it mirrors what the model trains\non — and a share that would round to 0 is **refused**, because validation scores per type and a type\nwith no samples drops silently out of the KPI that picks `best_checkpoint.txt`. Both are AMP's rules,\nshared through one allocation module rather than reimplemented.\n\n**`--num-sdg` is the only way to size a run**, as it is for AMP. It splits the total across the\ntypes rather than sizing each alike, so 25 over 3 types is 9\u002F8\u002F8 and lands on 25 — where a per-type\ncount could only reach 27, paying for two masks before anything discards them. For exact per-type\ntargets instead, `--per-defect-counts '{\"\u003Ctexture>+\u003Cdefect>\": N}'`; omitted types get 0.\n\n**`AMG_MODE` is in the log name because there are two runs.** Both would otherwise `tee` to one file\nand the second would overwrite the first, silently discarding the validation run's deviation ledger —\nthe same reason AMP's log carries `${AMP_MODE}`.\n\n**The validation set's size is a training-time cost, not just a one-off API charge.** Every validation\npass re-renders the whole `testcase_jsonl` set and runs one SAM2 forward per sample (~0.4 s each — see\n[`fine-tuning.md`](references\u002Ffine-tuning.md)), repeated `max_iter \u002F validation_iter` times. To spend\nless, lower `num_sdg`; do **not** raise `validation_iter`, which also coarsens the resolution\n`best_checkpoint.txt` is chosen at.\n\nAMG places every type it is given. A stopped or interrupted run\n**continues from where it was** when re-run with the same command. The run records every deviation as\n`degraded[KIND]` in its log — read the summary before trusting the output. Verify the deliverable\ndirectly against gate **amg** ([`verification.md`](references\u002Fverification.md)): `testcase.jsonl` rows\n= `${NUM_SDG}`. The fill loop delivers in beam-sized batches and then trims to the target, so\n`trimmed from N` with `N` well above a type's share is normal, not a defect — the surplus is kept under\n`{texture}\u002F_overflow\u002F{defect}\u002F` + `testcase_overflow.jsonl` and is deliberately **not** counted in\n`testcase.jsonl`, so counting mask files on disk will exceed the row count with nothing wrong. When\nthe user asks for different backends on different types, each backend places its own subset and this\ncount is over the union of the runs' rows (the AMP gate's `roi_*` checks and remedies are for AMP\nout-dirs only).\n\n**When the model is served here, the service spans Step 2 and nothing else.** Both mask sets are Step\n2 products, so serve once and run both against it — then stop it. Serving holds a large share of the\nGPU, and Step 3 (`full`) and Step 4 (`generation_only`) need that GPU back:\n\n```shell\nscripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh health                   # idempotent: probe first, start only if down\ncase $? in                                                # 0 up · 1 not running · 2 alive but loading\n  0) : ;;                                                 # ready — run the two generate runs below\n  1) echo \"DOWN — start it (references\u002Fagentic-mask-generation.md), then wait for it\" ;;\n  2) echo \"LOADING — call: scripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh wait   (repeat while it exits 2)\" ;;\nesac\n# ... the two generate runs above: AMG_DIR=${VAL_DIR}, then AMG_DIR=${GEN_DIR} ...\nscripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh stop                     # part of this step's gate\nscripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh health                   # ONLY exit 1 means the GPU is free\n[ $? = 1 ] || echo \"STILL HOLDING THE GPU — Step 3 will contend for it\"\n```\n\n**Test for exit 1, not for failure.** A server that is up (0) and one still loading (2) both hold their\n`--gpu-memory-utilization 0.9` reservation, so `health && echo ...` would clear the gate on a process\nthat never finished starting and is still sitting on the card.\n\n**Waiting for the service is an action, exactly as waiting for a fine-tune is.** `serverctl.sh wait`\nreports state as its exit code — **0** up, **1** no such process, **2** still loading, call again — and\neach call is a ~9.5-minute slice, not the whole wait. A single-GPU cold start measured **~14 minutes**\nto first answer `\u002Fv1\u002Fmodels`, so expect two or three calls. Do not read a `DOWN`\u002F`LOADING` line during\nthat window as a failed start: exit **2** means the process is alive and has not finished loading, and\nrestarting on that reading puts a second vLLM on the same GPU at `--gpu-memory-utilization 0.9`.\n\n**Step 2 is not done until that last line prints nothing.** The bootstrap that starts it — in a\ncontainer or on a dev host — is in [`agentic-mask-generation.md`](references\u002Fagentic-mask-generation.md).\n\n#### Classic AMP (`mask_backend=amp`)\n\n**Reference** (allocation modes, KPI floor, `--per_defect_counts`, ROI caching, `free\u002Ftext\u002Fcad\u002Fcad_tht`\nrouting, pairing coverage): [`mask-placement.md`](references\u002Fmask-placement.md).\n\nAMP builds a `testcase.jsonl` (clean image + placed mask + gen params) by running allocate → pair →\nplace. Build the **`validation`** set (fine-tune) and\u002For the **`generation`** set (SDG), each with a\ndistinct `--seed` — **full** → both, **finetune_only** → validation, **generation_only** → generation:\n\n```shell\nAMP_MODE=validation; AMP_DIR=\"${VAL_DIR}\"; SEED=42    # or: AMP_MODE=inference AMP_DIR=\"${GEN_DIR}\" SEED=43\n\npython -m anomalygen.scripts.auto_mask_placement.roi_place_pipeline \\\n    --num_sdg \"${NUM_SDG}\" --mode \"${AMP_MODE}\" --defect_desc \"${DEFECT_SPEC}\" \\\n    --dataset_dir \"${DATASET_DIR}\" --output_dir \"${AMP_DIR}\" --seed \"${SEED}\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Famp_${AMP_MODE}_${NAME}.log\"\n# flags for roi_place go after a bare --, e.g.:  -- --refresh_roi\n```\n\nIt derives every intermediate path from `--output_dir`, threads `roi_pair`'s `n_seeds` into\n`roi_place`, and stops with a named stage if one produces nothing. Output is placed masks +\n**`${AMP_DIR}\u002Ftestcase.jsonl`**. The **generation** set must have exactly as many rows as the\nallocation asked for — `num_sdg`, or the `--per_defect_counts` sum when you passed one — verify before\nproceeding: gate **amp**.\n\n**Only when the user set `per_clean_pairing=on`:** pass `--per_clean_pairing on`, and with it a\nsingle-type `--per_defect_counts '{\"\u003Ctexture>+\u003Cdefect>\": '\"${NUM_SDG}\"'}'` with `num_sdg` at the\nclean-image count — `on` is one record per clean, so it takes exactly one defect type. Absent, the\ndefault `off` pairing applies: it maximises (submask, clean) diversity and so visits only *some*\nclean images ([`mask-placement.md`](references\u002Fmask-placement.md)). Whether every clean must receive\nan output is a property of the batch that only the user knows; do not infer it.\n\n### Step 3 — fine-tuning (skip when generation_only)\n\n**Reference** (recipe knobs, launch mechanics, early stopping, checkpoint selection):\n[`fine-tuning.md`](references\u002Ffine-tuning.md).\n\n**Before training:** copy the template recipe and edit its dataset block so `testcase_jsonl` points at\nthe validation set from Step 2 (AMG or AMP) (other keys ship at tested defaults):\n\n```shell\nTEMPLATE=ag_config\u002Fexp_texture_ft_phone_screen.yaml   # the worked example doubles as the template\n[ -f \"${USER_RECIPE:-}\" ] && TEMPLATE=\"${USER_RECIPE}\"   # a recipe the user passed replaces it\n[ \"${RECIPE}\" = \"${TEMPLATE}\" ] || cp \"${TEMPLATE}\" \"${RECIPE}\"   # same file (name=phone_screen or a passed recipe): edit it in place\n```\n\nIf the user passed a `recipe`, set `USER_RECIPE` to it first: an existing file replaces the template,\nso a recipe already at `${RECIPE}` is edited in place, never overwritten.\n\n```yaml\n# edit the dataset block in ${RECIPE}\ndataset_name: ${NAME}\nanomaly_types: [[\u003Ctexture>, \u003Cdefect>], ...]   # every [texture, defect] pair on disk\ndataset_path: ${DATASET_DIR}\ntestcase_jsonl: ${VAL_DIR}\u002Ftestcase.jsonl        # ← Step 2 validation set\n```\n\nIf you change `max_iter`, set `cycle_lengths` to the same value. `cycle_lengths` sets how long the\nlearning-rate schedule lasts, and training crashes if `max_iter` is larger.\n\nOnly when `legacy_fixed_size` is set: change the recipe's `job_name` line to\n`anomalygen_texture_ft_legacy` (the value you passed as `--job_name`), and append this block to\n`${RECIPE}`, keys and values exactly as shown — it is the legacy mechanism as one unit, never a subset:\n\n```yaml\n# legacy_fixed_size only — append to ${RECIPE}\ninput_size_ladder: [512]\ncrop_mode: ratio\ncrop_ratio_range: [1.5, 8.0]\nbackground_dropout_prob: 0.5\nring_jitter_prob: 0.5\ninst_aug_prob: 0.5\n```\n\nA fine-tune runs hours at the `15000` default, so it is launched detached (own session, PID file, log).\n**Check `${RECIPE}` is the one you meant before launching** — it then runs unattended with your\ncredentials:\n\n```shell\nscripts\u002Fskill_utility\u002Ftrain_control.sh start --name \"${NAME}\" --recipe \"${RECIPE}\" \\\n    --num_gpus \"${NUM_GPUS}\" --scripts \"${SCRIPTS}\" --task \"${TASK}\"\n```\n\n**This launcher is the only sanctioned way to start a fine-tune. Never hand-roll a `torchrun` for\ntraining.** It is what writes `results\u002Ftrain_${NAME}.log` and `results\u002Ftrain_${NAME}.pid`, records the\nrun dir, and makes `wait`\u002F`stop` work; a direct `torchrun` bypasses all of it, and a literal\n`--nproc_per_node=\u003Cn>` typed at the prompt silently discards `${NUM_GPUS}` and the user's GPU budget\nwith it. Pass `--num_gpus ${NUM_GPUS}` — never a literal.\n\nWrites `${RUN_DIR}` (recipe copied in). `train_control.sh stop --name ${NAME}` ends a run;\n`start` again resumes from `latest_checkpoint.txt`.\n\n**Waiting is an action.** Call `wait` in the foreground until it stops returning **2** — arming a\nbackground watcher and ending your turn leaves nobody to run Steps 4–7:\n\n```shell\nscripts\u002Fskill_utility\u002Ftrain_control.sh wait --name \"${NAME}\"   # 0 = finished · 1 = failed · 2 = still running, call again\n```\n\n**Each call is a ~9.5-minute slice, not the whole wait.** The `15000` default runs for hours\n(dataset-dependent; the measured times are in `docs\u002Ftutorial\u002Ftexture\u002F7-agentic-end-to-end-flow.md`) —\nexpect **dozens of calls**.\nOnly exit **0** clears gate **train** — not a slice expiring, and not a checkpoint appearing\n(the trainer writes an intermediate `iter_\u003CN>.pt` every `save_iter`). On **1**, read the log\nand fix the run; do not proceed.\n\n**`finetune_only` stops here.** For `full`, take the **best** iteration from the pointer the trainer\nwrites at train end (peak `nn_score` on the `Average` column) — runs routinely peak mid-training:\n\n```shell\nCKPT=\"${RUN_DIR}\u002Fcheckpoints\u002Fmodel\u002F$(cat \"${RUN_DIR}\u002Fcheckpoints\u002Fbest_checkpoint.txt\")\"  # iter_\u003Cbest>.pt\nRECIPE=\"${RUN_DIR}\u002Fexp_${TASK}_${NAME}.yaml\"  # run-dir copy — MUST match the checkpoint\n```\n\nNever substitute `latest_checkpoint.txt` — it names the *last* iteration. `${RUN_DIR}` also resolves\ncorrectly (best pointer first, then latest, then highest `iter_*.pt`), but pass the explicit path so\nthe record names the exact checkpoint. A missing pointer is a **train** gate failure — fix the run,\ndon't let it fall back to the latest.\n\n### Step 4 — generation \u002F SDG (skip when finetune_only)\n\nReads the **generation** AMP `testcase.jsonl` (Step 2, `GEN_DIR`). `--recipe` **must be the recipe the\ncheckpoint was trained with** (use the run-dir copy) so `anomaly_type`→class-id lines up.\n\n```shell\ntorchrun --nproc_per_node=\"${NUM_GPUS}\" \"${SCRIPTS}\u002Fgenerate.py\" \\\n    --checkpoint \"${CKPT}\" \\\n    --recipe \"${RECIPE}\" \\\n    --input_data_path \"${GEN_DIR}\u002Ftestcase.jsonl\" \\\n    --output_dir \"${OUT}\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Fgeneration_${NAME}.log\"\n```\n\n`--nproc_per_node=${NUM_GPUS}` — expand the variable, never a literal count.\n\n`--base_seed` (default `1`) seeds the per-testcase noise. **Don't change it mid-pipeline** — Step 6\ncompares KPIs across re-generated rounds, which a different seed makes incomparable.\n\nOutput tree: `reconstructed_image\u002F` (the synthetic defects), `original_image\u002F`, `original_mask\u002F`, and\n`${TASK}_generation_result.csv`. `generate.py` emits **one image per testcase row** (no quality drop),\nexcept for samples the content-safety guardrail blocks — those write no image and land in\n`guardrail_blocked.csv`, which is expected, not a failure. Verify images + blocked = rows, and the\ncanonical CSV header, before Step 5 (gate **generate**); **never hand-edit the CSV** — a non-canonical\nCSV crashes Step 6.\n\n### Step 5 — evaluation (skip when finetune_only)\n\nScores the batch against the real dataset with the same correspondence KPI as training validation.\n\n```shell\npython \"${SCRIPTS}\u002Fevaluate.py\" \\\n    --gen_root \"${OUT}\" --real_root \"${DATASET_DIR}\" \\\n    --recipe \"${RECIPE}\" \\\n    --output_file \"${OUT}\u002F${NAME}_kpi.json\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Fevaluation_${NAME}.log\"\n```\n\nWrites per-type + `Average` blocks (`nn_score`, `mnn_score`, `fid`, `per_sample[]`) — verify it exists\n(gate **eval**). **`nn_score` is the primary KPI** (higher is better); `mnn_score`\u002F`fid` are secondary.\nIt also scores the anomaly-quality axes and `aq_nn`, the same metrics validation records\n([`fine-tuning.md`](references\u002Ffine-tuning.md)). `--anomaly_types Phone+oil ...` overrides\nrecipe-derived types. The per-sample rows carry NN, completeness, precision, and boundary IoU, which\nStep 6 needs when `--score aq_rank` is selected.\n\n### Step 6 — quality refinement (skip when finetune_only)\n\n**Reference** (draw strategy, ranges\u002Fseeding, `select`):\n[`quality-refinement.md`](references\u002Fquality-refinement.md).\n\n`quality_refine.py run` does the whole loop: `(draw → generate → evaluate) ×${NUM_SEARCH_RUN}`, then `select` and a final\nscore. Each round's `(guidance, crop_ratio)` is drawn per sample — **round 1 uniform**, **rounds 2+\nper-sample Bayesian optimization** (see the reference):\n\n```shell\npython \"${SCRIPTS}\u002Fquality_refine.py\" run \\\n    --base_testcase \"${GEN_DIR}\u002Ftestcase.jsonl\" \\\n    --original \"${OUT}\" --original_kpi \"${OUT}\u002F${NAME}_kpi.json\" \\\n    --rounds_dir \"${OUT}\u002Frounds\" --output \"${OUT}\u002Fsearched\" \\\n    --final_kpi \"${OUT}\u002Fsearched\u002F${NAME}_kpi.json\" \\\n    --checkpoint \"${CKPT}\" --recipe \"${RECIPE}\" --real_root \"${DATASET_DIR}\" \\\n    --score \"${SCORE}\" \\\n    --num_search_run \"${NUM_SEARCH_RUN}\" --num_gpus \"${NUM_GPUS}\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Frefine_${NAME}.log\"\n```\n\nIt refuses to continue past a round that did not finish — completed\u002Fblocked rows, a generation CSV\nthat names exactly the reconstructed images, and its `kpi.json`. Both BO and `select` key off those\nartifacts, so an unfinished round would otherwise be dropped silently and its GPU time wasted.\n**`select` always runs**: `num_search_run=0` reduces it to cloning `${OUT}` into `searched\u002F`, so\n`searched\u002F` always exists for Step 7. Verify the round dirs before Step 7: gate **refine**.\n\n`nn` remains the default score. `--score aq_rank` is an optional cumulative composite: before each\ndraw it pools Original with every earlier round, groups candidates by anomaly type, and recomputes\nAQ-Rank from NN, completeness, precision, and boundary IoU. Final selection recomputes it once more\nover Original plus only the rounds requested by the current run. It therefore does not reuse the\nbucket-local `aq_rank_score` written by `evaluate.py` whenever candidates compete; the zero-round\nclone may copy it into audit output but makes no ranking decision. A candidate missing any of the\nfour finite raw inputs is logged and excluded from the rank pool, so it cannot earn a favorable rank\non a negatively oriented axis; the rest of the bucket remains usable. If one sample has no eligible\nrender across any bucket, selection logs the fallback and keeps its Original render without calling\nit an AQ-Rank win. A bucket with no eligible candidate still fails explicitly.\n\nAQ-Rank fits each geometry-axis direction across the pooled samples but applies it when comparing\nround variants within one sample; those relationships can disagree. Every re-ranking logs each\naxis's AUROC and sign for audit. Treat this as an opt-in heuristic, not a within-sample improvement\nguarantee; changing to a within-sample orientation requires a separate experiment and human validation.\n\nWith `--score nn`, the `Average.nn_score` delta between `${OUT}\u002Fsearched\u002F${NAME}_kpi.json` and the\nStep 5 `${OUT}\u002F${NAME}_kpi.json` measures the refinement gain. AQ-Rank is pool-relative, so do not\ncompare its mean across passes. For `--score aq_rank`, inspect winner-source distribution and paired\nraw-metric changes, then use human or downstream evaluation for the final quality claim. A\nseven-dataset, one-reviewer blind pilot found that NN and AQ-Rank both continued selecting later-round\ncandidates and detected no statistically significant perceptual difference between their final\noutputs; this supports AQ-Rank as an option, not a claim that it is superior or equivalent to NN.\n\n### Step 7 — pseudo-labeling (skip when finetune_only)\n\nTurns the refined `${OUT}\u002Fsearched` tree into a labeled dataset: COCO instance annotations, a\nclassification layout, visualizations, and (unless `--no_caption`) VLM captions.\n\n```shell\npython \"${SCRIPTS}\u002Fpseudo_label.py\" \\\n    --gen_root \"${OUT}\u002Fsearched\" \\\n    --output_dir \"${OUT}\u002Fsearched\u002Fpseudo_labels\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Fpseudo_label_${NAME}.log\"\n# add --no_caption to skip the VLM captioning (fast, no GPU model load)\n```\n\n`--gen_root` must contain `reconstructed_image\u002F`, `original_image\u002F`, `original_mask\u002F`, and\n`${TASK}_generation_result.csv` (Step 6 always produces this at `${OUT}\u002Fsearched`). Verify the labels\nlanded — gate **label**.\n\n## Verification\n\nThe artifact each gate requires. Runnable commands + the fix for each failure:\n[`verification.md`](references\u002Fverification.md).\n\n| #   | Gate       | Step | Requires                                                                                                                     |\n| --- | ---------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |\n| 1   | `dataset`  | 1    | per-pair `clean_image\u002F`, `anomaly_image\u002F{defect}\u002F`, `mask\u002F{defect}\u002F`; + `defect_spec.jsonl` **only when `mask_backend=amp`** |\n| 2a  | `amg`      | 2    | each set's `testcase.jsonl`; rows = `num_sdg`; no `type_failed` \u002F `model_smoke_failed`                                       |\n| 2b  | `amp`      | 2    | `${AMP_DIR}\u002Ftestcase.jsonl`; generation row count = the allocation                                                           |\n| 3   | `train`    | 3    | `wait` exit **0** **and** `checkpoints\u002Fbest_checkpoint.txt`                                                                  |\n| 4   | `generate` | 4    | canonical CSV header **and** images + `guardrail_blocked.csv` rows = testcase rows                                           |\n| 5   | `eval`     | 5    | `${OUT}\u002F${NAME}_kpi.json` with per-type + `Average`                                                                          |\n| 6   | `refine`   | 6    | `${NUM_SEARCH_RUN}` round dirs, **each complete** (images *and* `kpi.json`)                                                  |\n| 7   | `label`    | 7    | `pseudo_labels\u002Fcoco_annotations.json` + `classification\u002Fclasses.txt`                                                         |\n\nGate 6 counts *complete* rounds — existing dirs aren't enough. An all-`original` `searched\u002F` `source`\ncolumn is a valid outcome (no round beat Step 4), not a failure; missing round dirs are.\n\n## Examples\n\nNatural invocations — the `key=value` params map to the **Inputs** table (recipe knobs like `max_iter`\nedit the recipe; see [`references\u002Finputs.md`](references\u002Finputs.md)). `pcb` is `cad`-routed,\n`magnetic_tile` is `free`-routed, `phone_screen` is `text`-routed, and a through-hole solder-joint set\nis `cad_tht`-routed, so their Step 2 AMP differs\n(see [`references\u002Fmask-placement.md`](references\u002Fmask-placement.md)).\n\nFull pipeline (Steps 1→7) on the text-grounded phone-screen set:\n\n```text\nUse AnomalyGen skill with\nname=phone_screen\nmode=full\ndataset_dir=datasets\u002Fphone_screen\nnum_sdg=25\nmax_iter=15000\nvalidation_iter=1000\nsave_iter=1000\n```\n\nTo generate more from an existing checkpoint instead, switch to `mode=generation_only` and add\n`recipe=${RUN_DIR}\u002Fexp_${TASK}_\u003Cname>.yaml` + `checkpoint=${RUN_DIR}\u002Fcheckpoints\u002Fmodel\u002Fiter_\u003Cbest>.pt`\n(from `best_checkpoint.txt`), dropping the training knobs (`max_iter`\u002F`validation_iter`\u002F`save_iter`).\n\nOnly a prompt that explicitly asks for it — \"FT using the legacy fixed-size mechanism\" — adds\n`legacy_fixed_size=true`: pass `--job_name anomalygen_texture_ft_legacy`, set the same `job_name` in the\nrecipe and append the legacy block (Step 3). The run lands under\n`results\u002Fanomalygen\u002F${NAME}\u002Fanomalygen_texture_ft_legacy`; SDG outputs under `results\u002Fgeneration_${NAME}`\nare still shared with a default run of the same `name`. Every other prompt trains with the default\nvariable-input-size mechanism.\n\n## Troubleshooting\n\nEach fails *quietly* — plausible output, wrong result. Detail in\n[`fine-tuning.md`](references\u002Ffine-tuning.md) and [`mask-placement.md`](references\u002Fmask-placement.md).\n\n| Symptom                                                                                                     | Cause \u002F fix                                                                                                                                                                   |\n| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Class ids misaligned in the labels                                                                          | A different `anomaly_types` set — the checkpoint stamp refuses it; use the run-dir recipe copy (order is sorted at parse, so it never matters)                                |\n| Validation scores nothing                                                                                   | `testcase_jsonl` not wired to the Step 2 validation set                                                                                                                       |\n| A fresh `max_iter` run exits immediately                                                                    | Resumed an old `iter_*.pt` — clear it or set a new `job_name`                                                                                                                 |\n| A legacy run dies after model load with a geometry-stamp refusal (`crop_mode` \u002F `input_size_ladder` differ) | It resumed a default run's checkpoint from the same run dir — the recipe's `job_name` and `--job_name` were not both `anomalygen_texture_ft_legacy`; fix both and start again |\n| Fewer rows than the allocation                                                                              | A defect yielded zero placements — check `roi_place` logs                                                                                                                     |\n| A worse checkpoint ships, numbers look fine                                                                 | Read column 1 of `${RUN_DIR}\u002Fvalid\u002F\u003Citer>\u002Fvalid_kpi.csv` (one per validated iteration, not one file), not `Average` — use `best_checkpoint.txt`                               |\n","# Skill: cdf-anomalygen\n\n## Purpose\n\nAnomalyGen fine-tunes the frozen **Cosmos** base into an **anomaly-generation** model: given a clean\nimage + defect mask, it paints a realistic defect into that region (synthetic data for detectors).\nPick a mode, collect its params, run the steps — **all commands from the repo root.**\n\n## When to Use This Skill\n\nUse for the CDF AnomalyGen pipeline over a defect dataset — any single stage (mask placement,\nfine-tuning, generation, evaluation, refinement, or pseudo-labeling) or the full run.\n\n- \"Run the AnomalyGen pipeline on phone_screen\"\n- \"Fine-tune an anomaly-generation model for PCB defects\"\n- \"Generate 25 synthetic PCB anomaly images\"\n- \"Place defect masks\", \"evaluate quality\", or \"pseudo-label the generated defects\"\n\nDo not use this skill for generic image generation, or for synthetic data that isn't defect images\nbuilt from the `{texture}\u002F{defect}` clean-image + defect-mask contract.\n\n## Prerequisites\n\n- A **CUDA GPU** and the project's built env (native `.venv` or the Docker image).\n- **Hugging Face auth** — run `hf auth login` — plus network access; the downloader fetches\n  the model checkpoints.\n- A **`dataset_dir`** in the Step 1 contract layout (clean images + `{defect}` masks; plus\n  `defect_spec.jsonl` **only when `mask_backend=amp`** — the default `amg` never reads it, and\n  nothing after Step 2 does either).\n\nPreflight the env + checkpoints (GPU, Python, CUDA\u002Ftorch, deps, HF auth, model checkpoints):\n\n```shell\nscripts\u002Fpreflight_env_ckpt.sh\n```\n\n**Read which group failed before reacting** — the summary separates them, and only one is fixed by\ndownloading:\n\n- *missing checkpoints* → `scripts\u002Fdownload_checkpoints.sh` (run `hf auth login` first).\n- *env \u002F Python \u002F deps* → rebuild the environment (`bash scripts\u002Fenv_setup.sh`, then activate it).\n\n**Third group — model access for mask placement (checked HERE, never mid-flow).** The default\n`mask_backend=amg` needs a vision model, and a run that discovers this at Step 2 has already spent\nthe user's time. A **VLM API is a base, a key and a model name** — and all three live in ONE place:\n**`~\u002F.anomalygen\u002Fendpoints.yaml`**, the model registry (nothing is built into the code; the template\nis `scripts\u002Fagentic_mask_generation_serving\u002Fendpoints.example.yaml`). It sits under `$HOME`, not in\nthe repo, so it works from any directory, serves every checkout, and is writable inside the\nread-only product containers. The moment inputs are locked with `mask_backend=amg` (the default), probe:\n\n```shell\n[ -f ~\u002F.anomalygen\u002Fendpoints.yaml ] && echo \"amg model: ~\u002F.anomalygen\u002Fendpoints.yaml present\" \\\n    || echo \"amg model: no ~\u002F.anomalygen\u002Fendpoints.yaml — NO model can resolve; copy scripts\u002Fagentic_mask_generation_serving\u002Fendpoints.example.yaml there\"\n```\n\n**The model resolves in the registry → use it.** That is the whole check: `--gen-model` and\n`--judge-model` are REQUIRED flags (there is no default model), and every name they carry must have\na registry entry (`model` + `base_url` + `key`) — the entry point refuses to start when one does\nnot; there is no environment fallback. A user's own OpenAI-compatible endpoint is the same case:\none `endpoints.yaml` entry with their documented base URL, their key, and their model name in\n`--gen-model`\u002F`--judge-model`.\n\n**Anything less → stop and ask the user now**, before Step 1 — unless the user's request already\nnames the model (e.g. \"use local Gemma\"): that IS the pick, act on it without re-asking. Three\noptions — whichever it is, set `AMG_MODEL` to the chosen name; the Step 2 command passes it to\nboth required flags:\n\n- **(a) supply an API** — one `endpoints.yaml` entry: a model name, a base and a key\n  (e.g. `AMG_MODEL=azure\u002Fopenai\u002Fgpt-6-astra`).\n- **(b) let the skill start the model service** — in a container, as a background process inside it;\n  on a dev host, from `scripts\u002Fagentic_mask_generation_serving\u002F`. Needs a GPU; the weights are a default checkpoint —\n  `scripts\u002Fdownload_checkpoints.sh gemma` fetches them and preflight verifies them (the group\n  argument fetches only this model; bare, the script fetches all eleven).\n  `mkdir -p ~\u002F.anomalygen && cp scripts\u002Fagentic_mask_generation_serving\u002Fendpoints.example.yaml ~\u002F.anomalygen\u002Fendpoints.yaml` wires it: the template's gemma entry already routes\n  `AMG_MODEL=nvidia\u002Fgoogle\u002Fgemma-4-31b-it` to `http:\u002F\u002Flocalhost:8902\u002Fv1`, and the run\n  carries `--beam-multi 4 --beam-pairwise --exemplar-captions --exemplar-visual-prompt --coverage-note` — the local model always pairs with the in-loop beam and the three information channels.\n  Bootstrap, lifecycle and the why: [`agentic-mask-generation.md`](references\u002Fagentic-mask-generation.md).\n- **(c) set `mask_backend=amp`** for this run.\n\nNever fall back silently. Whichever they pick, the run's own capability probe confirms the model can\ntake images and answer in JSON before Step 2 spends anything.\n\n## Inputs\n\nCollect the run's inputs from the user before starting. **If the `mode` or any input it requires is\nmissing, ask the user first — never guess a required input or silently fall back to its default.**\n\n**Lock the `mode` first** — it fixes which steps run and which inputs are required (ask for any not\nprovided):\n\n- **`full`** — train + generate, Steps **1 → 7**. Required: `name`, `dataset_dir`, `num_sdg`.\n- **`finetune_only`** — train only, Steps **1 → 3**. Required: `name`, `dataset_dir`, `num_sdg`. Here\n  `num_sdg` sizes only the validation set.\n- **`generation_only`** (a.k.a. `inference_only`) — generate from an existing checkpoint, Steps\n  **2, 4 → 7**. Required: `name`, `checkpoint`, `recipe`, `dataset_dir`, `num_sdg`. The checkpoint's\n  geometry stamp must equal `recipe`'s. A legacy checkpoint (trained before the stamp existed) has\n  none: pass its run-dir recipe copy and it is stamped from that recipe at load (generation only; it\n  cannot be resumed).\n\n`name` is required in every mode — an experiment label that names the recipe, run dir, logs and\nthe generated mask-set dirs. It is never a dataset location: where the data lives is `dataset_dir`,\nalways passed separately and never derived from `name`.\n\n**Optional in every mode** — all have working defaults, so ask only if the user raises them:\n`num_gpus` (`1`), `num_search_run` (`3`), `score` (`nn`), `task` (`texture_ft`),\n`base_seed` (`1`), `mask_backend` (`amg`), `legacy_fixed_size` (off), `per_clean_pairing` (`off`).\nAnything not listed as **Required** above is optional.\n\n`legacy_fixed_size` switches Step 3 to the legacy fixed-input-size training mechanism. It is off by\ndefault: every fine-tune uses the current variable-input-size mechanism unless the user **explicitly**\nasks for the legacy one (\"FT using the legacy fixed-size mechanism\", \"old fixed input size setting\",\n\"previous release FT mode\", etc.). Never infer it from the dataset, the image sizes, or KPI numbers,\nand never ask about it when the user has not raised it. When set, the run takes\n`job_name: anomalygen_texture_ft_legacy` — in the recipe and as `--job_name` to `set_pipeline_vars.sh`\n— so it never shares a run dir with a default run of the same `name`, and Step 3 appends the legacy\nblock to the recipe.\n\n`mask_backend` picks how Step 2 places masks: **`amg`** (default) — the agentic engine proposes,\nrefines and judge-accepts every mask, all defect types included; **`amp`** — the\nallocate → pair → place pipeline; no VLM beyond `text` ROIs. AMG\nneeds model access (preflight checks before spending); if the user cannot supply it and does not choose,\nstop and ask — never fall back silently.\n\nParameter tables (each mapped to its CLI arg) and the step map: [`inputs.md`](references\u002Finputs.md).\nConfirm the inputs, set the shared variables below, then run straight through — in `full`,\n`checkpoint` is derived after Step 3, so don't pass it.\n\n## Instructions\n\nRun the steps your `mode` selects (see **Inputs**), in order — each step's header notes when to skip it.\n\n> **A step is done only when its output exists on disk — not when its command is *launched*.** Every\n> step ends with a named gate (**dataset**, **amp**, **train**, …); run it before moving on. Never\n> treat starting a long job as a stopping point, nor proceed on a partial artifact. Gate commands and\n> the fix for each failure: [`references\u002Fverification.md`](references\u002Fverification.md).\n\nSet the shared variables every step below refers to. **Re-source this in each new shell** — variables\ndo not survive one — and read the values it echoes back (`${DATASET_DIR}`, `${VAL_DIR}`, `${GEN_DIR}`,\n`${OUT}`, `${RUN_DIR}`, `${LOG_DIR}`, …):\n\n```shell\nsource scripts\u002Fskill_utility\u002Fset_pipeline_vars.sh --name \u003Cname> --dataset_dir \u003Cdataset_dir> \\\n    --num_sdg \u003Cnum_sdg> [--num_gpus 1] [--num_search_run 3] [--task texture_ft] \\\n    [--job_name anomalygen_texture_ft_legacy]   # legacy_fixed_size only\nexport SCORE=\"\u003Cscore>\"  # repeat the confirmed choice in every shell; use nn when none was requested\n```\n\n**`--dataset_dir` is required and is never derived from `--name`.** The name is an experiment label; the\ndataset is a separate input that comes from the user. They differ in the normal case — a label of\n`uc1pega-opus5-e2e` over a dataset at `datasets\u002Fuc1pega` — so a name-derived path would be wrong far\nmore often than right, and wrong *silently*: the recipe's `dataset_path` is set separately, so the\nrecipe can point at the right dataset while `${DATASET_DIR}` hands Steps 5 and 6 a `--real_root` that\nscores against nothing. The script does **not** check that the path exists; gate **dataset** does, one\nstep later.\n\n**Every step's log goes under `${LOG_DIR}` (`results\u002F`), never the repo root.** Use\n`${LOG_DIR}\u002F\u003Cstep>_${NAME}.log`. The same goes for PID files — the launcher writes its own under `results\u002F`;\ndo not add one.\n\nThe steps below pipe through `tee` to keep the log and the console. **Run `set -o pipefail` first** —\nwithout it the pipeline's exit status is `tee`'s, so a step that died reports success:\n\n```shell\nset -o pipefail\n```\n\n`set_pipeline_vars.sh` **rejects** a `name`\u002F`task` outside `[A-Za-z0-9][A-Za-z0-9._-]*` and any non-integer count rather\nthan sanitizing them — both reach command lines below. Apply the same care to user-supplied paths\n(`dataset_dir`, `recipe`, `checkpoint`): quote every expansion. `texture_ft` is the only `task_type`\ntoday; a new task family adds one `${TASK}`→`${SCRIPTS}` line to that script plus a matching\n`task_type:` in the recipe.\n\nStep 3 sets `CKPT` and repoints `RECIPE` at the run-dir copy for Steps 4–7. **`generation_only` skips\nStep 3**, so set both yourself before Step 4 (use the user's `checkpoint` verbatim if given; `CKPT` and\n`RECIPE` must come from one run or class ids drift):\n\n```shell\nRUN_DIR=\u003Cexisting run dir>                      # only if it is not the ${RUN_DIR} already set above\nCKPT=\"${RUN_DIR}\u002Fcheckpoints\u002Fmodel\u002F$(cat \"${RUN_DIR}\u002Fcheckpoints\u002Fbest_checkpoint.txt\")\"\nRECIPE=\"${RUN_DIR}\u002Fexp_${TASK}_${NAME}.yaml\"    # run-dir copy — MUST match the checkpoint\n```\n\n### Step 1 — dataset (contract layout)\n\nAll modes need `dataset_dir` on disk in this layout — training and eval read the\n`anomaly_image\u002F`+`mask\u002F` pairs; both Step 2 backends read `clean_image\u002F` (AMG also samples those\nsame pairs as exemplars); `defect_spec.jsonl` has exactly one consumer, the AMP backend:\n\n```text\n{dataset_dir}\u002F{texture}\u002Fanomaly_image\u002F{defect}\u002F\u003Cname>.png   # defect image\n{dataset_dir}\u002F{texture}\u002Fmask\u002F{defect}\u002F\u003Cname>_mask.png       # binary mask (>=128 = defect); same stem + _mask\n{dataset_dir}\u002F{texture}\u002Fclean_image\u002F\u003Cname>.png              # clean images (Step 2 inputs — both backends)\n{dataset_dir}\u002F{texture}\u002Fcad_mask\u002F\u003Cclean_stem>.png           # cad\u002Fcad_tht only: one per clean image, no {defect} level\n{dataset_dir}\u002Fsemantic_segmentation_labels.json             # cad\u002Fcad_tht only: label map for those CAD masks\n{dataset_dir}\u002Fdefect_spec.jsonl                             # amp only: one row per {texture}+{defect}; sets spatial_dependency (free\u002Ftext\u002Fcad\u002Fcad_tht). amg never reads it — absent is normal\n```\n\nReady-made subjects:\n\n```shell\npython -m anomalygen.scripts.datasets.prepare_phone_screen_defect --output_dir \"${DATASET_DIR}\" --zip \u003Croboflow.zip>\n# --zip is required (the images are a manual Roboflow download); --masks_only asks for a dataset with no images.\n# also: prepare_pcb_defect, prepare_magnetic_tile_defect  (see anomalygen\u002Fscripts\u002Fdatasets\u002FREADME.md)\n```\n\nFor custom data, emit the same layout and list every `[texture, defect]` pair in the recipe's\n`anomaly_types`. Confirm the layout before proceeding — gate **dataset**.\n\n### Step 2 — mask placement\n\nTwo backends produce the same artifact (placed masks + `testcase.jsonl`); everything downstream is\nbackend-blind. Default is **AMG**; set `mask_backend=amp` for the classic pipeline.\n\nModel access was verified at **preflight** (third group). If preflight was skipped, run that\nprobe now — it must pass before anything below spends money.\n\nOne notice: if `defect_spec.jsonl` is present and declares `spatial_dependency`, tell the user —\n**AMG is the default and does not read that field** (it decides placement by looking at the board);\nto honour `free`\u002F`text`\u002F`cad` routing, run with `mask_backend=amp`. Do not change the default over\nit. A dataset with no `defect_spec.jsonl` at all is normal under `amg` — nothing in the pipeline\nreads it then, and the grep below is simply silent; under `amp` its absence is a **dataset** gate\nfailure.\n\n```shell\ngrep -l spatial_dependency \"${DEFECT_SPEC}\" >\u002Fdev\u002Fnull 2>&1 && echo   \"NOTE: spatial_dependency present but mask_backend=amg ignores it; use mask_backend=amp to honour it\"\n```\n\n#### AMG (default)\n\n**Reference** (model resolution, the model-service bootstrap, the capability probe, cost, resume, the\nrun's own deviation ledger): [`agentic-mask-generation.md`](references\u002Fagentic-mask-generation.md).\n\nOne run per output set, each sized by `--num-sdg` — the same request AMP answers, split across the\ntypes by the same rule (base each, remainder to the first types). **Both sets use `${NUM_SDG}`**, the\nsame convention as AMP, where `--num_sdg` sizes the validation and the generation set alike. The\ndeliverable is exactly `num_sdg` rows, so gate **amg** checks the number that was asked for:\n\n```shell\nAMG_MODE=validation; AMG_DIR=\"${VAL_DIR}\"; ALLOC=validation   # names the log, the out-dir, the split\n# then again:  AMG_MODE=generation AMG_DIR=\"${GEN_DIR}\" ALLOC=inference\n\npython -m anomalygen.scripts.agentic_mask_generation.generate \\\n    --dataset-path \"${DATASET_DIR}\" --anomaly-types \u003Ctexture>+\u003Cdefect> [...] \\\n    --gen-model \"${AMG_MODEL}\" --judge-model \"${AMG_MODEL}\" \\\n    --model-registry \"${AMG_REGISTRY:-$HOME\u002F.anomalygen\u002Fendpoints.yaml}\" \\\n    --num-sdg \"${NUM_SDG}\" --mode \"${ALLOC}\" \\\n    --visual-prompt auto --defect-library auto \\\n    --out-dir \"${AMG_DIR}\" 2>&1 | tee \"${LOG_DIR}\u002Famg_${AMG_MODE}_${NAME}.log\"\n```\n\n`--model-registry` is explicit, not left to the default, because Step 2 may run inside a container\nwhose `$HOME` is not the host's: the flag makes \"which registry answered\" a fact of the recorded\ncommand. Set `AMG_REGISTRY` to wherever the registry actually is (e.g. the path it was mounted at).\n\n**`--mode` is why the two sets are not interchangeable.** The generation set is `inference`: an even\nsplit, and a type may legitimately get 0 when `num_sdg` is below the type count. The validation set is\n`validation`: split in proportion to each type's real mask count, so it mirrors what the model trains\non — and a share that would round to 0 is **refused**, because validation scores per type and a type\nwith no samples drops silently out of the KPI that picks `best_checkpoint.txt`. Both are AMP's rules,\nshared through one allocation module rather than reimplemented.\n\n**`--num-sdg` is the only way to size a run**, as it is for AMP. It splits the total across the\ntypes rather than sizing each alike, so 25 over 3 types is 9\u002F8\u002F8 and lands on 25 — where a per-type\ncount could only reach 27, paying for two masks before anything discards them. For exact per-type\ntargets instead, `--per-defect-counts '{\"\u003Ctexture>+\u003Cdefect>\": N}'`; omitted types get 0.\n\n**`AMG_MODE` is in the log name because there are two runs.** Both would otherwise `tee` to one file\nand the second would overwrite the first, silently discarding the validation run's deviation ledger —\nthe same reason AMP's log carries `${AMP_MODE}`.\n\n**The validation set's size is a training-time cost, not just a one-off API charge.** Every validation\npass re-renders the whole `testcase_jsonl` set and runs one SAM2 forward per sample (~0.4 s each — see\n[`fine-tuning.md`](references\u002Ffine-tuning.md)), repeated `max_iter \u002F validation_iter` times. To spend\nless, lower `num_sdg`; do **not** raise `validation_iter`, which also coarsens the resolution\n`best_checkpoint.txt` is chosen at.\n\nAMG places every type it is given. A stopped or interrupted run\n**continues from where it was** when re-run with the same command. The run records every deviation as\n`degraded[KIND]` in its log — read the summary before trusting the output. Verify the deliverable\ndirectly against gate **amg** ([`verification.md`](references\u002Fverification.md)): `testcase.jsonl` rows\n= `${NUM_SDG}`. The fill loop delivers in beam-sized batches and then trims to the target, so\n`trimmed from N` with `N` well above a type's share is normal, not a defect — the surplus is kept under\n`{texture}\u002F_overflow\u002F{defect}\u002F` + `testcase_overflow.jsonl` and is deliberately **not** counted in\n`testcase.jsonl`, so counting mask files on disk will exceed the row count with nothing wrong. When\nthe user asks for different backends on different types, each backend places its own subset and this\ncount is over the union of the runs' rows (the AMP gate's `roi_*` checks and remedies are for AMP\nout-dirs only).\n\n**When the model is served here, the service spans Step 2 and nothing else.** Both mask sets are Step\n2 products, so serve once and run both against it — then stop it. Serving holds a large share of the\nGPU, and Step 3 (`full`) and Step 4 (`generation_only`) need that GPU back:\n\n```shell\nscripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh health                   # idempotent: probe first, start only if down\ncase $? in                                                # 0 up · 1 not running · 2 alive but loading\n  0) : ;;                                                 # ready — run the two generate runs below\n  1) echo \"DOWN — start it (references\u002Fagentic-mask-generation.md), then wait for it\" ;;\n  2) echo \"LOADING — call: scripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh wait   (repeat while it exits 2)\" ;;\nesac\n# ... the two generate runs above: AMG_DIR=${VAL_DIR}, then AMG_DIR=${GEN_DIR} ...\nscripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh stop                     # part of this step's gate\nscripts\u002Fagentic_mask_generation_serving\u002Fserverctl.sh health                   # ONLY exit 1 means the GPU is free\n[ $? = 1 ] || echo \"STILL HOLDING THE GPU — Step 3 will contend for it\"\n```\n\n**Test for exit 1, not for failure.** A server that is up (0) and one still loading (2) both hold their\n`--gpu-memory-utilization 0.9` reservation, so `health && echo ...` would clear the gate on a process\nthat never finished starting and is still sitting on the card.\n\n**Waiting for the service is an action, exactly as waiting for a fine-tune is.** `serverctl.sh wait`\nreports state as its exit code — **0** up, **1** no such process, **2** still loading, call again — and\neach call is a ~9.5-minute slice, not the whole wait. A single-GPU cold start measured **~14 minutes**\nto first answer `\u002Fv1\u002Fmodels`, so expect two or three calls. Do not read a `DOWN`\u002F`LOADING` line during\nthat window as a failed start: exit **2** means the process is alive and has not finished loading, and\nrestarting on that reading puts a second vLLM on the same GPU at `--gpu-memory-utilization 0.9`.\n\n**Step 2 is not done until that last line prints nothing.** The bootstrap that starts it — in a\ncontainer or on a dev host — is in [`agentic-mask-generation.md`](references\u002Fagentic-mask-generation.md).\n\n#### Classic AMP (`mask_backend=amp`)\n\n**Reference** (allocation modes, KPI floor, `--per_defect_counts`, ROI caching, `free\u002Ftext\u002Fcad\u002Fcad_tht`\nrouting, pairing coverage): [`mask-placement.md`](references\u002Fmask-placement.md).\n\nAMP builds a `testcase.jsonl` (clean image + placed mask + gen params) by running allocate → pair →\nplace. Build the **`validation`** set (fine-tune) and\u002For the **`generation`** set (SDG), each with a\ndistinct `--seed` — **full** → both, **finetune_only** → validation, **generation_only** → generation:\n\n```shell\nAMP_MODE=validation; AMP_DIR=\"${VAL_DIR}\"; SEED=42    # or: AMP_MODE=inference AMP_DIR=\"${GEN_DIR}\" SEED=43\n\npython -m anomalygen.scripts.auto_mask_placement.roi_place_pipeline \\\n    --num_sdg \"${NUM_SDG}\" --mode \"${AMP_MODE}\" --defect_desc \"${DEFECT_SPEC}\" \\\n    --dataset_dir \"${DATASET_DIR}\" --output_dir \"${AMP_DIR}\" --seed \"${SEED}\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Famp_${AMP_MODE}_${NAME}.log\"\n# flags for roi_place go after a bare --, e.g.:  -- --refresh_roi\n```\n\nIt derives every intermediate path from `--output_dir`, threads `roi_pair`'s `n_seeds` into\n`roi_place`, and stops with a named stage if one produces nothing. Output is placed masks +\n**`${AMP_DIR}\u002Ftestcase.jsonl`**. The **generation** set must have exactly as many rows as the\nallocation asked for — `num_sdg`, or the `--per_defect_counts` sum when you passed one — verify before\nproceeding: gate **amp**.\n\n**Only when the user set `per_clean_pairing=on`:** pass `--per_clean_pairing on`, and with it a\nsingle-type `--per_defect_counts '{\"\u003Ctexture>+\u003Cdefect>\": '\"${NUM_SDG}\"'}'` with `num_sdg` at the\nclean-image count — `on` is one record per clean, so it takes exactly one defect type. Absent, the\ndefault `off` pairing applies: it maximises (submask, clean) diversity and so visits only *some*\nclean images ([`mask-placement.md`](references\u002Fmask-placement.md)). Whether every clean must receive\nan output is a property of the batch that only the user knows; do not infer it.\n\n### Step 3 — fine-tuning (skip when generation_only)\n\n**Reference** (recipe knobs, launch mechanics, early stopping, checkpoint selection):\n[`fine-tuning.md`](references\u002Ffine-tuning.md).\n\n**Before training:** copy the template recipe and edit its dataset block so `testcase_jsonl` points at\nthe validation set from Step 2 (AMG or AMP) (other keys ship at tested defaults):\n\n```shell\nTEMPLATE=ag_config\u002Fexp_texture_ft_phone_screen.yaml   # the worked example doubles as the template\n[ -f \"${USER_RECIPE:-}\" ] && TEMPLATE=\"${USER_RECIPE}\"   # a recipe the user passed replaces it\n[ \"${RECIPE}\" = \"${TEMPLATE}\" ] || cp \"${TEMPLATE}\" \"${RECIPE}\"   # same file (name=phone_screen or a passed recipe): edit it in place\n```\n\nIf the user passed a `recipe`, set `USER_RECIPE` to it first: an existing file replaces the template,\nso a recipe already at `${RECIPE}` is edited in place, never overwritten.\n\n```yaml\n# edit the dataset block in ${RECIPE}\ndataset_name: ${NAME}\nanomaly_types: [[\u003Ctexture>, \u003Cdefect>], ...]   # every [texture, defect] pair on disk\ndataset_path: ${DATASET_DIR}\ntestcase_jsonl: ${VAL_DIR}\u002Ftestcase.jsonl        # ← Step 2 validation set\n```\n\nIf you change `max_iter`, set `cycle_lengths` to the same value. `cycle_lengths` sets how long the\nlearning-rate schedule lasts, and training crashes if `max_iter` is larger.\n\nOnly when `legacy_fixed_size` is set: change the recipe's `job_name` line to\n`anomalygen_texture_ft_legacy` (the value you passed as `--job_name`), and append this block to\n`${RECIPE}`, keys and values exactly as shown — it is the legacy mechanism as one unit, never a subset:\n\n```yaml\n# legacy_fixed_size only — append to ${RECIPE}\ninput_size_ladder: [512]\ncrop_mode: ratio\ncrop_ratio_range: [1.5, 8.0]\nbackground_dropout_prob: 0.5\nring_jitter_prob: 0.5\ninst_aug_prob: 0.5\n```\n\nA fine-tune runs hours at the `15000` default, so it is launched detached (own session, PID file, log).\n**Check `${RECIPE}` is the one you meant before launching** — it then runs unattended with your\ncredentials:\n\n```shell\nscripts\u002Fskill_utility\u002Ftrain_control.sh start --name \"${NAME}\" --recipe \"${RECIPE}\" \\\n    --num_gpus \"${NUM_GPUS}\" --scripts \"${SCRIPTS}\" --task \"${TASK}\"\n```\n\n**This launcher is the only sanctioned way to start a fine-tune. Never hand-roll a `torchrun` for\ntraining.** It is what writes `results\u002Ftrain_${NAME}.log` and `results\u002Ftrain_${NAME}.pid`, records the\nrun dir, and makes `wait`\u002F`stop` work; a direct `torchrun` bypasses all of it, and a literal\n`--nproc_per_node=\u003Cn>` typed at the prompt silently discards `${NUM_GPUS}` and the user's GPU budget\nwith it. Pass `--num_gpus ${NUM_GPUS}` — never a literal.\n\nWrites `${RUN_DIR}` (recipe copied in). `train_control.sh stop --name ${NAME}` ends a run;\n`start` again resumes from `latest_checkpoint.txt`.\n\n**Waiting is an action.** Call `wait` in the foreground until it stops returning **2** — arming a\nbackground watcher and ending your turn leaves nobody to run Steps 4–7:\n\n```shell\nscripts\u002Fskill_utility\u002Ftrain_control.sh wait --name \"${NAME}\"   # 0 = finished · 1 = failed · 2 = still running, call again\n```\n\n**Each call is a ~9.5-minute slice, not the whole wait.** The `15000` default runs for hours\n(dataset-dependent; the measured times are in `docs\u002Ftutorial\u002Ftexture\u002F7-agentic-end-to-end-flow.md`) —\nexpect **dozens of calls**.\nOnly exit **0** clears gate **train** — not a slice expiring, and not a checkpoint appearing\n(the trainer writes an intermediate `iter_\u003CN>.pt` every `save_iter`). On **1**, read the log\nand fix the run; do not proceed.\n\n**`finetune_only` stops here.** For `full`, take the **best** iteration from the pointer the trainer\nwrites at train end (peak `nn_score` on the `Average` column) — runs routinely peak mid-training:\n\n```shell\nCKPT=\"${RUN_DIR}\u002Fcheckpoints\u002Fmodel\u002F$(cat \"${RUN_DIR}\u002Fcheckpoints\u002Fbest_checkpoint.txt\")\"  # iter_\u003Cbest>.pt\nRECIPE=\"${RUN_DIR}\u002Fexp_${TASK}_${NAME}.yaml\"  # run-dir copy — MUST match the checkpoint\n```\n\nNever substitute `latest_checkpoint.txt` — it names the *last* iteration. `${RUN_DIR}` also resolves\ncorrectly (best pointer first, then latest, then highest `iter_*.pt`), but pass the explicit path so\nthe record names the exact checkpoint. A missing pointer is a **train** gate failure — fix the run,\ndon't let it fall back to the latest.\n\n### Step 4 — generation \u002F SDG (skip when finetune_only)\n\nReads the **generation** AMP `testcase.jsonl` (Step 2, `GEN_DIR`). `--recipe` **must be the recipe the\ncheckpoint was trained with** (use the run-dir copy) so `anomaly_type`→class-id lines up.\n\n```shell\ntorchrun --nproc_per_node=\"${NUM_GPUS}\" \"${SCRIPTS}\u002Fgenerate.py\" \\\n    --checkpoint \"${CKPT}\" \\\n    --recipe \"${RECIPE}\" \\\n    --input_data_path \"${GEN_DIR}\u002Ftestcase.jsonl\" \\\n    --output_dir \"${OUT}\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Fgeneration_${NAME}.log\"\n```\n\n`--nproc_per_node=${NUM_GPUS}` — expand the variable, never a literal count.\n\n`--base_seed` (default `1`) seeds the per-testcase noise. **Don't change it mid-pipeline** — Step 6\ncompares KPIs across re-generated rounds, which a different seed makes incomparable.\n\nOutput tree: `reconstructed_image\u002F` (the synthetic defects), `original_image\u002F`, `original_mask\u002F`, and\n`${TASK}_generation_result.csv`. `generate.py` emits **one image per testcase row** (no quality drop),\nexcept for samples the content-safety guardrail blocks — those write no image and land in\n`guardrail_blocked.csv`, which is expected, not a failure. Verify images + blocked = rows, and the\ncanonical CSV header, before Step 5 (gate **generate**); **never hand-edit the CSV** — a non-canonical\nCSV crashes Step 6.\n\n### Step 5 — evaluation (skip when finetune_only)\n\nScores the batch against the real dataset with the same correspondence KPI as training validation.\n\n```shell\npython \"${SCRIPTS}\u002Fevaluate.py\" \\\n    --gen_root \"${OUT}\" --real_root \"${DATASET_DIR}\" \\\n    --recipe \"${RECIPE}\" \\\n    --output_file \"${OUT}\u002F${NAME}_kpi.json\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Fevaluation_${NAME}.log\"\n```\n\nWrites per-type + `Average` blocks (`nn_score`, `mnn_score`, `fid`, `per_sample[]`) — verify it exists\n(gate **eval**). **`nn_score` is the primary KPI** (higher is better); `mnn_score`\u002F`fid` are secondary.\nIt also scores the anomaly-quality axes and `aq_nn`, the same metrics validation records\n([`fine-tuning.md`](references\u002Ffine-tuning.md)). `--anomaly_types Phone+oil ...` overrides\nrecipe-derived types. The per-sample rows carry NN, completeness, precision, and boundary IoU, which\nStep 6 needs when `--score aq_rank` is selected.\n\n### Step 6 — quality refinement (skip when finetune_only)\n\n**Reference** (draw strategy, ranges\u002Fseeding, `select`):\n[`quality-refinement.md`](references\u002Fquality-refinement.md).\n\n`quality_refine.py run` does the whole loop: `(draw → generate → evaluate) ×${NUM_SEARCH_RUN}`, then `select` and a final\nscore. Each round's `(guidance, crop_ratio)` is drawn per sample — **round 1 uniform**, **rounds 2+\nper-sample Bayesian optimization** (see the reference):\n\n```shell\npython \"${SCRIPTS}\u002Fquality_refine.py\" run \\\n    --base_testcase \"${GEN_DIR}\u002Ftestcase.jsonl\" \\\n    --original \"${OUT}\" --original_kpi \"${OUT}\u002F${NAME}_kpi.json\" \\\n    --rounds_dir \"${OUT}\u002Frounds\" --output \"${OUT}\u002Fsearched\" \\\n    --final_kpi \"${OUT}\u002Fsearched\u002F${NAME}_kpi.json\" \\\n    --checkpoint \"${CKPT}\" --recipe \"${RECIPE}\" --real_root \"${DATASET_DIR}\" \\\n    --score \"${SCORE}\" \\\n    --num_search_run \"${NUM_SEARCH_RUN}\" --num_gpus \"${NUM_GPUS}\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Frefine_${NAME}.log\"\n```\n\nIt refuses to continue past a round that did not finish — completed\u002Fblocked rows, a generation CSV\nthat names exactly the reconstructed images, and its `kpi.json`. Both BO and `select` key off those\nartifacts, so an unfinished round would otherwise be dropped silently and its GPU time wasted.\n**`select` always runs**: `num_search_run=0` reduces it to cloning `${OUT}` into `searched\u002F`, so\n`searched\u002F` always exists for Step 7. Verify the round dirs before Step 7: gate **refine**.\n\n`nn` remains the default score. `--score aq_rank` is an optional cumulative composite: before each\ndraw it pools Original with every earlier round, groups candidates by anomaly type, and recomputes\nAQ-Rank from NN, completeness, precision, and boundary IoU. Final selection recomputes it once more\nover Original plus only the rounds requested by the current run. It therefore does not reuse the\nbucket-local `aq_rank_score` written by `evaluate.py` whenever candidates compete; the zero-round\nclone may copy it into audit output but makes no ranking decision. A candidate missing any of the\nfour finite raw inputs is logged and excluded from the rank pool, so it cannot earn a favorable rank\non a negatively oriented axis; the rest of the bucket remains usable. If one sample has no eligible\nrender across any bucket, selection logs the fallback and keeps its Original render without calling\nit an AQ-Rank win. A bucket with no eligible candidate still fails explicitly.\n\nAQ-Rank fits each geometry-axis direction across the pooled samples but applies it when comparing\nround variants within one sample; those relationships can disagree. Every re-ranking logs each\naxis's AUROC and sign for audit. Treat this as an opt-in heuristic, not a within-sample improvement\nguarantee; changing to a within-sample orientation requires a separate experiment and human validation.\n\nWith `--score nn`, the `Average.nn_score` delta between `${OUT}\u002Fsearched\u002F${NAME}_kpi.json` and the\nStep 5 `${OUT}\u002F${NAME}_kpi.json` measures the refinement gain. AQ-Rank is pool-relative, so do not\ncompare its mean across passes. For `--score aq_rank`, inspect winner-source distribution and paired\nraw-metric changes, then use human or downstream evaluation for the final quality claim. A\nseven-dataset, one-reviewer blind pilot found that NN and AQ-Rank both continued selecting later-round\ncandidates and detected no statistically significant perceptual difference between their final\noutputs; this supports AQ-Rank as an option, not a claim that it is superior or equivalent to NN.\n\n### Step 7 — pseudo-labeling (skip when finetune_only)\n\nTurns the refined `${OUT}\u002Fsearched` tree into a labeled dataset: COCO instance annotations, a\nclassification layout, visualizations, and (unless `--no_caption`) VLM captions.\n\n```shell\npython \"${SCRIPTS}\u002Fpseudo_label.py\" \\\n    --gen_root \"${OUT}\u002Fsearched\" \\\n    --output_dir \"${OUT}\u002Fsearched\u002Fpseudo_labels\" \\\n    2>&1 | tee \"${LOG_DIR}\u002Fpseudo_label_${NAME}.log\"\n# add --no_caption to skip the VLM captioning (fast, no GPU model load)\n```\n\n`--gen_root` must contain `reconstructed_image\u002F`, `original_image\u002F`, `original_mask\u002F`, and\n`${TASK}_generation_result.csv` (Step 6 always produces this at `${OUT}\u002Fsearched`). Verify the labels\nlanded — gate **label**.\n\n## Verification\n\nThe artifact each gate requires. Runnable commands + the fix for each failure:\n[`verification.md`](references\u002Fverification.md).\n\n| #   | Gate       | Step | Requires                                                                                                                     |\n| --- | ---------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |\n| 1   | `dataset`  | 1    | per-pair `clean_image\u002F`, `anomaly_image\u002F{defect}\u002F`, `mask\u002F{defect}\u002F`; + `defect_spec.jsonl` **only when `mask_backend=amp`** |\n| 2a  | `amg`      | 2    | each set's `testcase.jsonl`; rows = `num_sdg`; no `type_failed` \u002F `model_smoke_failed`                                       |\n| 2b  | `amp`      | 2    | `${AMP_DIR}\u002Ftestcase.jsonl`; generation row count = the allocation                                                           |\n| 3   | `train`    | 3    | `wait` exit **0** **and** `checkpoints\u002Fbest_checkpoint.txt`                                                                  |\n| 4   | `generate` | 4    | canonical CSV header **and** images + `guardrail_blocked.csv` rows = testcase rows                                           |\n| 5   | `eval`     | 5    | `${OUT}\u002F${NAME}_kpi.json` with per-type + `Average`                                                                          |\n| 6   | `refine`   | 6    | `${NUM_SEARCH_RUN}` round dirs, **each complete** (images *and* `kpi.json`)                                                  |\n| 7   | `label`    | 7    | `pseudo_labels\u002Fcoco_annotations.json` + `classification\u002Fclasses.txt`                                                         |\n\nGate 6 counts *complete* rounds — existing dirs aren't enough. An all-`original` `searched\u002F` `source`\ncolumn is a valid outcome (no round beat Step 4), not a failure; missing round dirs are.\n\n## Examples\n\nNatural invocations — the `key=value` params map to the **Inputs** table (recipe knobs like `max_iter`\nedit the recipe; see [`references\u002Finputs.md`](references\u002Finputs.md)). `pcb` is `cad`-routed,\n`magnetic_tile` is `free`-routed, `phone_screen` is `text`-routed, and a through-hole solder-joint set\nis `cad_tht`-routed, so their Step 2 AMP differs\n(see [`references\u002Fmask-placement.md`](references\u002Fmask-placement.md)).\n\nFull pipeline (Steps 1→7) on the text-grounded phone-screen set:\n\n```text\nUse AnomalyGen skill with\nname=phone_screen\nmode=full\ndataset_dir=datasets\u002Fphone_screen\nnum_sdg=25\nmax_iter=15000\nvalidation_iter=1000\nsave_iter=1000\n```\n\nTo generate more from an existing checkpoint instead, switch to `mode=generation_only` and add\n`recipe=${RUN_DIR}\u002Fexp_${TASK}_\u003Cname>.yaml` + `checkpoint=${RUN_DIR}\u002Fcheckpoints\u002Fmodel\u002Fiter_\u003Cbest>.pt`\n(from `best_checkpoint.txt`), dropping the training knobs (`max_iter`\u002F`validation_iter`\u002F`save_iter`).\n\nOnly a prompt that explicitly asks for it — \"FT using the legacy fixed-size mechanism\" — adds\n`legacy_fixed_size=true`: pass `--job_name anomalygen_texture_ft_legacy`, set the same `job_name` in the\nrecipe and append the legacy block (Step 3). The run lands under\n`results\u002Fanomalygen\u002F${NAME}\u002Fanomalygen_texture_ft_legacy`; SDG outputs under `results\u002Fgeneration_${NAME}`\nare still shared with a default run of the same `name`. Every other prompt trains with the default\nvariable-input-size mechanism.\n\n## Troubleshooting\n\nEach fails *quietly* — plausible output, wrong result. Detail in\n[`fine-tuning.md`](references\u002Ffine-tuning.md) and [`mask-placement.md`](references\u002Fmask-placement.md).\n\n| Symptom                                                                                                     | Cause \u002F fix                                                                                                                                                                   |\n| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| Class ids misaligned in the labels                                                                          | A different `anomaly_types` set — the checkpoint stamp refuses it; use the run-dir recipe copy (order is sorted at parse, so it never matters)                                |\n| Validation scores nothing                                                                                   | `testcase_jsonl` not wired to the Step 2 validation set                                                                                                                       |\n| A fresh `max_iter` run exits immediately                                                                    | Resumed an old `iter_*.pt` — clear it or set a new `job_name`                                                                                                                 |\n| A legacy run dies after model load with a geometry-stamp refusal (`crop_mode` \u002F `input_size_ladder` differ) | It resumed a default run's checkpoint from the same run dir — the recipe's `job_name` and `--job_name` were not both `anomalygen_texture_ft_legacy`; fix both and start again |\n| Fewer rows than the allocation                                                                              | A defect yielded zero placements — check `roi_place` logs                                                                                                                     |\n| A worse checkpoint ships, numbers look fine                                                                 | Read column 1 of `${RUN_DIR}\u002Fvalid\u002F\u003Citer>\u002Fvalid_kpi.csv` (one per validated iteration, not one file), not `Average` — use `best_checkpoint.txt`                               |\n",{"name":5,"license":15,"metadata":24,"description":7,"compatibility":39},{"tags":25,"owner":30,"author":31,"service":32,"version":33,"languages":34,"frameworks":36},[26,27,28,29],"physical-ai","anomaly-generation","cosmos","fine-tuning","NVIDIA","NVIDIA \u003Cnvidia@nvidia.com>","anomaly generation","1.2.0",[35],"python",[37,28,38],"pytorch","diffusion","Requires a CUDA GPU and the built env (native .venv or the Docker image); Hugging Face auth + network access to download the model checkpoints.","main","ffa016d3c9a8d32821f71f6d9d916c30e04fcb67","讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen",0,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai","https:\u002F\u002Fgithub.com\u002Fleemiracle","i have some experience that make me better, so i want more. follow and star me would be a good choice.","2026-11-12 17:16:40",{"source":8,"skillName":5,"commands":49,"prompt":59,"zipAvailable":60},[50,53,56],{"tool":51,"command":52},"npx","npx skills add leemiracle\u002Fwork4ai --skill cdf-anomalygen",{"tool":54,"command":55},"bunx","bunx skills add leemiracle\u002Fwork4ai --skill cdf-anomalygen",{"tool":57,"command":58},"pnpm","pnpm dlx skills add leemiracle\u002Fwork4ai --skill cdf-anomalygen","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002FSKILL.md",true,[62,68,72,76,80,84,88,92],{"path":63,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":66,"sourceHtmlUrl":67},"BENCHMARK.md","REFERENCE","参考文档",7768,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002FBENCHMARK.md",{"path":69,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":70,"sourceHtmlUrl":71},"references\u002Fagentic-mask-generation.md",21855,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Freferences\u002Fagentic-mask-generation.md",{"path":73,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":74,"sourceHtmlUrl":75},"references\u002Ffine-tuning.md",20484,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Freferences\u002Ffine-tuning.md",{"path":77,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":78,"sourceHtmlUrl":79},"references\u002Finputs.md",9854,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Freferences\u002Finputs.md",{"path":81,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":82,"sourceHtmlUrl":83},"references\u002Fmask-placement.md",9109,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Freferences\u002Fmask-placement.md",{"path":85,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":86,"sourceHtmlUrl":87},"references\u002Fquality-refinement.md",12942,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Freferences\u002Fquality-refinement.md",{"path":89,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":90,"sourceHtmlUrl":91},"references\u002Fverification.md",17720,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Freferences\u002Fverification.md",{"path":93,"resourceType":64,"resourceTypeDesc":65,"sizeBytes":94,"sourceHtmlUrl":95},"skill-card.md",4971,"https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fpaidf-anomalygen\u002Frepo-docs\u002Fskills\u002Fcdf-anomalygen\u002Fskill-card.md",[97,104,111,118,125,132],{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":19},"01M7A57J4E78QJZS8MA72P82DV","agentic-ecology-ui","Guidelines and templates for creating a generic web UI to visualize, rank, filter, and annotate vector databases. The UI has a hierarchical structure covering database selection, label selection\u002Fdefinition, ranking\u002Ffiltering configuration, and row visualization\u002Fannotation. Use when building, serving, or adapting an interactive web UI for Hoplite vector databases.","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透google-deepmind\u002Fagentic_ecology\u002Frepo-docs\u002Fskills\u002Fagentic-ecology-ui\u002FSKILL.md",[],[],{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":19},"01M7A57C4RGS1A7VM6CNPNQDBH","agentic-ecology-init","Initializes a local uv-managed project directory for agentic ecology workloads. Sets up Python dependencies using reference pyproject.toml and uv.lock, configures workspace rules, and ensures Agentic Ecology skills are discoverable. Use when initializing a new project workspace or bootstrapping a clean environment.","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透google-deepmind\u002Fagentic_ecology\u002Frepo-docs\u002Fskills\u002Fagentic-ecology-init\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":19},"01M7A576Q1GYF5GAQCWGPPDQWZ","agentic-ecology-camera-traps","Provides capabilities to run SpeciesNet detector and classifier on camera trap images, extract crop-level feature embeddings, and populate a Hoplite vector database for downstream search and agile modeling. Use when ingesting camera trap images, classifying wildlife photos, or indexing camera trap data.","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透google-deepmind\u002Fagentic_ecology\u002Frepo-docs\u002Fskills\u002Fagentic-ecology-camera-traps\u002FSKILL.md",[],[],{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":19},"01M7A5708M54MMTKXQARDCJQMW","agentic-ecology-bioacoustics","Provides bioacoustic analysis capabilities for ecologists and researchers using the perch-hoplite Python package. A typical use case is to use agile modeling to bootstrap the creation and deployment of a bespoke detector for targeted species on an existing collection of passive acoustic monitoring recordings. Use when processing and annotating audio recordings for bioacoustic applications.","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透google-deepmind\u002Fagentic_ecology\u002Frepo-docs\u002Fskills\u002Fagentic-ecology-bioacoustics\u002FSKILL.md",[],[],{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":131,"publishedAt":19},"01M7A53GYCZY3AT9C2FR44TC35","sample-skill","Sample skill used by agent-env integration tests. Exercises SKILL.md parsing plus supporting scripts and references.","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透browser-use\u002Fagentenv-framework\u002Frepo-docs\u002Ftst\u002Fdata\u002Fskills\u002Fsample_skill\u002FSKILL.md",[],[],{"skillNo":133,"name":134,"nameZh":6,"description":135,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":19},"01M7A4KD50DHSNH1SCNKP1J6S1","simready-foundation-validate-foundation-change","Use for auditing SimReady requirement, validator, feature, profile, adapter, test, and skill consistency.","https:\u002F\u002Fgithub.com\u002Fleemiracle\u002Fwork4ai\u002Fblob\u002Fmain\u002F讲透宇宙\u002F05-侦\u002F讲透NVIDIA\u002Fsimready-foundation\u002Frepo-docs\u002F.codex\u002Fskills\u002Fsimready-foundation-validate-foundation-change\u002FSKILL.md",[],[]]