Testing callbacks
MetadataSaveCallback
Bases: Callback
A callback that saves metadata about the current training at the second validation epoch.
Source code in bionemo/testing/testing_callbacks.py
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 135 136 137 138 139 140 141 142 |
|
__init__(metadata_path, metrics_getter)
Initialises callback with path and called information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata_path
|
Path
|
Path where the metadata will be saved. |
required |
metrics_getter
|
dict[str, Callable[[Trainer, LightningModule], Any]]
|
A dictionary of metadata keys and their corresponding functions. |
required |
See Also: bionemo.testing.stop_and_go
Source code in bionemo/testing/testing_callbacks.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
on_validation_epoch_end(trainer, pl_module)
Stores requisite metadata at the end of the first non-warmup validation epoch.
Executes on the second validation epoch -only- due to how warmups are handled. May not work as intended in the absence of a warmup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trainer
|
Trainer
|
The Lightning Trainer object. |
required |
pl_module
|
LightningModule
|
The LightningModule being trained. |
required |
Notes
- If
called
is True andtrainer.is_global_zero
is True, the function saves metadata to compare after resuming with a checkpoint. - The metadata is obtained using the
metrics_getter
dict and results are saved as a pickle file.
Source code in bionemo/testing/testing_callbacks.py
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 135 136 137 138 139 140 141 142 |
|
setup(trainer, pl_module, stage)
Set up the testing callbacks and removes lingering metadata.
Source code in bionemo/testing/testing_callbacks.py
104 105 106 107 108 |
|
RaiseAfterMetadataCallback
Bases: Callback
A callback that raises a StopAndGoException kills it if the metadata from the MetadataSaveCallback was saved successfully beforehand.
Use this callback for pytest based Stop and go tests.
Source code in bionemo/testing/testing_callbacks.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
on_train_batch_start(trainer, pl_module, batch, batch_idx)
PTL callback that raises a StopAndGoException if metadata exists.
Source code in bionemo/testing/testing_callbacks.py
76 77 78 79 80 81 |
|
TestCheckpointIntegrityCallback
Bases: Callback
Callback that tests if current metrics match those saved in the associated metadata file.
This callback expects to be invoked only after resuming a model that used the MetadataSaveCallback. When training begins, it checks the value of each metric and compares to the metadata stored in the metadata pickle file. Any deviances are assumed to be a failure in restoration.
Source code in bionemo/testing/testing_callbacks.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
__init__(metadata_path, metrics_getter)
Initialises callback with path and called information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata_path
|
Path
|
Path where the metadata will be saved. |
required |
metrics_getter
|
dict[str, Callable[[Trainer, LightningModule], Any]]
|
A dictionary of metadata keys and their corresponding functions. Must be a subset of the dictionary passed to MetadataSaveCallback. |
required |
Source code in bionemo/testing/testing_callbacks.py
151 152 153 154 155 156 157 158 159 160 161 |
|
on_train_start(trainer, pl_module)
Loads associated metadata and compares with current metrics.
Source code in bionemo/testing/testing_callbacks.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
compute_biobert_loss_singlegpu(model, dl)
Computes the loss for BioBert models on a single GPU.
This will not function in multi-gpu settings nor with models that do not conform to BioBert.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
The Biobert model. |
required |
dl
|
DataLoader
|
The data loader. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The mean loss. |
See Also: - :class: BioBertModel
Source code in bionemo/testing/testing_callbacks.py
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 |
|