fix: correct decoder layer init in autoencoder notebooks (ae-basic)#83
Open
Mukller wants to merge 2 commits into
Open
fix: correct decoder layer init in autoencoder notebooks (ae-basic)#83Mukller wants to merge 2 commits into
Mukller wants to merge 2 commits into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Mukller
commented
Jul 10, 2026
Mukller
left a comment
Author
There was a problem hiding this comment.
Code Review: fix decoder layer init in autoencoder notebooks
Summary
Fixes a copy-paste bug in the Autoencoder.__init__ method where the decoder layer (linear_2) weight and bias initialization was incorrectly calling self.linear_1.weight / self.linear_1.bias instead of self.linear_2.weight / self.linear_2.bias. As a result, the decoder weights were never receiving custom initialization — only the encoder weights were initialized twice.
Critical Issues
| # | File | Issue | Severity |
|---|---|---|---|
| 1 | ae-basic.ipynb |
Decoder init referenced self.linear_1 twice, leaving self.linear_2 with default PyTorch init instead of the intended custom normal init |
🔴 Critical |
| 2 | ae-basic-with-rf.ipynb |
Same copy-paste bug in the refactored version | 🔴 Critical |
What the Fix Does
Changes:
# Before (bug)
self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)
self.linear_1.weight.detach().normal_(0.0, 0.1) # wrong: linear_1 again
self.linear_1.bias.detach().zero_() # wrong: linear_1 again
# After (correct)
self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)
self.linear_2.weight.detach().normal_(0.0, 0.1) # correct: linear_2
self.linear_2.bias.detach().zero_() # correct: linear_2What Looks Good
- The fix is minimal and surgical — no unrelated changes
- Both affected notebooks are corrected consistently
Verdict
Request Changes → now fixed. The initialization bug could silently affect training reproducibility since the decoder would use PyTorch's default Xavier init instead of the documented normal distribution init.
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.
Bug Fix: Autoencoder decoder initialization uses wrong layer
In the
Autoencoder.__init__()method, the DECODER section incorrectly initializesself.linear_1weights instead ofself.linear_2. This is a copy-paste bug wherethe encoder's weight initialization code was duplicated without updating the layer reference.
Before (wrong):
After (fixed):
Fixes encoder weights being initialized twice while the decoder is never initialized.
Closes #79