[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M78D30DM1F2ZAHMH5JBA2S2C":3,"skill-same:01M78D30DM1F2ZAHMH5JBA2S2C":105},{"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":32,"commitSha":33,"skillDirectory":34,"forksCount":14,"repositoryHtmlUrl":35,"repositoryHomepageUrl":36,"ownerHtmlUrl":37,"ownerBlogUrl":38,"ownerDescription":39,"updatedAt":40,"install":41,"resources":54},"01M78D30DM1F2ZAHMH5JBA2S2C","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.","Solizardking\u002Fskillhub-main","Solizardking","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F108096810?v=4","01M786KDB10AYV042N0F9BD5B5","Clawd","01M786NYYXSZK1D05WM8JQPC48",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md",[],[],"2026-11-15 14:19:17",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":24,"description":7,"allowed-tools":31},{"tags":25,"author":30},[26,27,28,29],"MedTech","MRI","brain","finetune","NVIDIA MedTech Team","Bash","main","be3de0244dc1a57e323d8160787ebb40fb64930e","skills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main","https:\u002F\u002Fskills.x402.wtf","https:\u002F\u002Fgithub.com\u002FSolizardking","https:\u002F\u002Fmusebook.trade","Got a mile high and never came down","2026-10-08 23:20:13",{"source":8,"skillName":5,"commands":42,"prompt":52,"zipAvailable":53},[43,46,49],{"tool":44,"command":45},"npx","npx skills add Solizardking\u002Fskillhub-main --skill nv-generate-mr-brain-finetune",{"tool":47,"command":48},"bunx","bunx skills add Solizardking\u002Fskillhub-main --skill nv-generate-mr-brain-finetune",{"tool":50,"command":51},"pnpm","pnpm dlx skills add Solizardking\u002Fskillhub-main --skill nv-generate-mr-brain-finetune","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md",true,[55,61,65,69,73,77,83,87,91,97,101],{"path":56,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":60},"BENCHMARK.md","REFERENCE","参考文档",4082,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002FBENCHMARK.md",{"path":62,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":63,"sourceHtmlUrl":64},"evals\u002Fevals.json",1228,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fevals\u002Fevals.json",{"path":66,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":67,"sourceHtmlUrl":68},"fixtures\u002Fpreflight_datalist.json",130,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002Fpreflight_datalist.json",{"path":70,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":71,"sourceHtmlUrl":72},"fixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_t1.txt",133,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_t1.txt",{"path":74,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":75,"sourceHtmlUrl":76},"fixtures\u002FREADME.md",228,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002FREADME.md",{"path":78,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"scripts\u002Frun_mr_brain_finetune.py","SCRIPT","脚本",27467,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py",{"path":84,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":85,"sourceHtmlUrl":86},"skill_manifest.yaml",6314,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fskill_manifest.yaml",{"path":88,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":89,"sourceHtmlUrl":90},"skill-card.md",4106,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fskill-card.md",{"path":92,"resourceType":93,"resourceTypeDesc":94,"sizeBytes":95,"sourceHtmlUrl":96},"skill.oms.sig","OTHER","其他",6333,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fskill.oms.sig",{"path":98,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":99,"sourceHtmlUrl":100},"tests\u002Ftest_run_mr_brain_finetune.py",6761,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ftests\u002Ftest_run_mr_brain_finetune.py",{"path":102,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":103,"sourceHtmlUrl":104},"validators\u002Foutput_schema.json",3842,"https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fvalidators\u002Foutput_schema.json",[106,114,121,128,135,143],{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":110,"licenseFileUrl":6,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":19},"01M78E0TGCAMNPS207BA3G07S7","zkrouter","Self-hosted OpenAI-compatible LLM router — smart tier-based routing, ZK-stamped routing decisions, mode overrides, free OpenRouter at install via the Birth bot. Save 60-80% on inference costs by routing to the cheapest capable model across 12+ OpenRouter models.","MIT","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fzkrouter\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":110,"licenseFileUrl":6,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":19},"01M78E0R1Z8BDT6EDTHY17MTNB","zk","For custom ZK Solana programs and privacy-preserving applications to prevent double spending. Guide to integrate rent-free nullifier PDAs for double-spend prevention.","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fzk\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":110,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":127,"publishedAt":19},"01M78E0P3ZTZ1YWF8MD5MM23QE","zk-omni-messaging","Zero-knowledge omnichain messaging between Robinhood Chain and Solana using CheshireZkOmniMessenger (msgType 4) with nullifier anti-replay and the zk-omni-relayer service.","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fzk-omni-messaging\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":110,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":134,"publishedAt":19},"01M78E0JXZ2PNB1896VXAGDBWD","zerion-wallet-data","Use when the user asks to check a wallet's portfolio, token balances, DeFi positions, PnL, transaction history, or NFTs. Provides interpreted on-chain data across 40+ EVM chains and Solana via x402 pay-per-request or API key — no raw RPC decoding needed.","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fzerion-wallet-data\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":110,"licenseFileUrl":139,"sourceHtmlUrl":140,"categories":141,"keywords":142,"publishedAt":19},"01M78E0G14FH9GRRTQYMKD5E59","youtube-clipper","YouTube 视频智能剪辑工具。下载视频和字幕，AI 分析生成精细章节（几分钟级别）， 用户选择片段后自动剪辑、翻译字幕为中英双语、烧录字幕到视频，并生成总结文案。 使用场景：当用户需要剪辑 YouTube 视频、生成短视频片段、制作双语字幕版本时。 关键词：视频剪辑、YouTube、字幕翻译、双语字幕、视频下载、clip video","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fyoutube-clipper\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fyoutube-clipper\u002FSKILL.md",[],[],{"skillNo":144,"name":145,"nameZh":6,"description":146,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":110,"licenseFileUrl":6,"sourceHtmlUrl":147,"categories":148,"keywords":149,"publishedAt":19},"01M78E0C2ZYA99CFFDNB7ZMK5S","yield-optimization","Multi-chain yield optimization via yield.xyz (StakeKit). Discover 2,988+ yield opportunities across 75+ blockchains, build deposit\u002Fwithdrawal transactions with shell scripts, and sign them with a MoonPay wallet. Use when the user wants to earn yield, find the best lending or staking rate, enter\u002Fexit a position, or check portfolio balances.","https:\u002F\u002Fgithub.com\u002FSolizardking\u002Fskillhub-main\u002Fblob\u002Fmain\u002Fskills\u002Fyield-optimization\u002FSKILL.md",[],[]]