zalandoresearch / pytorch-vq-vae

PyTorch implementation of VQ-VAE by Aäron van den Oord et al.
MIT License
534 stars 101 forks source link

Intentional weight sharing in ResidualStack? #2

Closed andreaskoepf closed 5 years ago

andreaskoepf commented 5 years ago

The list passed to nn.ModuleList in the ResidualStack class ctor in vae.ipynb#L324 duplicates a reference to a single Residual object instance. Was this done intentionally?

self._layers = nn.ModuleList(
[Residual(in_channels, num_hiddens, num_residual_hiddens)] * self._num_residual_layers)

To create a new objects for each layer the code might be changed to:

self._layers = nn.ModuleList([Residual(in_channels, num_hiddens, num_residual_hiddens)
                             for _ in range(self._num_residual_layers)])
kashif commented 5 years ago

@andreaskoepf thanks for your observation... I think its a bug... I will fix it!