Skip to content

How to assign methods as Flax Module attributes? #995

Answered by marcvanzee
marcvanzee asked this question in Q&A
Discussion options

You must be logged in to vote

Answer by @hexahedria:

Dataclass actually reads the type annotation, so the code below works fine (even with Any), but fails without any type annotation.

class Foo(nn.Module):
  go : Callable = somefunc

So moral of the story, put type annotations for the things you want to be dataclass attributes

Replies: 1 comment 1 reply

Comment options

marcvanzee
Feb 5, 2021
Maintainer Author

You must be logged in to vote
1 reply
@marcvanzee
Comment options

marcvanzee Feb 5, 2021
Maintainer Author

Answer selected by marcvanzee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant