Skip to content

How to update dictionaries in Flax when getting "ValueError: FrozenDict is immutable."? #2061

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

You must be logged in to vote

Flax uses FrozenDict as the datatype for dictionary, which are immutable. You should first unfreeze them using flax.core.frozen_dict.unfreeze(d). So something like this:

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] = ...

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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