Iomixin utils
IOMixinWithGettersSetters
Bases: WillHaveGetSetHparam
, IOMixin
An implementation of WillHaveGetSetHparam which makes use of the io.IOMixin.io added to your classes.
This enables you to mutate the hyper-parameters of your classes which will later be saved in configs.
Source code in bionemo/llm/utils/iomixin_utils.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
get_hparam(attribute)
Looks up the saved hyper-parameter for the io mixed class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
The element name to look up within the saved init settings for self |
required |
Returns: Value Raises: KeyError if the attribute does not exist in the saved init settings.
Source code in bionemo/llm/utils/iomixin_utils.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
get_hparams()
Returns the hyper-parameters of init in a dictionary format.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary of the init hyper-parameters on this object. |
Source code in bionemo/llm/utils/iomixin_utils.py
128 129 130 131 132 133 134 |
|
get_non_default_hparams()
Returns a list of hyper-parameters that have been changed from their default values.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of hyper-parameters that have been changed from their default values. |
Source code in bionemo/llm/utils/iomixin_utils.py
120 121 122 123 124 125 126 |
|
set_hparam(attribute, value, also_change_value=True)
Mutates the saved hyper-parameter for the io mixed class.
If you would like to only change the saved hyper-param
for example in the case of loading a dataclass where the same variables are mutated to other non-savable
entities by deterministic rules after init, then use also_change_value=False
to only update the
hyper-parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
The element name to modify within the saved init settings for self |
required |
value
|
Any
|
New parameter for the saved init settings |
required |
also_change_value
|
bool
|
If you also want to mutate the attribute of this same name in self to be the desired value, set this to True, otherwise if the init arg and self arg are expected to be divergent, then do not set this and modify the self attribute separately in the normal pythonic way. |
True
|
Returns:
Type | Description |
---|---|
None
|
None. |
Source code in bionemo/llm/utils/iomixin_utils.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
WillHaveGetSetHparam
Bases: ABC
An ABC that states that a particular class will have our mutatable IO Mixin variant added to it.
This is a placeholder until a similar piece of functionality is added in NeMo.
Raises:
Type | Description |
---|---|
NotImplementedError
|
You must implement set_hparam, get_hparam, and get_hparams |
Source code in bionemo/llm/utils/iomixin_utils.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
get_hparam(attribute)
abstractmethod
Looks up the saved hyper-parameter for the io mixed class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
The element name to look up within the saved init settings for self |
required |
Returns: Value Raises: KeyError if the attribute does not exist in the saved init settings.
Source code in bionemo/llm/utils/iomixin_utils.py
52 53 54 55 56 57 58 59 60 61 62 63 |
|
get_hparams()
abstractmethod
Returns the hyper-parameters of init in a dictionary format.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary of the init hyper-parameters on this object. |
Source code in bionemo/llm/utils/iomixin_utils.py
65 66 67 68 69 70 71 72 |
|
set_hparam(attribute, value, also_change_value=True)
abstractmethod
Mutates the saved hyper-parameter for the io mixed class.
If you would like to only change the saved hyper-param
for example in the case of loading a dataclass where the same variables are mutated to other non-savable
entities by deterministic rules after init, then use also_change_value=False
to only update the
hyper-parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
The element name to modify within the saved init settings for self |
required |
value
|
Any
|
New parameter for the saved init settings |
required |
also_change_value
|
bool
|
If you also want to mutate the attribute of this same name in self to be the desired value, set this to True, otherwise if the init arg and self arg are expected to be divergent, then do not set this and modify the self attribute separately in the normal pythonic way. |
True
|
Returns:
Type | Description |
---|---|
None
|
None. |
Source code in bionemo/llm/utils/iomixin_utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|