Transparent Sub-Module Scope #3282
Unanswered
joeryjoery
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I want to write a Module
B
that depends on an arbitrary sub-module treeA
, but I don't want to the top-level of the sub-modulesA
to be included in the"params"
container. Is this possible in Flax?In other words, I would like to have control over the parameter scope to prevent unnecesary nesting. Unfortunately, I couldn't understand how to do this with
pack
/lift
based on the docs.I want to use this for writing module compositions, e.g., for writing loss functions for neural networks, without having to worry about variable or rng management.
To illustrate what I want to achieve:
The reason why I desire the second param-container, without the
'a'
scope, is that I want to initialize fromA
and be able to use the same parameter container inB
:Workaround Pattern
I was able to get around my problem by passing custom methods inside the
apply
function ofmyA
:Or with dataclasses,
I'm not sure if these patterns are ideal, the former uses a method
dummy
that does not belong toA
and the latter breaks consistency with the Module interface.Ideally, I could implement a
Loss
Module dependent onA
where the callmyLoss.apply(vars_from_A, ...)
just works, does anyone know how to achieve this?Beta Was this translation helpful? Give feedback.
All reactions