Fix VAE sampling: enable reparameterization by default, return mu for inference#62
Draft
Copilot wants to merge 4 commits into
Draft
Fix VAE sampling: enable reparameterization by default, return mu for inference#62Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
… inference Agent-Logs-Url: https://github.com/ohsu-comp-bio/embedding-kit/sessions/0b5866f0-ed9a-412e-9be8-afccd0368e05 Co-authored-by: kellrott <113868+kellrott@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix sampling behavior in VAE training process
Fix VAE sampling: enable reparameterization by default, return mu for inference
May 5, 2026
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
kbcoulter
reviewed
May 11, 2026
There was a problem hiding this comment.
I didn't see this on the coverage report, but the tests themselves are working.
kbcoulter
reviewed
May 11, 2026
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.
Encoderdefaulted tosampling=False, causing the encoder to return the raw hidden statehaszinstead of the reparameterized sample — making every VAE a plain autoencoder silently.Root cause
forward()returned(mu, logvar, h)whensampling=False(wrong:h≠mu). Thebuild_encoderfactory never passedsampling=True. Result: KL loss computed againstmu/logvarbut decoder receivedh.Changes
encoder.py: Defaultsampling=True. Whensampling=False, return(mu, logvar, mu)— the third element is now always the correct decode input (reparameterizedzor deterministicmu).base_vae.py:build_encoder()accepts and forwardssampling=True.encode()returnsmufor stable deterministic embeddings.SimpleEncoderlikewise returnsmu.vae.py:VAE.__init__exposessampling: bool = True, passed through tobuild_encoder. Serialized into_dict/from_dict.commands/model.py: Added--sampling/--no-samplingflag totrain-vae(defaultTrue).encodecommand now usesresult[0](mu) instead ofresult[2]for inference output.Tests
Four new tests in
test_encoder.pycover: sampling enabled produces stochasticz, disabled givesz == mu, default isTrue, andforward()always returns a 3-tuple.