Skip to content

Issue definig subModules on super() #3476

Answered by chiamp
alonfnt asked this question in Q&A
Discussion options

You must be logged in to vote

Net2(n=10).init(key, x1_dummy, method='inner') is looking for a method called inner, which isn't defined. You could try something like this:

class Net2(nn.Module):
    n: int

    def setup(self):
        self.inner = Net1(self.n)
        self.outer = Net1(self.n*2)

    def inner_call(self, x):
        return self.inner(x)
    
    def outer_call(self, x):
        return self.outer(x)

...

inner_params = Net2(n=10).init(key, x1_dummy, method='inner_call')

Replies: 1 comment

Comment options

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