BaseAlgo
BaseAlgorithm
Bases: BaseStateManager
, BaseCallbackHook
, BaseCallback
Base class for Trainer component. Handles all the engineering code. Connects the algorighm with callback and logging functionallities. The class also inherits from BaseCallback and the user can implement desired functionalities either as standalone callbacks or by overwriting the parent callback hooks of the algorithm.
Attributes:
Name | Type | Description |
---|---|---|
metric_callback_msg |
Optional[str]
|
A message set by the MetricCallback that informs about the progress of training/validation etc. Can be used by other callbacks, e.g., TqdmCallback, to display such information in the console. |
num_tasks |
int
|
number of tasks. Set by |
classes_per_task |
int
|
the number of classes per task. For the moment, all tasks should have the same number
of classes. Set by |
episodic_memory_loader |
torch.utils.data.DataLoader
|
The dataloader for the memory. Applies to methods that utilize memoreis, such as GEM. |
episodic_memory_iter |
Iterable[torch.utils.data.DataLoader]
|
An iterator for |
loss |
Union[torch.Tensor, numpy.array]
|
The loss of the current batch. |
current_dataloader |
torch.utils.data.DataLoader
|
The current training/validation/testing dataloader. |
x |
Union[torch.Tensor, numpy.array]
|
The input tensors of the current batch. Set by
|
y |
Union[torch.Tensor, numpy.array]
|
The targets of the current batch. Set by
|
t |
Union[torch.Tensor, numpy.array]
|
The task ids of the current batch. Set by
|
bs |
int
|
The size of the current batch. Set by |
epochs |
int
|
The epochs each task is trained for. |
Source code in sequel/algos/base_algo.py
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 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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|
__init__(backbone, benchmark, optimizer, callbacks=[], loggers=None, lr_decay=None, grad_clip=None, reinit_optimizer=True)
Inits the BaseAlgorithm class. Handles all the engineering code. Base classes for algorithms in Pytorch and Jax inherit from this class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone |
Union[PytorchBaseBackbone, JaxBaseBackbone]
|
The backbone model, e.g., a CNN. |
required |
benchmark |
Benchmark
|
The benchmark, e.g., SplitMNIST. |
required |
optimizer |
Union[torch.optim.Optimizer, optax.GradientTransformation]
|
The optimizer used to update the backbone weights. |
required |
callbacks |
Iterable[BaseCallback]
|
A list of callbacks. At least one instance of MetricCallback should be given. Defaults to []. |
[]
|
loggers |
Optional[Logger]
|
A list of logger, e.g. for Weights&Biases logging functionality. Defaults to None. |
None
|
lr_decay |
Optional[float]
|
A learning rate decay used for every new task. Defaults to None. |
None
|
reinit_optimizer |
bool
|
Indicates whether the optimizer state is reinitialized before fitting a new task. Defaults to True. |
True
|
Source code in sequel/algos/base_algo.py
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 |
|
check_and_parse_callbacks(callbacks)
Checks that the callbacks is a list containing exaclty one MetricCallback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
callbacks |
Iterable[BaseCallback]
|
list of callbacks |
required |
Returns:
Type | Description |
---|---|
Iterable[BaseCallback]
|
Iterable[BaseCallback]: the parsed list of callbacks. |
Source code in sequel/algos/base_algo.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
eval_epoch(*args, **kwargs)
Performs the evaluation of the model on the validation set. If no validation dataloader is provided, the method returns without any computation.
Source code in sequel/algos/base_algo.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
forward(*args, **kwargs)
Calls the forward function of the model.
Source code in sequel/algos/base_algo.py
160 161 162 |
|
parse_benchmark()
Extracts attributes from the benchmark and registers them to the algo for quick access.
Source code in sequel/algos/base_algo.py
114 115 116 117 118 |
|
test_step(*args, **kwargs)
Performs the testing step. Callbacks are offered for each step of the process.
Source code in sequel/algos/base_algo.py
214 215 216 |
|
train_algorithm_on_task(task)
Fits a single task.
Source code in sequel/algos/base_algo.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
training_epoch(*args, **kwargs)
Trains the model for a single epoch. Callbacks are offered for each method.
Source code in sequel/algos/base_algo.py
218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
training_step(*args, **kwargs)
The training step, i.e. training for each batch.
Goes through the usual hoops of zeroing out the optimizer, forwarding the input, computing the loss, backpropagating and updating the weights. For each different steps, callabacks are offered for maximum versatility and ease of use.
Source code in sequel/algos/base_algo.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
unpack_batch(batch)
Unpacks the batch and registers to the algorithm the current batch input, targets and task ids as self.x
,
self.y
and self.t
, respectively. It also registers the current batch size as self.bs
Source code in sequel/algos/base_algo.py
168 169 170 171 |
|
update_episodic_memory()
Updates the episodic memory. This funciton is called after fitting one task.
Source code in sequel/algos/base_algo.py
120 121 122 123 124 |
|
valid_step(*args, **kwargs)
Performs the validation step.Callbacks are offered for each step of the process.
Source code in sequel/algos/base_algo.py
210 211 212 |
|