Skip to content

Fix bug that could lead to duplicate params #783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

BenjaminBossan
Copy link
Collaborator

@BenjaminBossan BenjaminBossan commented Jun 20, 2021

When a net's module references another of that net's modules, the former
will yield the latter's parameters. Therefore, when all parameters are
collected, the latter's parameters appear twice.

This bugfix consists of remembering all yielded parameters in a set and
not yielding those that were already encountered.

This bug was introduced very recently (#751) and should occur very
rarely, since modules don't typically reference each other.

When a net's module references another of that net's modules, the former
will yield the latter's parameters. Therefore, when all parameters are
collected, the latter's parameters appear twice.

This bugfix consists of remembering all yielded parameters in a set and
not yielding those that were already encountered.

This bug was introduced very recently (751) and should occur very
rarely, since modules don't typically reference each other.
Comment on lines +762 to +763
# happen when a module references another module (e.g. the criterion
# references the module), thus yielding that module's parameters again.
Copy link
Member

Choose a reason for hiding this comment

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

This could be silly question: What is an example of a criterion with learnable parameters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not silly. One use case that has been discussed at some point is for GAN training with the generator being the module and the discriminator the criterion (though you might need different criteria in this case). Another case (which revealed this bug for me) is when using GPyTorch.
But this issue is not only relevant when the criterion references the module, it could also be one module referencing a second module.

@BenjaminBossan BenjaminBossan merged commit 906932c into master Jun 23, 2021
@BenjaminBossan BenjaminBossan deleted the bugfix/duplicate-params-when-modules-reference-each-other branch October 3, 2021 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants