[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71NYSCGZM4XXRNXFWFXK879":3,"skill-same:01M71NYSCGZM4XXRNXFWFXK879":118},{"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":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":47,"commitSha":48,"skillDirectory":49,"forksCount":14,"repositoryHtmlUrl":50,"repositoryHomepageUrl":51,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":53,"install":54,"resources":67},"01M71NYSCGZM4XXRNXFWFXK879","nv-generate-mr-brain-finetune",null,"Used for finetuning NV-Generate-CTMR MR-brain diffusion UNet from a NIfTI datalist. Not for clinical or production data approval.","pattanation\u002FNorvik","pattanation","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F235419268?v=4","01M71M5THHYYB15ME8R2E4FCZG","Patta","01M71M5TJM1NDM992M8PDKYR2K",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"finetune","nv generate mr brain finetune","generate","nv generate mr","nv generate mr brain","brain","mr","approval","Production Data","Production","data","MRI","diffusion","team","Bash","finetuning","clinical","for","NVIDIA","2026-11-10 10:56:23",false,"---\nname: nv-generate-mr-brain-finetune\ndescription: Used for finetuning NV-Generate-CTMR MR-brain diffusion UNet from a NIfTI datalist. 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    - MRI\n    - brain\n    - finetune\n---\n\n# NV-Generate-MR-Brain-Finetune\n\n## Purpose\n- Used for finetuning the NV-Generate-CTMR `rflow-mr-brain` diffusion UNet from user-supplied NIfTI training volumes.\n- Not for clinical interpretation, regulatory use, or approving synthetic data for production training.\n- The wrapper stages the config glue locally and delegates execution to existing upstream scripts: `scripts.diff_model_create_training_data`, `scripts.diff_model_train`, and optionally `scripts.diff_model_infer`. It does not execute the notebook.\n- Manifest I\u002FO: inputs are `datalist` and `data_base_dir`; outputs are `finetuned_checkpoint`, optional `inference_outputs`, and `result_json`.\n- The underlying training contract is the upstream config\u002Fenv JSON (the same one driven from cell `[10]` of `train_diff_unet_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_mr_brain_finetune.py` from the Medical AI Skills repo root.\n- If a host agent exposes `run_script`, use `run_script(\"scripts\u002Frun_mr_brain_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:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir OUT_DIR \\\n  --modality mri_t1 \\\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_mr_brain_finetune.py` | Primary entrypoint declared by `skill_manifest.yaml`. | `DATALIST.json --data-base-dir DATA_DIR --output-dir OUT_DIR [--epochs N] [--modality mri_t1] [--num-gpus N] [--no-amp] [--model-config FILE] [--run-inference] [--preflight]` |\n\n## Prerequisites\n- An explicit `NV_GENERATE_ROOT` may point to the caller's local checkout and\n  must contain `scripts\u002Fdiff_model_create_training_data.py`,\n  `scripts\u002Fdiff_model_train.py`, and `scripts\u002Fdiff_model_infer.py`. The result\n  records its current commit.\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`, and downloaded MR-brain weights.\n- Side effects: writes staged configs, embeddings, checkpoints, optional inference images, and logs under the caller-provided `--output-dir`; may write model caches under the upstream checkout and `~\u002F.cache\u002Fhuggingface\u002F`; may contact `https:\u002F\u002Fhuggingface.co` for model assets and `https:\u002F\u002Fgithub.com` for the upstream checkout.\n- The datalist is a MONAI-style JSON object with `training[].image` paths relative to `--data-base-dir`. `training[].modality` is optional and defaults to `mri_t1`.\n\nWhen no local checkout is supplied, create the recommended pinned default\ncheckout once:\n\n```bash\nif [ -z \"${NV_GENERATE_ROOT:-}\" ]; then\n  export NV_GENERATE_COMMIT=61c4ec709b84cad468852243c48e250bec732074\n  export NV_GENERATE_ROOT=\"$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7\"\n  if [ ! -d \"$NV_GENERATE_ROOT\u002F.git\" ]; then\n    git clone https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR.git \"$NV_GENERATE_ROOT\"\n    git -C \"$NV_GENERATE_ROOT\" checkout --detach \"$NV_GENERATE_COMMIT\"\n  fi\nfi\n```\n\n## 1. Config and environment JSON (adapt to your data)\n\nThis is a thin wrapper around the upstream `train_diff_unet_tutorial.ipynb` flow. Each run performs four steps, delegating the heavy lifting to the model author's scripts:\n\n1. **Stage configs** — copy the three config JSONs and rewrite only the run-specific paths and `n_epochs` (notebook cell 15).\n2. `python -m scripts.diff_model_create_training_data` → latent `*_emb.nii.gz` embeddings (cell 17).\n3. **Write embedding sidecars** — a `\u003Cemb>.nii.gz.json` per embedding with `spacing`\u002F`modality` (and body-region indices when the model uses them). This is the one piece of glue that lives in the notebook (cell 19), not in upstream `scripts\u002F`, and `diff_model_train` requires it; the skill owns it.\n4. `python -m scripts.diff_model_train` (cell 21), optionally `python -m scripts.diff_model_infer`.\n\n**Tune by editing the config JSON, not by adding flags.** All training\u002Finference hyperparameters (`lr`, `batch_size`, `cache_rate`, inference `dim`\u002F`spacing`\u002F`num_inference_steps`\u002F`cfg_guidance_scale`, …) live in `config_maisi_diff_model_rflow-mr-brain.json`. Edit the upstream copy, or pass your own with `--model-config FILE` (and `--env-config` \u002F `--model-def` for the other two). The wrapper only ever rewrites the fields below.\n\nEnvironment JSON (`environment_maisi_diff_model_rflow-mr-brain.json`) — fields the wrapper rewrites per run:\n\n| Field | Set from | Notes |\n|---|---|---|\n| `data_base_dir` | `--data-base-dir` | Root for relative `training[].image` paths. |\n| `json_data_list` | your datalist | Staged copy with per-entry `modality` filled in. |\n| `embedding_base_dir`, `model_dir`, `output_dir` | `--output-dir` | Latent embeddings, checkpoints, inference images. |\n| `modality_mapping_path` | upstream | Maps modality name → integer code. |\n| `model_filename` | `--model-filename` | Output checkpoint name (default `diff_unet_3d_rflow-mr-brain_v0.pt`). |\n| `existing_ckpt_filepath` | upstream weights \u002F `--existing-ckpt-filepath` | Starting checkpoint; cleared by `--train-from-scratch`. |\n| `trained_autoencoder_path` | upstream weights \u002F `--trained-autoencoder-path` | VAE used to encode\u002Fdecode latents. |\n\nModel config (`config_maisi_diff_model_rflow-mr-brain.json`) — the only fields the wrapper touches:\n\n| Field | Set from | Default | Notes |\n|---|---|---|---|\n| `diffusion_unet_train.n_epochs` | `--epochs` | `2` (upstream config ships `1000`) | Convenience override (cell 15 does the same); wrapper default is small for verification. |\n| `diffusion_unet_inference.modality` | `--modality` | from `modality_mapping.json` | Kept consistent with the training modality for optional `--run-inference`. |\n\nEverything else in that file (`lr`, `batch_size`, `cache_rate`, the rest of `diffusion_unet_inference`) is left exactly as written — edit the JSON to change it.\n\nRuntime flags (not config fields): `--num-gpus N` (`>1` launches `torch.distributed.run`), `--no-amp` (disable mixed precision, passed through to `diff_model_train`).\n\n`--modality` selects the integer code from `configs\u002Fmodality_mapping.json`. Supported brain values: `mri` (8), `mri_t1` (9, default), `mri_t2` (10), `mri_flair` (11), `mri_swi` (20), and their `*_skull_stripped` variants (29\u002F30\u002F31\u002F32). Per-case `training[].modality` overrides `--modality`. The modality also feeds the step-3 embedding sidecars.\n\nFor an end-to-end reference including example data download and checkpoint loading, see the upstream tutorial `train_diff_unet_tutorial.ipynb`.\n\n## 2. Usage (one-line training)\n\nPreflight only:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nPreflight bundle input:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_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_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nGPU finetuning:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython -m pip install -r \"$NV_GENERATE_ROOT\u002Frequirements.txt\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune \\\n  --epochs 2 \\\n  --modality mri_t1 \\\n  --run-inference\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\n`scripts.diff_model_train` writes TensorBoard event files under the staged `model_dir` (`OUT_DIR\u002Fartifacts\u002Fmodels`). Launch TensorBoard against the output directory and watch the loss curve:\n\n```bash\npython -m pip install tensorboard && \\\ntensorboard --logdir runs\u002Fnv_generate_mr_brain_finetune\u002Fartifacts\n```\n\nThe run summary is written to `OUT_DIR\u002Fartifacts\u002Fworkflow_summary.json` (checkpoint path, embedding sidecars, inference outputs); the JSON the wrapper prints to stdout mirrors the same paths plus `exit_code` and a `stderr_tail` for quick triage.\n\n## 4. Hyperparameter tuning and common pitfalls\n\n- **Loss not decreasing \u002F unstable** — lower `diffusion_unet_train.lr` (default `1e-5`) in the model-config JSON, or keep AMP on (default); `--no-amp` is slower but more numerically stable on older GPUs.\n- **Out-of-memory** — keep `diffusion_unet_train.batch_size` at `1` and `cache_rate` at `0` in the config JSON, and confirm the autoencoder\u002FUNet fit your GPU before scaling. Multi-GPU (`--num-gpus N`) shards the batch via `torch.distributed.run`.\n- **Few cases \u002F quick check** — keep `--epochs` small (the wrapper default `2` is for verification, not convergence; the upstream config ships `1000`).\n- **Wrong modality conditioning** — set `--modality` or per-case `training[].modality` to a value present in `configs\u002Fmodality_mapping.json`; a mismatch produces a clear error rather than silently mislabeling latents.\n- **Slow startup on first run** — `diff_model_create_training_data` precomputes latent embeddings once; reuse the same `--output-dir` to avoid recomputing them.\n\n## 5. Evaluate the finetuned model\n\nUse the staged checkpoint (`OUT_DIR\u002Fartifacts\u002Fmodels\u002F\u003Cmodel_filename>`) as the diffusion UNet for generation, then inspect the synthesized volumes:\n\n- Pass `--run-inference` here for a quick built-in sanity render, or\n- Point the [`nv-generate-mr-brain`](..\u002Fnv-generate-mr-brain\u002FSKILL.md) inference skill at the finetuned checkpoint to generate fresh brain MRI volumes for qualitative review.\n\nThis skill gates file accounting and command provenance only — anatomical realism and downstream utility must be judged by a domain expert on the generated images.\n\n## Limitations\n- Requires a current upstream `NV-Generate-CTMR` checkout with the existing diffusion training scripts. The skill itself stages the required config and datalist glue locally and does not depend on the notebook or PR #33.\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 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| `diffusion training scripts 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| `missing datalist image` | `training[].image` paths are not relative to `--data-base-dir` or files are absent. | Fix the datalist or pass the correct data root. |\n| CUDA or MONAI import failure | Runtime environment lacks upstream dependencies. | Install `\"$NV_GENERATE_ROOT\u002Frequirements.txt\"` in the selected environment. |\n","# NV-Generate-MR-Brain-Finetune\n\n## Purpose\n- Used for finetuning the NV-Generate-CTMR `rflow-mr-brain` diffusion UNet from user-supplied NIfTI training volumes.\n- Not for clinical interpretation, regulatory use, or approving synthetic data for production training.\n- The wrapper stages the config glue locally and delegates execution to existing upstream scripts: `scripts.diff_model_create_training_data`, `scripts.diff_model_train`, and optionally `scripts.diff_model_infer`. It does not execute the notebook.\n- Manifest I\u002FO: inputs are `datalist` and `data_base_dir`; outputs are `finetuned_checkpoint`, optional `inference_outputs`, and `result_json`.\n- The underlying training contract is the upstream config\u002Fenv JSON (the same one driven from cell `[10]` of `train_diff_unet_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_mr_brain_finetune.py` from the Medical AI Skills repo root.\n- If a host agent exposes `run_script`, use `run_script(\"scripts\u002Frun_mr_brain_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:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir OUT_DIR \\\n  --modality mri_t1 \\\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_mr_brain_finetune.py` | Primary entrypoint declared by `skill_manifest.yaml`. | `DATALIST.json --data-base-dir DATA_DIR --output-dir OUT_DIR [--epochs N] [--modality mri_t1] [--num-gpus N] [--no-amp] [--model-config FILE] [--run-inference] [--preflight]` |\n\n## Prerequisites\n- An explicit `NV_GENERATE_ROOT` may point to the caller's local checkout and\n  must contain `scripts\u002Fdiff_model_create_training_data.py`,\n  `scripts\u002Fdiff_model_train.py`, and `scripts\u002Fdiff_model_infer.py`. The result\n  records its current commit.\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`, and downloaded MR-brain weights.\n- Side effects: writes staged configs, embeddings, checkpoints, optional inference images, and logs under the caller-provided `--output-dir`; may write model caches under the upstream checkout and `~\u002F.cache\u002Fhuggingface\u002F`; may contact `https:\u002F\u002Fhuggingface.co` for model assets and `https:\u002F\u002Fgithub.com` for the upstream checkout.\n- The datalist is a MONAI-style JSON object with `training[].image` paths relative to `--data-base-dir`. `training[].modality` is optional and defaults to `mri_t1`.\n\nWhen no local checkout is supplied, create the recommended pinned default\ncheckout once:\n\n```bash\nif [ -z \"${NV_GENERATE_ROOT:-}\" ]; then\n  export NV_GENERATE_COMMIT=61c4ec709b84cad468852243c48e250bec732074\n  export NV_GENERATE_ROOT=\"$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7\"\n  if [ ! -d \"$NV_GENERATE_ROOT\u002F.git\" ]; then\n    git clone https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR.git \"$NV_GENERATE_ROOT\"\n    git -C \"$NV_GENERATE_ROOT\" checkout --detach \"$NV_GENERATE_COMMIT\"\n  fi\nfi\n```\n\n## 1. Config and environment JSON (adapt to your data)\n\nThis is a thin wrapper around the upstream `train_diff_unet_tutorial.ipynb` flow. Each run performs four steps, delegating the heavy lifting to the model author's scripts:\n\n1. **Stage configs** — copy the three config JSONs and rewrite only the run-specific paths and `n_epochs` (notebook cell 15).\n2. `python -m scripts.diff_model_create_training_data` → latent `*_emb.nii.gz` embeddings (cell 17).\n3. **Write embedding sidecars** — a `\u003Cemb>.nii.gz.json` per embedding with `spacing`\u002F`modality` (and body-region indices when the model uses them). This is the one piece of glue that lives in the notebook (cell 19), not in upstream `scripts\u002F`, and `diff_model_train` requires it; the skill owns it.\n4. `python -m scripts.diff_model_train` (cell 21), optionally `python -m scripts.diff_model_infer`.\n\n**Tune by editing the config JSON, not by adding flags.** All training\u002Finference hyperparameters (`lr`, `batch_size`, `cache_rate`, inference `dim`\u002F`spacing`\u002F`num_inference_steps`\u002F`cfg_guidance_scale`, …) live in `config_maisi_diff_model_rflow-mr-brain.json`. Edit the upstream copy, or pass your own with `--model-config FILE` (and `--env-config` \u002F `--model-def` for the other two). The wrapper only ever rewrites the fields below.\n\nEnvironment JSON (`environment_maisi_diff_model_rflow-mr-brain.json`) — fields the wrapper rewrites per run:\n\n| Field | Set from | Notes |\n|---|---|---|\n| `data_base_dir` | `--data-base-dir` | Root for relative `training[].image` paths. |\n| `json_data_list` | your datalist | Staged copy with per-entry `modality` filled in. |\n| `embedding_base_dir`, `model_dir`, `output_dir` | `--output-dir` | Latent embeddings, checkpoints, inference images. |\n| `modality_mapping_path` | upstream | Maps modality name → integer code. |\n| `model_filename` | `--model-filename` | Output checkpoint name (default `diff_unet_3d_rflow-mr-brain_v0.pt`). |\n| `existing_ckpt_filepath` | upstream weights \u002F `--existing-ckpt-filepath` | Starting checkpoint; cleared by `--train-from-scratch`. |\n| `trained_autoencoder_path` | upstream weights \u002F `--trained-autoencoder-path` | VAE used to encode\u002Fdecode latents. |\n\nModel config (`config_maisi_diff_model_rflow-mr-brain.json`) — the only fields the wrapper touches:\n\n| Field | Set from | Default | Notes |\n|---|---|---|---|\n| `diffusion_unet_train.n_epochs` | `--epochs` | `2` (upstream config ships `1000`) | Convenience override (cell 15 does the same); wrapper default is small for verification. |\n| `diffusion_unet_inference.modality` | `--modality` | from `modality_mapping.json` | Kept consistent with the training modality for optional `--run-inference`. |\n\nEverything else in that file (`lr`, `batch_size`, `cache_rate`, the rest of `diffusion_unet_inference`) is left exactly as written — edit the JSON to change it.\n\nRuntime flags (not config fields): `--num-gpus N` (`>1` launches `torch.distributed.run`), `--no-amp` (disable mixed precision, passed through to `diff_model_train`).\n\n`--modality` selects the integer code from `configs\u002Fmodality_mapping.json`. Supported brain values: `mri` (8), `mri_t1` (9, default), `mri_t2` (10), `mri_flair` (11), `mri_swi` (20), and their `*_skull_stripped` variants (29\u002F30\u002F31\u002F32). Per-case `training[].modality` overrides `--modality`. The modality also feeds the step-3 embedding sidecars.\n\nFor an end-to-end reference including example data download and checkpoint loading, see the upstream tutorial `train_diff_unet_tutorial.ipynb`.\n\n## 2. Usage (one-line training)\n\nPreflight only:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nPreflight bundle input:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_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_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nGPU finetuning:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-$HOME\u002F.cache\u002Fnvidia-skills\u002Fupstreams\u002FNV-Generate-CTMR-61c4ec7}\" && \\\npython -m pip install -r \"$NV_GENERATE_ROOT\u002Frequirements.txt\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune \\\n  --epochs 2 \\\n  --modality mri_t1 \\\n  --run-inference\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\n`scripts.diff_model_train` writes TensorBoard event files under the staged `model_dir` (`OUT_DIR\u002Fartifacts\u002Fmodels`). Launch TensorBoard against the output directory and watch the loss curve:\n\n```bash\npython -m pip install tensorboard && \\\ntensorboard --logdir runs\u002Fnv_generate_mr_brain_finetune\u002Fartifacts\n```\n\nThe run summary is written to `OUT_DIR\u002Fartifacts\u002Fworkflow_summary.json` (checkpoint path, embedding sidecars, inference outputs); the JSON the wrapper prints to stdout mirrors the same paths plus `exit_code` and a `stderr_tail` for quick triage.\n\n## 4. Hyperparameter tuning and common pitfalls\n\n- **Loss not decreasing \u002F unstable** — lower `diffusion_unet_train.lr` (default `1e-5`) in the model-config JSON, or keep AMP on (default); `--no-amp` is slower but more numerically stable on older GPUs.\n- **Out-of-memory** — keep `diffusion_unet_train.batch_size` at `1` and `cache_rate` at `0` in the config JSON, and confirm the autoencoder\u002FUNet fit your GPU before scaling. Multi-GPU (`--num-gpus N`) shards the batch via `torch.distributed.run`.\n- **Few cases \u002F quick check** — keep `--epochs` small (the wrapper default `2` is for verification, not convergence; the upstream config ships `1000`).\n- **Wrong modality conditioning** — set `--modality` or per-case `training[].modality` to a value present in `configs\u002Fmodality_mapping.json`; a mismatch produces a clear error rather than silently mislabeling latents.\n- **Slow startup on first run** — `diff_model_create_training_data` precomputes latent embeddings once; reuse the same `--output-dir` to avoid recomputing them.\n\n## 5. Evaluate the finetuned model\n\nUse the staged checkpoint (`OUT_DIR\u002Fartifacts\u002Fmodels\u002F\u003Cmodel_filename>`) as the diffusion UNet for generation, then inspect the synthesized volumes:\n\n- Pass `--run-inference` here for a quick built-in sanity render, or\n- Point the [`nv-generate-mr-brain`](..\u002Fnv-generate-mr-brain\u002FSKILL.md) inference skill at the finetuned checkpoint to generate fresh brain MRI volumes for qualitative review.\n\nThis skill gates file accounting and command provenance only — anatomical realism and downstream utility must be judged by a domain expert on the generated images.\n\n## Limitations\n- Requires a current upstream `NV-Generate-CTMR` checkout with the existing diffusion training scripts. The skill itself stages the required config and datalist glue locally and does not depend on the notebook or PR #33.\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 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| `diffusion training scripts 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| `missing datalist image` | `training[].image` paths are not relative to `--data-base-dir` or files are absent. | Fix the datalist or pass the correct data root. |\n| CUDA or MONAI import failure | Runtime environment lacks upstream dependencies. | Install `\"$NV_GENERATE_ROOT\u002Frequirements.txt\"` in the selected environment. |\n",{"name":5,"license":15,"metadata":43,"description":7,"allowed-tools":33},{"tags":44,"author":46},[45,30,24,19],"MedTech","NVIDIA MedTech Team","claude\u002Finstall-gsd-build-foQdV","d86cd127f527124b5fd0fd0bc679a4d79b7d01d7",".agents\u002Fskills\u002Fnv-generate-mr-brain-finetune","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik","https:\u002F\u002Fnorvik-orpin.vercel.app","https:\u002F\u002Fgithub.com\u002Fpattanation","2026-07-17 11:17:04",{"source":8,"skillName":5,"commands":55,"prompt":65,"zipAvailable":66},[56,59,62],{"tool":57,"command":58},"npx","npx skills add pattanation\u002FNorvik --skill nv-generate-mr-brain-finetune",{"tool":60,"command":61},"bunx","bunx skills add pattanation\u002FNorvik --skill nv-generate-mr-brain-finetune",{"tool":63,"command":64},"pnpm","pnpm dlx skills add pattanation\u002FNorvik --skill nv-generate-mr-brain-finetune","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md",true,[68,74,78,82,86,90,96,100,104,110,114],{"path":69,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":72,"sourceHtmlUrl":73},"BENCHMARK.md","REFERENCE","参考文档",4082,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002FBENCHMARK.md",{"path":75,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":76,"sourceHtmlUrl":77},"evals\u002Fevals.json",1228,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Fevals\u002Fevals.json",{"path":79,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":80,"sourceHtmlUrl":81},"fixtures\u002Fpreflight_datalist.json",130,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002Fpreflight_datalist.json",{"path":83,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":84,"sourceHtmlUrl":85},"fixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_t1.txt",133,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_t1.txt",{"path":87,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":88,"sourceHtmlUrl":89},"fixtures\u002FREADME.md",228,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002FREADME.md",{"path":91,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":94,"sourceHtmlUrl":95},"scripts\u002Frun_mr_brain_finetune.py","SCRIPT","脚本",27467,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py",{"path":97,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":98,"sourceHtmlUrl":99},"skill_manifest.yaml",6314,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Fskill_manifest.yaml",{"path":101,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":102,"sourceHtmlUrl":103},"skill-card.md",4106,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Fskill-card.md",{"path":105,"resourceType":106,"resourceTypeDesc":107,"sizeBytes":108,"sourceHtmlUrl":109},"skill.oms.sig","OTHER","其他",6333,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Fskill.oms.sig",{"path":111,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":112,"sourceHtmlUrl":113},"tests\u002Ftest_run_mr_brain_finetune.py",6761,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Ftests\u002Ftest_run_mr_brain_finetune.py",{"path":115,"resourceType":70,"resourceTypeDesc":71,"sizeBytes":116,"sourceHtmlUrl":117},"validators\u002Foutput_schema.json",3842,"https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fnv-generate-mr-brain-finetune\u002Fvalidators\u002Foutput_schema.json",[119,127,134,141,166,191],{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":125,"publishedAt":126},"01M73Z1NPMJ667E0DSPBS9FH0B","jetson-set-target","Switch the active Jetson target-platform pointer to an existing profile YAML. Use before customize\u002Fbuild\u002Fflash to change target; not for authoring profiles — use jetson-init-target instead.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fjetson-set-target\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":128,"name":129,"nameZh":6,"description":130,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":131,"categories":132,"keywords":133,"publishedAt":126},"01M73YC29YWGCW521P7B0NM3HQ","earth2studio-data-fetch","Fetch weather\u002Fclimate data via Earth2Studio data sources for specific variables and times. Do NOT use for inference pipelines, model discovery, or installation.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fearth2studio-data-fetch\u002FSKILL.md",[],[],{"skillNo":135,"name":136,"nameZh":6,"description":137,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":138,"categories":139,"keywords":140,"publishedAt":126},"01M73YBNHMHFDFP83MAVGQQ92N","earth2studio-create-datasource","Create and validate Earth2Studio data source wrappers (DataSource, ForecastSource, DataFrameSource, ForecastFrameSource) from remote stores. Do NOT use for fetching data with existing sources, model inference, or installation tasks.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fearth2studio-create-datasource\u002FSKILL.md",[],[],{"skillNo":142,"name":143,"nameZh":6,"description":144,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":145,"sourceHtmlUrl":146,"categories":147,"keywords":148,"publishedAt":165},"01M71QDV4DM8T19HEHWATEF1K4","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[149,150,151,152,153,36,154,155,156,157,158,159,160,161,162,163,164],"webapp","testing","webapp testing","local","screenshots","applications","browser","ui","behavior","web","playwright","with","frontend","debugging","toolkit","logs","2026-11-10 13:02:02",{"skillNo":167,"name":168,"nameZh":6,"description":169,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":170,"sourceHtmlUrl":171,"categories":172,"keywords":173,"publishedAt":165},"01M71QDH2GGMXGA9105C9W1N7B","web-artifacts-builder","Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn\u002Fui). Use for complex artifacts requiring state management, routing, or shadcn\u002Fui components - not for simple single-file HTML\u002FJSX artifacts.","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fweb-artifacts-builder\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[174,158,175,176,177,178,179,180,181,182,183,184,36,185,186,161,187,188,189,190],"web artifacts builder","artifacts","artifacts builder","builder","multi","state","routing","state management","react","single-file","css","Tailwind","ui components","single","use","file","components",{"skillNo":192,"name":193,"nameZh":6,"description":194,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":195,"licenseFileUrl":196,"sourceHtmlUrl":197,"categories":198,"keywords":199,"publishedAt":165},"01M71QD9T2XC3EWMQNN9ACNWQ1","vueuse-functions","Apply VueUse composables where appropriate to build concise, maintainable Vue.js \u002F Nuxt features.","MIT","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fvueuse-functions\u002FLICENSE.md","https:\u002F\u002Fgithub.com\u002Fpattanation\u002FNorvik\u002Fblob\u002Fclaude\u002Finstall-gsd-build-foQdV\u002F.agents\u002Fskills\u002Fvueuse-functions\u002FSKILL.md",[],[200,201,202,203,204,205,206,207,208,209,210,211,212,213],"vueuse","vueuse functions","functions","composables","project","nuxt","apply","github","concise","build","https","features","vue","js"]