Nv Generate Vae Finetune
NVIDIAOfficialCreated by NVIDIA MedTech Team
- Skill
- Workflow
- Software development
- Apache-2.0
- Medium risk
- Has scripts
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a wrapper for finetuning the NV-Generate-CTMR MAISI VAE/autoencoder. It manages the configuration and execution flow by staging required JSON files and providing a CLI interface to interact with upstream helper APIs. It supports preflight validation of datalists and GPU-based training, while handling output bookkeeping for checkpoints and TensorBoard logs. This tool is intended for research and development workflows and is not for clinical or production data approval.
What it does
- Stages configuration and environment files for VAE finetuning.
- Validates input datalists and data directories via a preflight check.
- Executes GPU-based finetuning of the MAISI VAE model.
- Exposes configurable hyperparameters for training, such as epochs, patch size, and loss weights.
- Generates TensorBoard logs and summary JSON files for training monitoring.
- Saves autoencoder and discriminator checkpoints for downstream evaluation.
When to use it
- When you need to finetune a MAISI VAE model on custom CT or MRI NIfTI datasets.
- When you need to validate the structure of a training datalist before initiating a training run.
- When you need to monitor training progress through TensorBoard scalars and loss history.
- When you need to adjust training parameters like perceptual weight or learning rate for specific data.
Advantages
- Simplifies the configuration process by automating the staging of upstream JSON files.
- Provides a consistent CLI interface for both preflight checks and full training runs.
- Integrates with TensorBoard for tracking loss metrics and validation performance.
- Allows for flexible hyperparameter tuning to address common issues like reconstruction blurriness.
Usage examples
- “Run a preflight check on my MRI dataset located in /data/mri_bundle.”
- The skill validates the datalist and dataset structure without starting a GPU training job.
- “Finetune the VAE model on my CT data for 5 epochs.”
- The skill initiates the training process using the provided datalist, saving checkpoints and logs to the specified output directory.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/nvidia/nv-generate-vae-finetune/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip nv-generate-vae-finetune.zip -d .agents/skills
Documentation by NVIDIA MedTech Team
NV-Generate-VAE-Finetune
Purpose
Used for finetuning the NV-Generate-CTMR MAISI VAE/autoencoder from user-supplied CT or MRI NIfTI training volumes.
Not for clinical interpretation, regulatory use, or approving synthetic data for production training.
Upstream currently documents VAE training in
train_vae_tutorial.ipynband provides configs/helpers, but not ascripts.train_vaeCLI. This skill does not execute the notebook; it stages the required config/datalist glue locally and uses upstream helper APIs.Manifest I/O: inputs are
datalistanddata_base_dir; outputs areautoencoder_checkpoint,discriminator_checkpoint, andresult_json.The underlying training contract is the upstream config/env JSON (
config_maisi_vae_train.json+environment_maisi_vae_train.json, as used intrain_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/tune a run.
Instructions
Read
skill_manifest.yamlbefore changing arguments, side effects, or validation gates.Run
scripts/run_vae_finetune.pyfrom the Medical AI Skills repo root.If a host agent exposes
run_script, userun_script("scripts/run_vae_finetune.py", args=[...]); otherwise run the Bash/Python command below.Use
--preflightfirst when checking a new datalist; remove--preflightonly when the user explicitly wants to launch GPU finetuning.For a staged preflight input bundle directory, use
BUNDLE/preflight_datalist.jsonas the datalist andBUNDLE/preflight_datasetas--data-base-dirwhen those files are present.
Examples
Validate 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:
export NV_GENERATE_ROOT="${NV_GENERATE_ROOT:-$HOME/.cache/nvidia-skills/upstreams/NV-Generate-CTMR-61c4ec7}" && \
python skills/nv-generate-vae-finetune/scripts/run_vae_finetune.py \
INPUT_BUNDLE/preflight_datalist.json \
--data-base-dir INPUT_BUNDLE/preflight_dataset \
--output-dir OUT_DIR \
--modality mri \
--preflightFor real GPU finetuning and other variations, see Usage below.
Available Scripts
| Script | Purpose | Arguments |
|---|---|---|
scripts/run_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] |
Prerequisites
An explicit
NV_GENERATE_ROOTmay point to the caller's local checkout and must containconfigs/config_maisi_vae_train.json,scripts/transforms.py, andscripts/utils.py. The result records its current commit.If
NV_GENERATE_ROOTis unset, the wrapper searches.workbench_data/upstreams/NV-Generate-CTMR.CUDA_VISIBLE_DEVICESis optional and can be used to select the GPU for real training.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.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,~/.cache/huggingface/, and~/.cache/torch/; may contacthttps://huggingface.co,https://github.com, andhttps://download.pytorch.org.The datalist is a MONAI-style JSON object with non-empty
training[]andvalidation[]ortesting[]. Each entry has animagepath relative to--data-base-dirand optionalclassormodalityofctormri.
When no local checkout is supplied, create the recommended pinned default checkout once:
if [ -z "${NV_GENERATE_ROOT:-}" ]; then
export NV_GENERATE_COMMIT=61c4ec709b84cad468852243c48e250bec732074
export NV_GENERATE_ROOT="$HOME/.cache/nvidia-skills/upstreams/NV-Generate-CTMR-61c4ec7"
if [ ! -d "$NV_GENERATE_ROOT/.git" ]; then
git clone https://github.com/NVIDIA-Medtech/NV-Generate-CTMR.git "$NV_GENERATE_ROOT"
git -C "$NV_GENERATE_ROOT" checkout --detach "$NV_GENERATE_COMMIT"
fi
fi1. Config and environment JSON (adapt to your data)
The wrapper copies the upstream VAE config/env JSON from $NV_GENERATE_ROOT/configs, rewrites the fields below, and writes the staged copies under OUT_DIR/workflow/configs/. You normally only set your datalist and data root; the listed CLI flags override individual fields when you need to.
Environment JSON (environment_maisi_vae_train.json):
| Field | Set from | Notes |
|---|---|---|
model_dir | --output-dir | Where autoencoder.pt/discriminator.pt and best checkpoints are saved. |
tfevent_path | --output-dir | TensorBoard event directory. |
finetune | --train-from-scratch | true (default) loads trained_autoencoder_path; the flag sets it false. |
trained_autoencoder_path | upstream weights / --trained-autoencoder-path | Starting VAE checkpoint when finetuning. |
Training fields (config_maisi_vae_train.json):
| Field | Flag | Type | Default | Notes |
|---|---|---|---|---|
autoencoder_train.n_epochs | --epochs | int | 1 | |
autoencoder_train.batch_size | --batch-size | int | 1 | Per-GPU (single-GPU runner). |
autoencoder_train.patch_size | --patch-size | int,int,int | 64,64,64 | Training crop. |
autoencoder_train.val_batch_size | --val-batch-size | int | 1 | |
autoencoder_train.val_sliding_window_patch_size | --val-sliding-window-patch-size | int,int,int | 96,96,64 | Sliding-window validation ROI. |
autoencoder_train.lr | --lr | float | 1e-4 | |
autoencoder_train.perceptual_weight | --perceptual-weight | float | 0.3 | LPIPS term. |
autoencoder_train.kl_weight | --kl-weight | float | 1e-7 | KL term. |
autoencoder_train.adv_weight | --adv-weight | float | 0.1 | Adversarial term. |
autoencoder_train.recon_loss | --recon-loss | l1|l2 | l1 | |
autoencoder_train.val_interval | --val-interval | int | 1 | Epochs between validation passes. |
autoencoder_train.cache | --cache-rate | float | 0.0 | MONAI CacheDataset fraction. |
autoencoder_train.amp | --no-amp | flag | on | Mixed precision; flag disables it. |
data_option.random_aug | --no-random-aug | flag | on | Random augmentation; flag disables it. |
data_option.spacing_type | --spacing-type | original|fixed|rand_zoom | original | |
data_option.spacing | --spacing | float,float,float | unset | Required when spacing_type is fixed/rand_zoom. |
data_option.select_channel | --select-channel | int | 0 | Channel for multi-channel inputs. |
--modality (ct or mri, default mri) fills the per-entry class for datalist items missing one. Validation/testing entries are required because the training loop runs a validation pass.
For an end-to-end reference including example data download, see the upstream tutorial train_vae_tutorial.ipynb.
2. Usage (one-line training)
Preflight only:
export NV_GENERATE_ROOT="${NV_GENERATE_ROOT:-$HOME/.cache/nvidia-skills/upstreams/NV-Generate-CTMR-61c4ec7}" && \
python skills/nv-generate-vae-finetune/scripts/run_vae_finetune.py \
PATH_TO_DATALIST.json \
--data-base-dir PATH_TO_DATA_ROOT \
--output-dir runs/nv_generate_vae_finetune_preflight \
--preflightPreflight bundle input:
export NV_GENERATE_ROOT="${NV_GENERATE_ROOT:-$HOME/.cache/nvidia-skills/upstreams/NV-Generate-CTMR-61c4ec7}" && \
python skills/nv-generate-vae-finetune/scripts/run_vae_finetune.py \
PATH_TO_INPUT_BUNDLE/preflight_datalist.json \
--data-base-dir PATH_TO_INPUT_BUNDLE/preflight_dataset \
--output-dir runs/nv_generate_vae_finetune_preflight \
--preflightGPU finetuning:
export NV_GENERATE_ROOT="${NV_GENERATE_ROOT:-$HOME/.cache/nvidia-skills/upstreams/NV-Generate-CTMR-61c4ec7}" && \
python -m pip install -r "$NV_GENERATE_ROOT/requirements.txt" && \
python -m pip install lpips tensorboard && \
python skills/nv-generate-vae-finetune/scripts/run_vae_finetune.py \
PATH_TO_DATALIST.json \
--data-base-dir PATH_TO_DATA_ROOT \
--output-dir runs/nv_generate_vae_finetune \
--epochs 1 \
--modality mri \
--patch-size 64,64,64 \
--download-model-dataReplace 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.
3. Monitor training (TensorBoard)
The runner writes TensorBoard scalars (per-iteration and per-epoch recons_loss, kl_loss, p_loss, adversarial/real/fake losses, and a validation scale_factor) under OUT_DIR/artifacts/tfevent/autoencoder. Launch TensorBoard against the output directory:
python -m pip install tensorboard && \
tensorboard --logdir runs/nv_generate_vae_finetune/artifacts/tfeventThe same per-epoch loss history is also captured in OUT_DIR/artifacts/workflow_summary.json and echoed in the JSON the wrapper prints to stdout (loss_history, best-checkpoint paths, exit_code, stderr_tail).
4. Hyperparameter tuning and common pitfalls
Reconstructions blurry — raise
--perceptual-weight(default0.3); try--recon-loss l2if edges look washed out.Posterior collapse / over-regularized latents —
--kl-weightis intentionally tiny (1e-7); increasing it too much degrades reconstruction.Adversarial training unstable — lower
--adv-weight(default0.1) or--lr; a warmup schedule already ramps the LR over the first 20 epochs.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.datalist must include non-empty validation[] or testing[]— the validation loop is mandatory; addvalidation[](ortesting[]) entries.Single-GPU only — the runner asserts exactly one CUDA GPU; set
CUDA_VISIBLE_DEVICESto pick which one.
5. Evaluate the finetuned VAE
Validation reconstruction loss (lowest-val_weighted_loss epoch) is tracked automatically and the best autoencoder is saved as autoencoder_epochN.pt under OUT_DIR/artifacts/models. To evaluate downstream:
Compare validation
recons_loss/p_losscurves across runs in TensorBoard, andPlug the finetuned autoencoder into a diffusion finetune/generation run (e.g.
nv-generate-mr-brain-finetunevia--trained-autoencoder-path) to confirm latents still decode to usable volumes.
This skill gates file accounting and reconstruction bookkeeping only — image quality and downstream utility must be judged by a domain expert.
Limitations
Requires a current upstream
NV-Generate-CTMRcheckout with VAE configs and helper APIs. The skill owns the runner glue and does not depend on the notebook.Full training can be expensive and is not deterministic across hardware, CUDA, and package versions.
The wrapper gates file accounting and command provenance, not anatomical realism, reconstruction quality, or downstream model utility.
Not for clinical deployment, clinical interpretation, autonomous diagnosis, regulatory submission, or production training-data approval.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
VAE configs/helpers were not found | NV_GENERATE_ROOT does not point at a current NV-Generate-CTMR checkout. | Clone or update https://github.com/NVIDIA-Medtech/NV-Generate-CTMR and set NV_GENERATE_ROOT. |
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. |
| CUDA, MONAI, or LPIPS import failure | Runtime environment lacks upstream dependencies. | Install "$NV_GENERATE_ROOT/requirements.txt" plus lpips tensorboard in the selected environment. |
Files
- ATTRIBUTION.mdAdded by AutoGineer943 B
- BENCHMARK.md4.0 KiB
- LICENSELicence file added by AutoGineer11.2 KiB
- SKILL.md12.2 KiB
- evals/evals.json1.2 KiB
- fixtures/README.md232 B
- fixtures/preflight_datalist.json221 B
- fixtures/preflight_dataset/imagesTr/placeholder_mri_train.txt37 B
- fixtures/preflight_dataset/imagesVal/placeholder_mri_val.txt37 B
- scripts/run_vae_finetune.pyScript32.1 KiB
- skill-card.md4.0 KiB
- skill.oms.sig6.4 KiB
- skill_manifest.yaml6.2 KiB
- tests/test_run_vae_finetune.pyScript5.6 KiB
- validators/output_schema.json4.0 KiB
LICENSE
Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Declares allowed tools, Needs a command-line tool, Needs Python
Security
What our scanner noticed· Medium risk
- Large base64-encoded blobs
- Instructions that use the network
- Scripts that your agent may run
This skill includes scripts that your agent may run. Read them before you use it.
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- NVIDIA MedTech Team
- Publisher
- NVIDIA (Official)
- Source
- NVIDIA/skills · skills/nv-generate-vae-finetune · commit fce3cca
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE-APACHE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by NVIDIA MedTech Team or NVIDIA.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download nv-generate-vae-finetune.zip