Open townwish4git opened 1 month ago
I don't know if this will contribute to the discussion meaningfully but there is a method in ConfigMixin that allows changing of FrozenDict this way:
self.register_to_config(cross_attention_dim=256)
I don't know if this will contribute to the discussion meaningfully but there is a method in ConfigMixin that allows changing of FrozenDict this way:
self.register_to_config(cross_attention_dim=256)
Thanks a lot for resolving my confusion about 2&3. So it looks like self.config
should not be modified directly, but should be updated through the provided register_to_config
interface. Thanks again!
I am confused about the design of
FrozenDict
inconfiguration_utils.py
and the usage of it.1. Is
FrozenDict
really frozen?From the code,
FrozenDict
setsself.__frozen = True
during initialization. It then checksif hasattr(self, "__frozen") and self.__frozen
in methods like__setattr__
or__setitem__
to raise an exception if it's supposed to be frozen. However, in Python, using double underscores (__
) triggers name mangling, which meanshasattr(self, "__frozen")
couldn't find__frozen
as it is_FrozenDict__frozen
actually. This check would always return False, rendering the intended freeze ineffective ā__setattr__
and__setitem__
can still be used, making theFrozenDict
not truly frozen.Is this what we expect?
2. If we were to modify
FrozenDict
to be truly immutable, how would we use it asmodel.config
?Typically, we register parameters needed for model initialization as a
FrozenDict
viaregister_to_config
. These are often accessed during the forward method with checks likeif self.config.xxx == xxx
to determine execution paths. However, in some models, certain properties ofself.config
might need to be altered after initialization, as seen in IP-AdapterDoes this contradict the design philosophy of
FrozenDict
?3. If
models.config
could be mutable, how should one go about changing it?In the example above, should we use
__setattr__
to modifyself.config.encoder_hid_dim_type
or__setitem__
to add an additional key-value pair toFrozenDict
which appears more in line with typical dictionary usage, likeI was just wondering if you might have a moment to clarify these points for me?