Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Migrates the VAE example (
examples/vae) fromflax.linentoflax.nnx, as requested in #5068.Encoder,Decoder, and theVAEwrapper asnnx.Modulewithnnx.Linear, keeping the original architecture (784 → 500 → latent 20 → 500 → 784) and parameter count (815,824, identical to the linen version).flax.training.train_state.TrainStatewithnnx.Optimizer(optax.adam), andapply()-based training/eval with direct model calls under@nnx.jit. Randomness for the reparameterization trick usesnnx.Rngs.examples/vae/train_test.py(model forward/generate, metrics, train-step loss decrease, eval output shapes) and bumps the example'sflaxrequirement from 0.6.9 (which predatesnnx) to 0.9.0.Note:
examples/nnx_toy_examples/05_vae.pyis a separate minimal demo and is left untouched; this PR migrates the full training example inexamples/vaeas the issue asks.train_stepuses@nnx.jit, following the in-repo nnx examples (examples/mnist/train.py); happy to switch tojax.jitif preferred.Fixes #5068
Test evidence
examples/vae/train_test.py: 4 tests, all passing.train_and_evaluateon real binarized MNIST (2 epochs, batch 128, CPU): epoch 1 loss 119.81, epoch 2 loss 112.18 — decreasing and on trajectory for the README's ~104 after 10 epochs.ruff checkandruff format --checkclean on the changed files.Generated by AI tools, and reviewed by Ethan Sim.