[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79FJR08GS98DTEJ9R9V7SM0":3,"skill-same:01M79FJR08GS98DTEJ9R9V7SM0":106},{"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":33,"commitSha":34,"skillDirectory":35,"forksCount":14,"repositoryHtmlUrl":36,"repositoryHomepageUrl":6,"ownerHtmlUrl":37,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":38,"install":39,"resources":52},"01M79FJR08GS98DTEJ9R9V7SM0","nv-generate-vae-finetune",null,"Used for finetuning the NV-Generate-CTMR MAISI VAE from CT\u002FMRI NIfTI datalists. Not for clinical or production data approval.","Elogic360\u002Fsoftware-factory","Elogic360","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F156535519?v=4","01M74NH3F0RB13PWB7JZDE2V80","elogic360","01M74NH3FPC65082MDZVMFHDM3",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: nv-generate-vae-finetune\ndescription: Used for finetuning the NV-Generate-CTMR MAISI VAE from CT\u002FMRI NIfTI datalists. Not for clinical or production data approval.\nlicense: Apache-2.0\nallowed-tools: Bash\nmetadata:\n  author: NVIDIA MedTech Team\n  tags:\n    - MedTech\n    - CT\n    - MRI\n    - VAE\n    - finetune\n---\n\n# NV-Generate-VAE-Finetune\n\n## Purpose\n- Used for finetuning the NV-Generate-CTMR MAISI VAE\u002Fautoencoder from user-supplied CT or MRI NIfTI training volumes.\n- Not for clinical interpretation, regulatory use, or approving synthetic data for production training.\n- Upstream currently documents VAE training in `train_vae_tutorial.ipynb` and provides configs\u002Fhelpers, but not a `scripts.train_vae` CLI. This skill does not execute the notebook; it stages the required config\u002Fdatalist glue locally and uses upstream helper APIs.\n- Manifest I\u002FO: inputs are `datalist` and `data_base_dir`; outputs are `autoencoder_checkpoint`, `discriminator_checkpoint`, and `result_json`.\n- The underlying training contract is the upstream config\u002Fenv JSON (`config_maisi_vae_train.json` + `environment_maisi_vae_train.json`, as used in `train_vae_tutorial.ipynb`). The wrapper stages those JSON files for you and exposes the most-tuned fields as CLI flags; the sections below document the fields, their defaults, and how to monitor\u002Ftune a run.\n\n## Instructions\n- Read `skill_manifest.yaml` before changing arguments, side effects, or validation gates.\n- Run `scripts\u002Frun_vae_finetune.py` from the Medical AI Skills repo root.\n- If a host agent exposes `run_script`, use `run_script(\"scripts\u002Frun_vae_finetune.py\", args=[...])`; otherwise run the Bash\u002FPython command below.\n- Use `--preflight` first when checking a new datalist; remove `--preflight` only when the user explicitly wants to launch GPU finetuning.\n- For a staged preflight input bundle directory, use `BUNDLE\u002Fpreflight_datalist.json` as the datalist and `BUNDLE\u002Fpreflight_dataset` as `--data-base-dir` when those files are present.\n\n## Examples\n\nValidate and stage a preflight finetune check from an input bundle (the recommended first step — no GPU, no training). This is the single canonical command; replace `INPUT_BUNDLE` and `OUT_DIR` with your paths:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir OUT_DIR \\\n  --modality mri \\\n  --preflight\n```\n\nFor real GPU finetuning and other variations, see [Usage](#2-usage-one-line-training) below.\n\n## Available Scripts\n| Script | Purpose | Arguments |\n|---|---|---|\n| `scripts\u002Frun_vae_finetune.py` | Primary entrypoint declared by `skill_manifest.yaml`. | `DATALIST.json --data-base-dir DATA_DIR --output-dir OUT_DIR [--epochs N] [--modality mri] [--patch-size 64,64,64] [--preflight]` |\n\n## Prerequisites\n- `NV_GENERATE_ROOT` may point to a current checkout of `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` containing `configs\u002Fconfig_maisi_vae_train.json`, `scripts\u002Ftransforms.py`, and `scripts\u002Futils.py`.\n- If `NV_GENERATE_ROOT` is unset, the wrapper searches `.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR`.\n- `CUDA_VISIBLE_DEVICES` is optional and can be used to select the GPU for real training.\n- Runtime requirements: NVIDIA CUDA GPU for real training, Python packages from the upstream `requirements.txt`, `lpips`, and downloaded VAE weights unless using `--train-from-scratch`.\n- Side effects: writes staged configs, checkpoints, TensorBoard logs, and run summaries under the caller-provided `--output-dir`; may write model caches under the upstream checkout, `~\u002F.cache\u002Fhuggingface\u002F`, and `~\u002F.cache\u002Ftorch\u002F`; may contact `https:\u002F\u002Fhuggingface.co`, `https:\u002F\u002Fgithub.com`, and `https:\u002F\u002Fdownload.pytorch.org`.\n- The datalist is a MONAI-style JSON object with non-empty `training[]` and `validation[]` or `testing[]`. Each entry has an `image` path relative to `--data-base-dir` and optional `class` or `modality` of `ct` or `mri`.\n\n## 1. Config and environment JSON (adapt to your data)\n\nThe wrapper copies the upstream VAE config\u002Fenv JSON from `$NV_GENERATE_ROOT\u002Fconfigs`, rewrites the fields below, and writes the staged copies under `OUT_DIR\u002Fworkflow\u002Fconfigs\u002F`. You normally only set your datalist and data root; the listed CLI flags override individual fields when you need to.\n\nEnvironment JSON (`environment_maisi_vae_train.json`):\n\n| Field | Set from | Notes |\n|---|---|---|\n| `model_dir` | `--output-dir` | Where `autoencoder.pt`\u002F`discriminator.pt` and best checkpoints are saved. |\n| `tfevent_path` | `--output-dir` | TensorBoard event directory. |\n| `finetune` | `--train-from-scratch` | `true` (default) loads `trained_autoencoder_path`; the flag sets it `false`. |\n| `trained_autoencoder_path` | upstream weights \u002F `--trained-autoencoder-path` | Starting VAE checkpoint when finetuning. |\n\nTraining fields (`config_maisi_vae_train.json`):\n\n| Field | Flag | Type | Default | Notes |\n|---|---|---|---|---|\n| `autoencoder_train.n_epochs` | `--epochs` | int | `1` | |\n| `autoencoder_train.batch_size` | `--batch-size` | int | `1` | Per-GPU (single-GPU runner). |\n| `autoencoder_train.patch_size` | `--patch-size` | int,int,int | `64,64,64` | Training crop. |\n| `autoencoder_train.val_batch_size` | `--val-batch-size` | int | `1` | |\n| `autoencoder_train.val_sliding_window_patch_size` | `--val-sliding-window-patch-size` | int,int,int | `96,96,64` | Sliding-window validation ROI. |\n| `autoencoder_train.lr` | `--lr` | float | `1e-4` | |\n| `autoencoder_train.perceptual_weight` | `--perceptual-weight` | float | `0.3` | LPIPS term. |\n| `autoencoder_train.kl_weight` | `--kl-weight` | float | `1e-7` | KL term. |\n| `autoencoder_train.adv_weight` | `--adv-weight` | float | `0.1` | Adversarial term. |\n| `autoencoder_train.recon_loss` | `--recon-loss` | `l1`\\|`l2` | `l1` | |\n| `autoencoder_train.val_interval` | `--val-interval` | int | `1` | Epochs between validation passes. |\n| `autoencoder_train.cache` | `--cache-rate` | float | `0.0` | MONAI `CacheDataset` fraction. |\n| `autoencoder_train.amp` | `--no-amp` | flag | on | Mixed precision; flag disables it. |\n| `data_option.random_aug` | `--no-random-aug` | flag | on | Random augmentation; flag disables it. |\n| `data_option.spacing_type` | `--spacing-type` | `original`\\|`fixed`\\|`rand_zoom` | `original` | |\n| `data_option.spacing` | `--spacing` | float,float,float | unset | Required when `spacing_type` is `fixed`\u002F`rand_zoom`. |\n| `data_option.select_channel` | `--select-channel` | int | `0` | Channel for multi-channel inputs. |\n\n`--modality` (`ct` or `mri`, default `mri`) fills the per-entry `class` for datalist items missing one. Validation\u002Ftesting entries are required because the training loop runs a validation pass.\n\nFor an end-to-end reference including example data download, see the upstream tutorial `train_vae_tutorial.ipynb`.\n\n## 2. Usage (one-line training)\n\nPreflight only:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_vae_finetune_preflight \\\n  --preflight\n```\n\nPreflight bundle input:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  PATH_TO_INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir PATH_TO_INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir runs\u002Fnv_generate_vae_finetune_preflight \\\n  --preflight\n```\n\nGPU finetuning:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython -m pip install -r \"$NV_GENERATE_ROOT\u002Frequirements.txt\" && \\\npython -m pip install lpips tensorboard && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_vae_finetune \\\n  --epochs 1 \\\n  --modality mri \\\n  --patch-size 64,64,64 \\\n  --download-model-data\n```\n\nReplace `PATH_TO_DATALIST.json` and `PATH_TO_DATA_ROOT` with the user's actual paths. Do not use the fixture datalist for real training; it is a preflight-only placeholder.\n\n## 3. Monitor training (TensorBoard)\n\nThe runner writes TensorBoard scalars (per-iteration and per-epoch `recons_loss`, `kl_loss`, `p_loss`, adversarial\u002Freal\u002Ffake losses, and a validation `scale_factor`) under `OUT_DIR\u002Fartifacts\u002Ftfevent\u002Fautoencoder`. Launch TensorBoard against the output directory:\n\n```bash\npython -m pip install tensorboard && \\\ntensorboard --logdir runs\u002Fnv_generate_vae_finetune\u002Fartifacts\u002Ftfevent\n```\n\nThe same per-epoch loss history is also captured in `OUT_DIR\u002Fartifacts\u002Fworkflow_summary.json` and echoed in the JSON the wrapper prints to stdout (`loss_history`, best-checkpoint paths, `exit_code`, `stderr_tail`).\n\n## 4. Hyperparameter tuning and common pitfalls\n\n- **Reconstructions blurry** — raise `--perceptual-weight` (default `0.3`); try `--recon-loss l2` if edges look washed out.\n- **Posterior collapse \u002F over-regularized latents** — `--kl-weight` is intentionally tiny (`1e-7`); increasing it too much degrades reconstruction.\n- **Adversarial training unstable** — lower `--adv-weight` (default `0.1`) or `--lr`; a warmup schedule already ramps the LR over the first 20 epochs.\n- **Out-of-memory** — reduce `--patch-size` (e.g. `48,48,48`) and `--val-sliding-window-patch-size`, keep `--batch-size 1`, and lower `--cache-rate`.\n- **`datalist must include non-empty validation[] or testing[]`** — the validation loop is mandatory; add `validation[]` (or `testing[]`) entries.\n- **Single-GPU only** — the runner asserts exactly one CUDA GPU; set `CUDA_VISIBLE_DEVICES` to pick which one.\n\n## 5. Evaluate the finetuned VAE\n\nValidation reconstruction loss (lowest-`val_weighted_loss` epoch) is tracked automatically and the best autoencoder is saved as `autoencoder_epochN.pt` under `OUT_DIR\u002Fartifacts\u002Fmodels`. To evaluate downstream:\n\n- Compare validation `recons_loss`\u002F`p_loss` curves across runs in TensorBoard, and\n- Plug the finetuned autoencoder into a diffusion finetune\u002Fgeneration run (e.g. [`nv-generate-mr-brain-finetune`](..\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md) via `--trained-autoencoder-path`) to confirm latents still decode to usable volumes.\n\nThis skill gates file accounting and reconstruction bookkeeping only — image quality and downstream utility must be judged by a domain expert.\n\n## Limitations\n- Requires a current upstream `NV-Generate-CTMR` checkout with VAE configs and helper APIs. The skill owns the runner glue and does not depend on the notebook.\n- Full training can be expensive and is not deterministic across hardware, CUDA, and package versions.\n- The wrapper gates file accounting and command provenance, not anatomical realism, reconstruction quality, or downstream model utility.\n- Not for clinical deployment, clinical interpretation, autonomous diagnosis, regulatory submission, or production training-data approval.\n\n## Troubleshooting\n| Error | Cause | Fix |\n|---|---|---|\n| `VAE configs\u002Fhelpers were not found` | `NV_GENERATE_ROOT` does not point at a current NV-Generate-CTMR checkout. | Clone or update `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` and set `NV_GENERATE_ROOT`. |\n| `datalist must include non-empty validation[] or testing[]` | VAE training requires validation data for the configured validation loop. | Add `validation[]` or `testing[]` entries with relative image paths. |\n| CUDA, MONAI, or LPIPS import failure | Runtime environment lacks upstream dependencies. | Install `\"$NV_GENERATE_ROOT\u002Frequirements.txt\"` plus `lpips tensorboard` in the selected environment. |\n","# NV-Generate-VAE-Finetune\n\n## Purpose\n- Used for finetuning the NV-Generate-CTMR MAISI VAE\u002Fautoencoder from user-supplied CT or MRI NIfTI training volumes.\n- Not for clinical interpretation, regulatory use, or approving synthetic data for production training.\n- Upstream currently documents VAE training in `train_vae_tutorial.ipynb` and provides configs\u002Fhelpers, but not a `scripts.train_vae` CLI. This skill does not execute the notebook; it stages the required config\u002Fdatalist glue locally and uses upstream helper APIs.\n- Manifest I\u002FO: inputs are `datalist` and `data_base_dir`; outputs are `autoencoder_checkpoint`, `discriminator_checkpoint`, and `result_json`.\n- The underlying training contract is the upstream config\u002Fenv JSON (`config_maisi_vae_train.json` + `environment_maisi_vae_train.json`, as used in `train_vae_tutorial.ipynb`). The wrapper stages those JSON files for you and exposes the most-tuned fields as CLI flags; the sections below document the fields, their defaults, and how to monitor\u002Ftune a run.\n\n## Instructions\n- Read `skill_manifest.yaml` before changing arguments, side effects, or validation gates.\n- Run `scripts\u002Frun_vae_finetune.py` from the Medical AI Skills repo root.\n- If a host agent exposes `run_script`, use `run_script(\"scripts\u002Frun_vae_finetune.py\", args=[...])`; otherwise run the Bash\u002FPython command below.\n- Use `--preflight` first when checking a new datalist; remove `--preflight` only when the user explicitly wants to launch GPU finetuning.\n- For a staged preflight input bundle directory, use `BUNDLE\u002Fpreflight_datalist.json` as the datalist and `BUNDLE\u002Fpreflight_dataset` as `--data-base-dir` when those files are present.\n\n## Examples\n\nValidate and stage a preflight finetune check from an input bundle (the recommended first step — no GPU, no training). This is the single canonical command; replace `INPUT_BUNDLE` and `OUT_DIR` with your paths:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir OUT_DIR \\\n  --modality mri \\\n  --preflight\n```\n\nFor real GPU finetuning and other variations, see [Usage](#2-usage-one-line-training) below.\n\n## Available Scripts\n| Script | Purpose | Arguments |\n|---|---|---|\n| `scripts\u002Frun_vae_finetune.py` | Primary entrypoint declared by `skill_manifest.yaml`. | `DATALIST.json --data-base-dir DATA_DIR --output-dir OUT_DIR [--epochs N] [--modality mri] [--patch-size 64,64,64] [--preflight]` |\n\n## Prerequisites\n- `NV_GENERATE_ROOT` may point to a current checkout of `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` containing `configs\u002Fconfig_maisi_vae_train.json`, `scripts\u002Ftransforms.py`, and `scripts\u002Futils.py`.\n- If `NV_GENERATE_ROOT` is unset, the wrapper searches `.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR`.\n- `CUDA_VISIBLE_DEVICES` is optional and can be used to select the GPU for real training.\n- Runtime requirements: NVIDIA CUDA GPU for real training, Python packages from the upstream `requirements.txt`, `lpips`, and downloaded VAE weights unless using `--train-from-scratch`.\n- Side effects: writes staged configs, checkpoints, TensorBoard logs, and run summaries under the caller-provided `--output-dir`; may write model caches under the upstream checkout, `~\u002F.cache\u002Fhuggingface\u002F`, and `~\u002F.cache\u002Ftorch\u002F`; may contact `https:\u002F\u002Fhuggingface.co`, `https:\u002F\u002Fgithub.com`, and `https:\u002F\u002Fdownload.pytorch.org`.\n- The datalist is a MONAI-style JSON object with non-empty `training[]` and `validation[]` or `testing[]`. Each entry has an `image` path relative to `--data-base-dir` and optional `class` or `modality` of `ct` or `mri`.\n\n## 1. Config and environment JSON (adapt to your data)\n\nThe wrapper copies the upstream VAE config\u002Fenv JSON from `$NV_GENERATE_ROOT\u002Fconfigs`, rewrites the fields below, and writes the staged copies under `OUT_DIR\u002Fworkflow\u002Fconfigs\u002F`. You normally only set your datalist and data root; the listed CLI flags override individual fields when you need to.\n\nEnvironment JSON (`environment_maisi_vae_train.json`):\n\n| Field | Set from | Notes |\n|---|---|---|\n| `model_dir` | `--output-dir` | Where `autoencoder.pt`\u002F`discriminator.pt` and best checkpoints are saved. |\n| `tfevent_path` | `--output-dir` | TensorBoard event directory. |\n| `finetune` | `--train-from-scratch` | `true` (default) loads `trained_autoencoder_path`; the flag sets it `false`. |\n| `trained_autoencoder_path` | upstream weights \u002F `--trained-autoencoder-path` | Starting VAE checkpoint when finetuning. |\n\nTraining fields (`config_maisi_vae_train.json`):\n\n| Field | Flag | Type | Default | Notes |\n|---|---|---|---|---|\n| `autoencoder_train.n_epochs` | `--epochs` | int | `1` | |\n| `autoencoder_train.batch_size` | `--batch-size` | int | `1` | Per-GPU (single-GPU runner). |\n| `autoencoder_train.patch_size` | `--patch-size` | int,int,int | `64,64,64` | Training crop. |\n| `autoencoder_train.val_batch_size` | `--val-batch-size` | int | `1` | |\n| `autoencoder_train.val_sliding_window_patch_size` | `--val-sliding-window-patch-size` | int,int,int | `96,96,64` | Sliding-window validation ROI. |\n| `autoencoder_train.lr` | `--lr` | float | `1e-4` | |\n| `autoencoder_train.perceptual_weight` | `--perceptual-weight` | float | `0.3` | LPIPS term. |\n| `autoencoder_train.kl_weight` | `--kl-weight` | float | `1e-7` | KL term. |\n| `autoencoder_train.adv_weight` | `--adv-weight` | float | `0.1` | Adversarial term. |\n| `autoencoder_train.recon_loss` | `--recon-loss` | `l1`\\|`l2` | `l1` | |\n| `autoencoder_train.val_interval` | `--val-interval` | int | `1` | Epochs between validation passes. |\n| `autoencoder_train.cache` | `--cache-rate` | float | `0.0` | MONAI `CacheDataset` fraction. |\n| `autoencoder_train.amp` | `--no-amp` | flag | on | Mixed precision; flag disables it. |\n| `data_option.random_aug` | `--no-random-aug` | flag | on | Random augmentation; flag disables it. |\n| `data_option.spacing_type` | `--spacing-type` | `original`\\|`fixed`\\|`rand_zoom` | `original` | |\n| `data_option.spacing` | `--spacing` | float,float,float | unset | Required when `spacing_type` is `fixed`\u002F`rand_zoom`. |\n| `data_option.select_channel` | `--select-channel` | int | `0` | Channel for multi-channel inputs. |\n\n`--modality` (`ct` or `mri`, default `mri`) fills the per-entry `class` for datalist items missing one. Validation\u002Ftesting entries are required because the training loop runs a validation pass.\n\nFor an end-to-end reference including example data download, see the upstream tutorial `train_vae_tutorial.ipynb`.\n\n## 2. Usage (one-line training)\n\nPreflight only:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_vae_finetune_preflight \\\n  --preflight\n```\n\nPreflight bundle input:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  PATH_TO_INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir PATH_TO_INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir runs\u002Fnv_generate_vae_finetune_preflight \\\n  --preflight\n```\n\nGPU finetuning:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython -m pip install -r \"$NV_GENERATE_ROOT\u002Frequirements.txt\" && \\\npython -m pip install lpips tensorboard && \\\npython skills\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_vae_finetune \\\n  --epochs 1 \\\n  --modality mri \\\n  --patch-size 64,64,64 \\\n  --download-model-data\n```\n\nReplace `PATH_TO_DATALIST.json` and `PATH_TO_DATA_ROOT` with the user's actual paths. Do not use the fixture datalist for real training; it is a preflight-only placeholder.\n\n## 3. Monitor training (TensorBoard)\n\nThe runner writes TensorBoard scalars (per-iteration and per-epoch `recons_loss`, `kl_loss`, `p_loss`, adversarial\u002Freal\u002Ffake losses, and a validation `scale_factor`) under `OUT_DIR\u002Fartifacts\u002Ftfevent\u002Fautoencoder`. Launch TensorBoard against the output directory:\n\n```bash\npython -m pip install tensorboard && \\\ntensorboard --logdir runs\u002Fnv_generate_vae_finetune\u002Fartifacts\u002Ftfevent\n```\n\nThe same per-epoch loss history is also captured in `OUT_DIR\u002Fartifacts\u002Fworkflow_summary.json` and echoed in the JSON the wrapper prints to stdout (`loss_history`, best-checkpoint paths, `exit_code`, `stderr_tail`).\n\n## 4. Hyperparameter tuning and common pitfalls\n\n- **Reconstructions blurry** — raise `--perceptual-weight` (default `0.3`); try `--recon-loss l2` if edges look washed out.\n- **Posterior collapse \u002F over-regularized latents** — `--kl-weight` is intentionally tiny (`1e-7`); increasing it too much degrades reconstruction.\n- **Adversarial training unstable** — lower `--adv-weight` (default `0.1`) or `--lr`; a warmup schedule already ramps the LR over the first 20 epochs.\n- **Out-of-memory** — reduce `--patch-size` (e.g. `48,48,48`) and `--val-sliding-window-patch-size`, keep `--batch-size 1`, and lower `--cache-rate`.\n- **`datalist must include non-empty validation[] or testing[]`** — the validation loop is mandatory; add `validation[]` (or `testing[]`) entries.\n- **Single-GPU only** — the runner asserts exactly one CUDA GPU; set `CUDA_VISIBLE_DEVICES` to pick which one.\n\n## 5. Evaluate the finetuned VAE\n\nValidation reconstruction loss (lowest-`val_weighted_loss` epoch) is tracked automatically and the best autoencoder is saved as `autoencoder_epochN.pt` under `OUT_DIR\u002Fartifacts\u002Fmodels`. To evaluate downstream:\n\n- Compare validation `recons_loss`\u002F`p_loss` curves across runs in TensorBoard, and\n- Plug the finetuned autoencoder into a diffusion finetune\u002Fgeneration run (e.g. [`nv-generate-mr-brain-finetune`](..\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md) via `--trained-autoencoder-path`) to confirm latents still decode to usable volumes.\n\nThis skill gates file accounting and reconstruction bookkeeping only — image quality and downstream utility must be judged by a domain expert.\n\n## Limitations\n- Requires a current upstream `NV-Generate-CTMR` checkout with VAE configs and helper APIs. The skill owns the runner glue and does not depend on the notebook.\n- Full training can be expensive and is not deterministic across hardware, CUDA, and package versions.\n- The wrapper gates file accounting and command provenance, not anatomical realism, reconstruction quality, or downstream model utility.\n- Not for clinical deployment, clinical interpretation, autonomous diagnosis, regulatory submission, or production training-data approval.\n\n## Troubleshooting\n| Error | Cause | Fix |\n|---|---|---|\n| `VAE configs\u002Fhelpers were not found` | `NV_GENERATE_ROOT` does not point at a current NV-Generate-CTMR checkout. | Clone or update `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` and set `NV_GENERATE_ROOT`. |\n| `datalist must include non-empty validation[] or testing[]` | VAE training requires validation data for the configured validation loop. | Add `validation[]` or `testing[]` entries with relative image paths. |\n| CUDA, MONAI, or LPIPS import failure | Runtime environment lacks upstream dependencies. | Install `\"$NV_GENERATE_ROOT\u002Frequirements.txt\"` plus `lpips tensorboard` in the selected environment. |\n",{"name":5,"license":15,"metadata":24,"description":7,"allowed-tools":32},{"tags":25,"author":31},[26,27,28,29,30],"MedTech","CT","MRI","VAE","finetune","NVIDIA MedTech Team","Bash","main","c475fc64e94e803b50d14a791dfee8853fbb2c5c","skills\u002Fnvidia\u002Fnv-generate-vae-finetune","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory","https:\u002F\u002Fgithub.com\u002FElogic360","2026-11-08 22:21:22",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":51},[41,44,47],{"tool":42,"command":43},"npx","npx skills add Elogic360\u002Fsoftware-factory --skill nv-generate-vae-finetune",{"tool":45,"command":46},"bunx","bunx skills add Elogic360\u002Fsoftware-factory --skill nv-generate-vae-finetune",{"tool":48,"command":49},"pnpm","pnpm dlx skills add Elogic360\u002Fsoftware-factory --skill nv-generate-vae-finetune","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002FSKILL.md",true,[53,59,63,67,71,74,78,84,88,92,98,102],{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"BENCHMARK.md","REFERENCE","参考文档",4349,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002FBENCHMARK.md",{"path":60,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":61,"sourceHtmlUrl":62},"evals\u002Fevals.json",1182,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Fevals\u002Fevals.json",{"path":64,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":65,"sourceHtmlUrl":66},"fixtures\u002Fpreflight_datalist.json",221,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Ffixtures\u002Fpreflight_datalist.json",{"path":68,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":69,"sourceHtmlUrl":70},"fixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_train.txt",37,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Ffixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_train.txt",{"path":72,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":69,"sourceHtmlUrl":73},"fixtures\u002Fpreflight_dataset\u002FimagesVal\u002Fplaceholder_mri_val.txt","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Ffixtures\u002Fpreflight_dataset\u002FimagesVal\u002Fplaceholder_mri_val.txt",{"path":75,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":76,"sourceHtmlUrl":77},"fixtures\u002FREADME.md",232,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Ffixtures\u002FREADME.md",{"path":79,"resourceType":80,"resourceTypeDesc":81,"sizeBytes":82,"sourceHtmlUrl":83},"scripts\u002Frun_vae_finetune.py","SCRIPT","脚本",32915,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Fscripts\u002Frun_vae_finetune.py",{"path":85,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":86,"sourceHtmlUrl":87},"skill_manifest.yaml",6196,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Fskill_manifest.yaml",{"path":89,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":90,"sourceHtmlUrl":91},"skill-card.md",3682,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Fskill-card.md",{"path":93,"resourceType":94,"resourceTypeDesc":95,"sizeBytes":96,"sourceHtmlUrl":97},"skill.oms.sig","OTHER","其他",6601,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Fskill.oms.sig",{"path":99,"resourceType":80,"resourceTypeDesc":81,"sizeBytes":100,"sourceHtmlUrl":101},"tests\u002Ftest_run_vae_finetune.py",5742,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Ftests\u002Ftest_run_vae_finetune.py",{"path":103,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":104,"sourceHtmlUrl":105},"validators\u002Foutput_schema.json",4061,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-vae-finetune\u002Fvalidators\u002Foutput_schema.json",[107,114,121,128,135,142],{"skillNo":108,"name":109,"nameZh":6,"description":110,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":19},"01M79G206MT3J6S0GY3C45P2KV","vss-summarize-video","Use to summarize a recorded video via the LVS summarization microservice (HITL-gated) with a VLM fallback. Not for report generation or live RTSP captioning.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-summarize-video\u002FSKILL.md",[],[],{"skillNo":115,"name":116,"nameZh":6,"description":117,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":19},"01M79G1WN63PGRE8CKD47WEBQ5","vss-setup-video-analytics-api","Use to deploy the vss-video-analytics-api REST service standalone (config-source, data-log bind, Elasticsearch, optional Kafka). Not for full warehouse deploy.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-setup-video-analytics-api\u002FSKILL.md",[],[],{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":127,"publishedAt":19},"01M79G1S9F7VY3EF6H53PRP5AN","vss-setup-behavior-analytics","Use to deploy the vss-behavior-analytics service standalone (entrypoint, config-source, optional calibration). Not for the full warehouse deploy.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-setup-behavior-analytics\u002FSKILL.md",[],[],{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":19},"01M79G1N1S1Y27PFZPYMNK1MTQ","vss-search-archive","Use this skill to run top-level VSS fusion search on archived video, or to ingest video files \u002F RTSP streams for search. Do NOT use for ad-hoc visual Q&A (use vss-ask-video), live captioning (use vss-deploy-dense-captioning), or video summarization and reports (use vss-summarize-video).","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-search-archive\u002FSKILL.md",[],[],{"skillNo":136,"name":137,"nameZh":6,"description":138,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":139,"categories":140,"keywords":141,"publishedAt":19},"01M79G1H6WN0Q6C0VCAXCZX6B7","vss-query-analytics","Use this skill when reading video-analytics metrics, incidents, alerts, and sensor data via the VA-MCP server (port 9901). Not for live VLM or incident-range narrative reports.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-query-analytics\u002FSKILL.md",[],[],{"skillNo":143,"name":144,"nameZh":6,"description":145,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":146,"categories":147,"keywords":148,"publishedAt":19},"01M79G1DYPNXQS7QHZ0AAF5FX5","vss-manage-video-io-storage","Use to call the VIOS REST API (sensor list, timelines, clip extraction, snapshots, add\u002Fdelete sensors and streams). Not for VLM inference or search.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-manage-video-io-storage\u002FSKILL.md",[],[]]