How to dispatch to different instances of the same Module? #1146
Answered
by
marcvanzee
marcvanzee
asked this question in
Q&A
-
Q |
Beta Was this translation helpful? Give feedback.
Answered by
marcvanzee
Mar 17, 2021
Replies: 1 comment
-
Answer by @levskaya: Dynamically dispatching can have complicated performance behavior in the XLA setting (if you are rnning on TPU or GPU). class Foo(nn.Module):
@nn.compact
def __call__(self, x, idx):
denses = [nn.Dense(2) for i in range(3)]
ys = [denses[i](x) for i in range(3)]
return ys[idx] |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
marcvanzee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer by @levskaya:
Dynamically dispatching can have complicated performance behavior in the XLA setting (if you are rnning on TPU or GPU).
Why not just computing all results and indexing?