Experiment
File: experiment.py
Provides the main module of the package: Experiment.
Experiment
Bases: ABC
Base experiment superclass. All other experiments should inherit from this class. Each sub-experiment must provide an implementation of the "evaluate" abstract method. A sub-experiment has full autonomy to override the basic components such as the training loop "train".
Source code in torchplate/experiment.py
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 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 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 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 143 144 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 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 215 216 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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
__init__(model, optimizer, trainloader, save_weights_every_n_epochs=None, wandb_logger=None, verbose=True, experiment_name=misc.timestamp())
Experiment superclass initializer. Each subclass must provide a model, optimizer, and trainloader at the very least. Arguments:
- model: torch nn.module
- optimizer: torch optimizer
- trainloader: torch Dataloader to be used for training Optional:
- save_weights_every_n_epochs: how often to save the model weight automatically. Default: None. Specify None if you don't want to save weights automatically.
- wandb_logger (wandb.init object): pass in if you want to log to wandb. Default: None.
- verbose (boolean): if true, print out metrics during training. Default: True.
- experiment_name (str): name of the experiment for saving. Default: timestamp.
Source code in torchplate/experiment.py
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 |
|
evaluate(batch)
abstractmethod
Abstract method which the user must provide. Implement the forward pass and return the loss value.
- batch: a batch from the train data loader (i.e., an (x, y) pair). To be used as input into the model.
- A scalar loss value.
Source code in torchplate/experiment.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
load_weights(weight_path)
Function to load model weights saved at 'weight_path'.
- weight_path: path pointing to the saved weights.
Source code in torchplate/experiment.py
255 256 257 258 259 260 261 262 |
|
on_batch_end()
Callback that can be overriden. Implement whatever you want to happen after each batch iteration.
Source code in torchplate/experiment.py
201 202 203 204 205 206 |
|
on_batch_start()
Callback that can be overriden. Implement whatever you want to happen before each batch iteration.
Source code in torchplate/experiment.py
193 194 195 196 197 198 |
|
on_epoch_end()
Callback that can be overriden. Implement whatever you want to happen after each epoch iteration.
Source code in torchplate/experiment.py
217 218 219 220 221 222 |
|
on_epoch_start()
Callback that can be overriden. Implement whatever you want to happen before each epoch iteration.
Source code in torchplate/experiment.py
209 210 211 212 213 214 |
|
on_run_end()
Callback that can be overriden. Implement whatever you want to happen after each run.
Source code in torchplate/experiment.py
233 234 235 236 237 238 |
|
on_run_start()
Callback that can be overriden. Implement whatever you want to happen before each run.
Source code in torchplate/experiment.py
225 226 227 228 229 230 |
|
save_weights(save_path=None)
Function to save model weights at 'save_path'.
- save_path: path to save the weights. If not given, defaults to current timestamp.
Source code in torchplate/experiment.py
241 242 243 244 245 246 247 248 249 250 251 252 |
|
train(num_epochs, gradient_accumulate_every_n_batches=1, display_batch_loss=False)
Training loop. Can optionally specify how often to accumulate gradients. Default: 1.
Source code in torchplate/experiment.py
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 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 143 144 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 |
|