Skip to content

Compatibility between submodule declaration and @nn.compact #565

Answered by marcvanzee
rolandgvc asked this question in General
Discussion options

You must be logged in to vote

I think the problem here is not related to __setattr__. The problem is that in Model.__call__() you call self.conv_block(...), which constructs the Module ConvBlock (because partial inside Model.setup() does not create it yet). The __post_init__ call in ConvBlock will then check where in the parent (which is Model) the submodule was created, and realize this was outside of setup.

I don't think this is a bug, because you aren't allowed to create submodules in this way. However, I agree this error message is confusing. I am adding this example to the error messages in #1072 .

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@rolandgvc
Comment options

@rolandgvc
Comment options

Comment options

You must be logged in to vote
2 replies
@rolandgvc
Comment options

@avital
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by marcvanzee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants