Skip to content

fix: correct decoder layer init in autoencoder notebooks (ae-basic)#83

Open
Mukller wants to merge 2 commits into
rasbt:masterfrom
Mukller:fix/autoencoder-decoder-init
Open

fix: correct decoder layer init in autoencoder notebooks (ae-basic)#83
Mukller wants to merge 2 commits into
rasbt:masterfrom
Mukller:fix/autoencoder-decoder-init

Conversation

@Mukller

@Mukller Mukller commented Jul 9, 2026

Copy link
Copy Markdown

Bug Fix: Autoencoder decoder initialization uses wrong layer

In the Autoencoder.__init__() method, the DECODER section incorrectly initializes
self.linear_1 weights instead of self.linear_2. This is a copy-paste bug where
the encoder's weight initialization code was duplicated without updating the layer reference.

Before (wrong):

### DECODER
self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)
self.linear_1.weight.detach().normal_(0.0, 0.1)  # ❌ wrong layer
self.linear_1.bias.detach().zero_()               # ❌ wrong layer

After (fixed):

### DECODER
self.linear_2 = torch.nn.Linear(num_hidden_1, num_features)
self.linear_2.weight.detach().normal_(0.0, 0.1)  # ✓ correct
self.linear_2.bias.detach().zero_()               # ✓ correct

Fixes encoder weights being initialized twice while the decoder is never initialized.
Closes #79

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@Mukller Mukller left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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_2

What 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.

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.

Encoder weights initialized twice, decoder weights not initialized

1 participant