How to update dictionaries in Flax when getting "ValueError: FrozenDict is immutable."? #2061
Answered
by
marcvanzee
marcvanzee
asked this question in
Q&A
-
Original question from an internal user: "Hello all, just checking if there is any best practice with passing and then updating dictionaries in a Flax module? I currently face a |
Beta Was this translation helpful? Give feedback.
Answered by
marcvanzee
Apr 21, 2022
Replies: 1 comment
-
Flax uses from flax.core.frozen_dict import unfreeze
variables = module.init(random.PRNGKey(0), ...)
# variables is now of type FrozenDict, first unfreeze it to modify it.
variables = unfreeze(variables)
# now they can be modified
variables[key] = ... |
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
Flax uses
FrozenDict
as the datatype for dictionary, which are immutable. You should first unfreeze them usingflax.core.frozen_dict.unfreeze(d)
. So something like this: