Skip to content

Added --save-latent flag to train-vae for latent mu/sigma and loss hi… - #67

Open
kbcoulter wants to merge 3 commits into
ohsu-comp-bio:developfrom
kbcoulter:feature/save-latent-stats
Open

Added --save-latent flag to train-vae for latent mu/sigma and loss hi…#67
kbcoulter wants to merge 3 commits into
ohsu-comp-bio:developfrom
kbcoulter:feature/save-latent-stats

Conversation

@kbcoulter

Copy link
Copy Markdown
Contributor

Add --save-latent flag to train-vae for latent stat and loss saving

train_vae conveniently had --save-stats added, which saves mean/std, but not latent mu/sigma or per-epoch loss. Latent mu is needed for the betascan test in embedding-rotation.

Changes

New --save-latent flag for train-vae (independent of --save-stats):

  • Writes per-epoch loss/recon/kl to {out}.losses_stats.tsv
  • Runs vae.eval() with no-grad on the training data to export mu/sigma to {out}.latent_mu.tsv and {out}.latent_std.tsv
  • Uses device/dtype instead of forcing float32, to work with --bfloat16

Opening this for review. I am happy to add tests for train-vae if the approach looks good or look at adding --save-latent into other models (train-netvae) if thatd be useful.

…story, used in betascan.

- model.py
    - train_vae: new --save-latent flag (independent of --save-stats)
        - Writes per-epoch loss/recon/kl history to {out}.losses_stats.tsv
        - Runs vae.eval() then a no-grad pass over the training data to export mu/sigma to {out}.latent_mu.tsv and {out}.latent_std.tsv
        - x_tensor uses device/dtype (not .float()) so it matches the model under --bfloat16
-cli.md
    - Added save-latent to docs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new --save-latent flag to the embkit model train-vae CLI command to persist per-epoch training losses and latent distribution statistics (mu/std) for downstream analysis workflows (e.g., betascan/embedding rotation).

Changes:

  • Introduces --save-latent to export {out}.losses_stats.tsv, {out}.latent_mu.tsv, and {out}.latent_std.tsv after training.
  • Runs an eval/no-grad pass over the training dataset to compute and save latent mu and sigma.
  • Updates CLI documentation to include the new flag.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/embkit/commands/model.py Adds the --save-latent flag and implements loss + latent mu/std export.
docs/cli.md Documents the new --save-latent option for train-vae.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/embkit/commands/model.py Outdated
Comment thread src/embkit/commands/model.py
Comment thread src/embkit/commands/model.py
To 32 before building. Everything here is functionally identical.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@kbcoulter
kbcoulter marked this pull request as draft August 3, 2026 18:35
Covers losses, mu, std, sample index, save-stats (with save-latent)
@kbcoulter
kbcoulter marked this pull request as ready for review August 3, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants