torch_callbacks
DenovoDesign
Bases: TorchCallback
A callback for de novo design that designs SMILES strings in the end of every epoch.
Source code in s4dd/torch_callbacks.py
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
__init__(design_fn, basedir, temperatures)
Creates a DenovoDesign
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
design_fn |
Callable[[float], List[str]]
|
A function that takes a temperature and returns a list of SMILES strings. |
required |
basedir |
str
|
The base directory to save the generated molecules to. |
required |
temperatures |
List[float]
|
A list of temperatures to use for sampling. |
required |
Source code in s4dd/torch_callbacks.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
on_epoch_end(epoch_ix, **kwargs)
Designs and saves molecules in the end of every epoch with their log-likelihoods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch_ix |
int
|
The index of the epoch that just ended. |
required |
Source code in s4dd/torch_callbacks.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
EarlyStopping
Bases: TorchCallback
A callback that stops training when a monitored metric has stopped improving.
Source code in s4dd/torch_callbacks.py
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
__init__(patience, delta, criterion, mode)
Creates an EarlyStopping
callback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
patience |
int
|
Number of epochs to wait for improvement before stopping the training. |
required |
delta |
float
|
Minimum change in the monitored quantity to qualify as an improvement. |
required |
criterion |
str
|
The name of the metric to monitor. |
required |
mode |
str
|
One of |
required |
Source code in s4dd/torch_callbacks.py
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 |
|
on_epoch_end(epoch_ix, history, **kwargs)
Called at the end of an epoch. Updates the best metric value and the number of epochs waited for improvement.
stop_training
attribute is set to True
if the training should be stopped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch_ix |
int
|
The index of the epoch that just ended. |
required |
history |
Dict[str, float]
|
A dictionary containing the training history. The keys are the names of the metrics, and the values are lists of the metric values at each epoch. |
required |
Source code in s4dd/torch_callbacks.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
HistoryLogger
Bases: TorchCallback
A callback that saves the training history in the end of every epoch.
Source code in s4dd/torch_callbacks.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
__init__(savedir)
Creates a HistoryLogger
instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
savedir |
str
|
The directory to save the training history to. |
required |
Source code in s4dd/torch_callbacks.py
220 221 222 223 224 225 226 227 228 229 230 |
|
on_epoch_end(history, **kwargs)
Saves the training history in the end of every epoch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
history |
Dict[str, List[float]]
|
A dictionary containing the training history. The keys are the names of the metrics ( |
required |
Source code in s4dd/torch_callbacks.py
232 233 234 235 236 237 238 239 240 241 242 |
|
ModelCheckpoint
Bases: TorchCallback
A callback that saves the model in the end of every epoch.
Source code in s4dd/torch_callbacks.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
__init__(save_fn, save_per_epoch, basedir)
Creates a ModelCheckpoint
instance that runs per a fixed number of epoch and at the end of training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_fn |
Callable[[str], None]
|
A function that takes a directory and saves the model to that directory. |
required |
save_per_epoch |
int
|
The number of epochs to wait between saves. |
required |
basedir |
str
|
The base directory to save the model to. |
required |
Source code in s4dd/torch_callbacks.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
on_epoch_end(epoch_ix, **kwargs)
Saves the model in the end of every epoch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch_ix |
int
|
The index of the epoch that just ended. |
required |
Source code in s4dd/torch_callbacks.py
193 194 195 196 197 198 199 200 201 202 203 204 |
|
on_train_end(epoch_ix, **kwargs)
Saves the model in the end of training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch_ix |
int
|
The index of the epoch that just ended. |
required |
Source code in s4dd/torch_callbacks.py
206 207 208 209 210 211 212 213 214 |
|
TorchCallback
Bases: ABC
Base class for all Torch callbacks.
Source code in s4dd/torch_callbacks.py
11 12 13 14 15 16 17 18 19 20 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 |
|
__init__()
Creates a TorchCallback. Sets the stop_training
flag to False
, which would be common attribute of all callbacks.
Source code in s4dd/torch_callbacks.py
14 15 16 17 |
|
on_epoch_end(epoch_ix, history, **kwargs)
Called at the end of an epoch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch_ix |
int
|
The index of the epoch that just ended. |
required |
history |
Dict[str, List[float]]
|
A dictionary containing the training history. The keys are the names of the metrics, and the values are lists of the metric values at each epoch. |
required |
**kwargs |
Any additional keyword arguments. |
{}
|
Source code in s4dd/torch_callbacks.py
19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
on_train_end(epoch_ix, history, **kwargs)
Called at the end of training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch_ix |
int
|
The index of the epoch that just ended. |
required |
history |
Dict[str, List[float]]
|
A dictionary containing the training history. The keys are the names of the metrics, and the values are lists of the metric values at each epoch. |
required |
**kwargs |
Any additional keyword arguments. |
{}
|
Source code in s4dd/torch_callbacks.py
33 34 35 36 37 38 39 40 41 42 43 44 45 |
|