Training
iris.training
Implements the training and testing setups for a Reverter.
The primary function of this module is train_reverter, which
implements a robust training setup. In addition to the training setup, this module provides a
test function that mirrors all features of the training function.
PhysicalLoss
Bases: Module
The abstract base class for a physical loss function to be used in
Reverter training.
Takes a batch of predicted top-down density images
and corresponding true top-down density images and computes a scalar comparison metric to
minimize during Reverter training.
Attributes:
| Name | Type | Description |
|---|---|---|
normalization |
Parameter
|
The normalization constant, in units of density, to be applied to true and
predicted densities. Is set as the conversion of
|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyper
|
Hyper
|
A hyperparameters object. |
required |
Source code in iris/training.py
forward(pred, true)
The abstract signature of the forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Tensor
|
The predicted top-down density image. |
required |
true
|
Tensor
|
The true top-down density image. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The scalar loss metric. |
Source code in iris/training.py
normed_residual(pred, true)
Computes a unitless residual by normalizing by the density units constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Tensor
|
The predicted top-down density image. |
required |
true
|
Tensor
|
The true top-down density image. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The units-normalized residual. |
Source code in iris/training.py
ScaledDensityLoss
Bases: PhysicalLoss
The specific PhysicalLoss used in the IRIS paper.
Source code in iris/training.py
forward(pred, true)
Injects an arc-hyperbolic-sine nonlinearity inside a units-normalized
mean square error. Experiments conducted for the IRIS paper indicated that
nonlinearizing the loss function was essential to enabling effective Reverter
training by expanding the dynamic range of the prediction space in the target
regime and enabling the training process to better "see" inaccuracies in the
model predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Tensor
|
The predicted top-down density image. |
required |
true
|
Tensor
|
The true top-down density image. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The scalar loss metric. |
Source code in iris/training.py
train_reverter(reverter, dataset, noise=None, litter=None, observer=None, hyper=None, checkpoint_directory=None, checkpoint_name=None, auto_startup=True, auto_cleanup=True)
Implements the training setup for a Reverter.
The training setup is a simple supervised training scheme. A pair of an input
observation and output [top-down density image] make up the ground
truth the neural network is trained to reproduce. At training time, a batch of observations
is fed into the network, which produces a corresponding batch of top-down predictions. A
physical loss function compares the predicted images to the true
top-down images, yielding a loss reduced loss on which a backwards pass is executed. The
Reverter parameters are stepped based on the gradient of this physical loss. Because the
predictions exist in a space imbued with physical units of density, the loss function must
contain a units normalization in order to be units-invariant, so that loss scores can be compared
between datasets with differing units. See PhysicalLoss for
details on specifying a physical loss function.
This setup is designed to operate with both preobserved
and standard datasets, although it is recommended that
only preobserved datasets be used for Reverter training, as they reduce disk usage and load
latency by orders of magnitude and eliminate redundant observation at runtime, which introduces
a large computational overhead. The setup is also configured to enable an optional addition of
noise and litter. Noise is a random observational defect added to the input observations by
a Noise object, in order to innoculate the Reverter to noise
expected in the true observations on which it will be applied.
Litter is a separate data augmentation that addresses the other source of confounding information
in a true observation--foreground and background features that do not reflect actual structures
in the CMZ itself. If full-cone observations are used in constructing the training dataset, then
foreground and background features will naturally be present. Full-cone observations, however,
require orders of magnitude more time and memory to compute than observations of a small, central
cutout of the CMZ region, and so were not found to be pragmatic for constructing a training dataset
in the IRIS paper. Instead, litter allows a separate dataset of only foreground/background features
that are added to the Reverter inputs randomly during training. This also introduces an additional
source of regularization, since the litter is applied randomly as opposed to being matched with
specific observations via a fixed one-to-one pairing.
Of course, the use of litter assumes the task of the Reverter regarding foreground and background
features is merely to learn to ignore them, i.e. that there is no useful information that can be
extracted from them regarding the CMZ structure, which may not be precisely true in theory.
Litter must be constructed as an InfiniteDataset,
which can be accomplished by a Reader. Like the training dataset,
litter may be sourced from either a PreObservedDataset
or a StandardDataset, but it is recommended that only
a PreObservedDataset be used, for optimal performance.
This training setup is also designed to enable a fully distributed, multi-node, multi-GPU,
data parallel configuration. A scalable set of CPU workers load datapoints from the disk
while a single manager process per GPU asynchronously manages the training process. Model gradients
are automatically synced across GPUs via torch.nn.parallel.DistributedDataParallel. This provides
infinitely scalable batch sizes. In practice, however, the IRIS paper found that small batches
provide a critical source of regularization. Moreover, the primary training bottleneck was found to
be the latency in loading a training point from the disk into memory--in particular, because the
IRIS paper performed training on a large dataset stored on a locally networked drive in an HPC
environment. The GPU latency of the forward and backward passes and step computations was found to be
small. Instead, it was found that the best practical setup involved training on a single GPU with a large
number of CPU workers for asynchronous data loading. See the IRIS paper for more details and discussion
(subsec: Implementation of Reversion: Training Hyperparameters, Overfitting, and Regularization).
All training hyperparameters are specified in the training_hyper
of a hyperparameters object. These include:
validation_data_fraction: How much of the training data is segregated for validation.epochs: How many epochs to train for.batch_size: The batch size. Specified per-GPU, i.e. ifbatch_size=8and training on two GPUs, the actual batch size is 16.batches_per_update: How many batches over which to accumulate gradients before computing an optimizer step.physical_loss: Type of the specificPhysicalLossto be instantiated and used during training.density_normalization: The units normalization to be applied to the true and predicted densities in computing a units-invariant physical loss.optimizer: A callable that accepts theReverterparameters and returns a tupleoptimizer, schedulerof atorch.optim.optimizer.Optimizer, andtorch.optim.lr_scheduler.LRSchedulerinitialized on these parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reverter
|
Reverter
|
The reverter to be trained. |
required |
dataset
|
Dataset | ConcatDataset
|
A dataset on which to train the reverter. |
required |
noise
|
Noise | None
|
An object that adds random noise to each input observation. |
None
|
litter
|
InfiniteDataset | None
|
A dataset of foreground/background features to be added randomly to observations during training. |
None
|
observer
|
Observer | None
|
An observer with which to generate observations of
physical tensors, if training with a
|
None
|
hyper
|
Hyper | None
|
A hyperparameters object. |
None
|
checkpoint_directory
|
str | None
|
If not |
None
|
checkpoint_name
|
str | None
|
The subdirectory name in which to save model checkpoints. Must be specified
if |
None
|
auto_startup
|
bool
|
If |
True
|
auto_cleanup
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
Module
|
A tuple |
int
|
and the integer rank of the current process in the |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If one but not both of |
Source code in iris/training.py
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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
test_reverter(reverter, dataset, noise=None, litter=None, observer=None, hyper=None, auto_startup=True, auto_cleanup=True)
Tests Reverter performance over a dataset.
Mirrors all configurations and functionalities of train_reverter
other than model training. Instead, the Reverter is tested over a single epoch over the
entire dataset. No gradients or parameter steps are computed and the model is called in eval
mode in order to record physical loss scores, as in validation. See
train_reverter for all details regarding physical losses,
hyperparameters, and the multi-node, multi-GPU distributed setup.
The specific hyperparameters in TrainingHyper that still apply
during Reverter testing are:
batch_size: The batch size. Specified per-GPU, i.e. ifbatch_size=8and training on two GPUs, the actual batch size is 16.physical_loss: Type of the specificPhysicalLossto be instantiated and used during testing.density_normalization: The units normalization to be applied to the true and predicted densities in computing a units-invariant physical loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reverter
|
Reverter
|
The reverter to be trained. |
required |
dataset
|
Dataset | ConcatDataset
|
A dataset on which to test the reverter. |
required |
noise
|
Noise | None
|
An object that adds random noise to each input observation. |
None
|
litter
|
InfiniteDataset | None
|
A dataset of foreground/background features to be added randomly to observations during testing. |
None
|
observer
|
Observer | None
|
An observer with which to generate observations of
physical tensors, if testing with a
|
None
|
hyper
|
Hyper | None
|
A hyperparameters object. |
None
|
auto_startup
|
bool
|
If |
True
|
auto_cleanup
|
bool
|
If |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
Source code in iris/training.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |