Use FieldReference and placeholders for shared values
masterA FieldReference allows multiple fields to point to the same underlying value. If the value of the reference changes, all fields pointing to it will reflect the change.
placeholder(type): A shortcut to create aFieldReferencewith aNonedefault value and a specific type constraint.- Indirection Note: If you assign a
FieldReferenceto another field via standard assignment (e.g.,cfg.field2 = cfg.field1), the indirection is lost and it becomes a standard value field. To maintain the link, ensure you are working with the reference object itself.
To change the value of a FieldReference, use .set(value). To retrieve the actual value, use .get().
from ml_collections import config_dict
placeholder = config_dict.FieldReference(0)
cfg = config_dict.ConfigDict()
cfg.placeholder = placeholder
cfg.optional = config_dict.placeholder(int)
cfg.optional = 1555
cfg.placeholder = 1 # Changes the value for all fields tied to this placeholder