Train¶
hypertorch.train
¶
LaTexTableConfig
¶
Bases: TypedDict
Configuration for the LaTex table logger.
Attributes:
| Name | Type | Description |
|---|---|---|
table_caption |
NotRequired[str]
|
Caption for the LaTex table. |
sort_by |
NotRequired[list[str]]
|
Per-column sorting criteria ("asc" or "des"). |
border |
NotRequired[bool]
|
Whether to include borders in the LaTex table. |
Source code in hypertorch/train/latex_logger.py
LaTexTableLogger
¶
Bases: Logger
A Lightning Logger that accumulates metrics and writes a LaTex comparison table.
Multiple instances (one per model) share a class-level store keyed by experiment_name. Every time finalize() is called (after fit() or test() for each model), the current state of all accumulated metrics is written to a LaTex file. The last model to finalize produces the most complete table.
This means the file is progressively updated as models finish training/testing, so you can open it mid-run to see partial results.
Source code in hypertorch/train/latex_logger.py
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 386 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 | |
name
property
¶
Return the logger name.
Returns:
| Name | Type | Description |
|---|---|---|
name |
str
|
Logger name. |
version
property
¶
Return the logger version.
Returns:
| Name | Type | Description |
|---|---|---|
version |
str | int
|
Model name used as the logger version. |
store
property
¶
Access the shared store for the current experiment.
save_dir
property
¶
Return the logger save directory.
Returns:
| Name | Type | Description |
|---|---|---|
save_dir |
str | Path
|
Base directory for comparison files. |
experiment_name
property
¶
Return the experiment name.
Returns:
| Name | Type | Description |
|---|---|---|
experiment_name |
str | Path
|
Shared experiment key. |
__init__(save_dir, model_name, experiment_name, precision=4, options=None)
¶
Initialize the LaTex table logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_dir
|
str | Path
|
Base directory where comparison files are written. |
required |
model_name
|
str
|
Full model name to use as the table row label. |
required |
experiment_name
|
str
|
Shared key grouping models in the same experiment. |
required |
precision
|
int
|
Decimal places for metric values. |
4
|
options
|
LaTexTableConfig | None
|
Optional table rendering configuration. Defaults to an empty dict configuration, if not provided. |
None
|
Source code in hypertorch/train/latex_logger.py
clear(experiment_name)
¶
Remove accumulated data for an experiment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_name
|
str
|
The experiment name whose data should be cleared. |
required |
log_hyperparams(params)
¶
Accept hyperparameter logging calls from Lightning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Any
|
Hyperparameters provided by Lightning, unused. |
required |
log_metrics(metrics, step=None)
¶
Accumulate metrics for this model. Called by Lightning on every log step.
Keeps only the latest value for each metric name. For example, if "val_auc" is logged at step 10 and step 20, only the step 20 value is kept.
Source code in hypertorch/train/latex_logger.py
finalize(status)
¶
Write the LaTex comparison table with all accumulated metrics so far.
Called by Lightning after fit() and after test() for each model. Since models train/test sequentially, each finalize() overwrites the file with all data accumulated up to that point. The file grows more complete over time.
Source code in hypertorch/train/latex_logger.py
__build_comparison_table(sections_data, precision=4, table_caption=None, sort_by=None, border=True)
¶
Build a LaTex comparison table from grouped result sections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sections_data
|
list[tuple[str, Mapping[str, Mapping[str, Any]]]]
|
Section titles and per-model metric mappings. |
required |
precision
|
int
|
Decimal places for metric values. Defaults to |
4
|
table_caption
|
str | None
|
Optional table caption. Defaults to |
None
|
sort_by
|
list[str] | None
|
Optional per-metric sort directions. Defaults to |
None
|
border
|
bool
|
Whether to use bordered table rules. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
table |
str
|
LaTex table content. |
Source code in hypertorch/train/latex_logger.py
__get_section_lines(title, results, total_cols, precision, sort_by, border)
¶
Build LaTex table rows for a result section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Section title. |
required |
results
|
Mapping[str, Mapping[str, Any]]
|
Mapping from model names to metric dictionaries. |
required |
total_cols
|
int
|
Total number of columns in the shared table. |
required |
precision
|
int
|
Decimal places for metric values. |
required |
sort_by
|
list[str] | None
|
Optional per-metric sort directions. |
required |
border
|
bool
|
Whether to use bordered table rules. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lines |
list[str]
|
LaTex rows for the section. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any sort direction is unsupported. |
Source code in hypertorch/train/latex_logger.py
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 386 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 | |
__save_comparison_tables(test_results, save_dir, train_results=None, val_results=None, filename='overall.tex', precision=4, table_caption=None, sort_by=None, border=True)
¶
Build and save LaTex comparison tables to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_results
|
Mapping[str, Mapping[str, Any]]
|
Mapping from model names to test metrics. |
required |
save_dir
|
str | Path
|
Directory where the LaTex file will be written. |
required |
train_results
|
Mapping[str, Mapping[str, Any]] | None
|
Optional mapping from model names to train metrics.
Defaults to |
None
|
val_results
|
Mapping[str, Mapping[str, Any]] | None
|
Optional mapping from model names to validation metrics.
Defaults to |
None
|
filename
|
str
|
Name of the output file. Defaults to |
'overall.tex'
|
precision
|
int
|
Decimal places for metric values. Defaults to |
4
|
table_caption
|
str | None
|
Optional table caption. Defaults to |
None
|
sort_by
|
list[str] | None
|
Optional per-metric sort directions. Defaults to |
None
|
border
|
bool
|
Whether to use bordered table rules. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
path |
Path
|
Path to the written file. |
Source code in hypertorch/train/latex_logger.py
__split_results()
¶
Split all accumulated metrics into test vs train/val groups.
Metrics are classified by their name prefix: - "test/" -> test_results - "train/" -> train_results - "val/*" -> val_results - anything else (e.g., "epoch") -> ignored
Source code in hypertorch/train/latex_logger.py
MarkdownTableLogger
¶
Bases: Logger
A Lightning Logger that accumulates metrics and writes a markdown comparison table.
Multiple instances (one per model) share a class-level store keyed by experiment_name.
Every time finalize() is called (after fit() or test() for each model), the current
state of all accumulated metrics is written to a markdown file. The last model to
finalize produces the most complete table.
This means the file is progressively updated as models finish training/testing, so partial results are available while running.
Source code in hypertorch/train/markdown_logger.py
10 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 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 | |
name
property
¶
Return the logger name.
Returns:
| Name | Type | Description |
|---|---|---|
name |
str
|
Logger name. |
version
property
¶
Return the logger version.
Returns:
| Name | Type | Description |
|---|---|---|
version |
str | int
|
Model name used as the logger version. |
store
property
¶
Access the shared store for the current experiment.
save_dir
property
¶
Return the logger save directory.
Returns:
| Name | Type | Description |
|---|---|---|
save_dir |
str | Path
|
Base directory for comparison files. |
experiment_name
property
¶
Return the experiment name.
Returns:
| Name | Type | Description |
|---|---|---|
experiment_name |
str | Path
|
Shared experiment key. |
__init__(save_dir, model_name, experiment_name, precision=4)
¶
Initialize the markdown table logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_dir
|
str | Path
|
Base directory where comparison files are written. |
required |
model_name
|
str
|
Full model name to use as the table row label. |
required |
experiment_name
|
str
|
Shared key grouping models in the same experiment. |
required |
precision
|
int
|
Decimal places for metric values. Default is |
4
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in hypertorch/train/markdown_logger.py
clear(experiment_name)
¶
Remove accumulated data for an experiment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_name
|
str
|
The experiment name whose data should be cleared. |
required |
Source code in hypertorch/train/markdown_logger.py
log_hyperparams(params)
¶
Accept hyperparameter logging calls from Lightning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Any
|
Hyperparameters provided by Lightning, unused. |
required |
log_metrics(metrics, step=None)
¶
Accumulate metrics for this model. Called by Lightning on every log step.
Keeps only the latest value for each metric name. For example, if "val_auc" is logged at step 10 and step 20, only the step 20 value is kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
dict[str, float]
|
Dictionary of metric names to values. |
required |
step
|
int | None
|
Optional step number, unused. Defaults to |
None
|
Source code in hypertorch/train/markdown_logger.py
finalize(status)
¶
Write the markdown comparison table with all accumulated metrics so far.
Called by Lightning after fit() and after test() for each model. Since models train/test sequentially, each finalize() overwrites the file with all data accumulated up to that point. The file grows more complete over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
The stage that just completed, unused. For example, "fit" or "test". |
required |
Source code in hypertorch/train/markdown_logger.py
__build_comparison_table(results, precision=4)
¶
Build a markdown comparison table from model results.
Examples:
Input:
Output:
| Model | test_auc | test_loss |
| --- | --- | --- |
| gat:default | 0.8200 | - |
| mlp:mean | 0.8500 | 0.3200 |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Mapping[str, Mapping[str, float]]
|
Mapping of model names to metric dictionaries. |
required |
precision
|
int
|
Number of decimal places for numeric metric values.
Defaults to |
4
|
Returns:
| Name | Type | Description |
|---|---|---|
table |
str
|
Markdown table string. Returns an empty string if |
Source code in hypertorch/train/markdown_logger.py
__save_comparison_tables(test_results, save_dir, train_results=None, val_results=None, filename='results.md', precision=4)
¶
Build and save markdown comparison tables to a file.
Writes two sections: - "## Test Results" with the test metrics table - "## Train/Val Results" with the train/val metrics table (if provided)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_results
|
Mapping[str, Mapping[str, float]]
|
Dict from test_all(), mapping model names to test metric dicts. |
required |
save_dir
|
str | Path
|
Directory where the markdown file will be written. |
required |
train_results
|
Mapping[str, Mapping[str, float]] | None
|
Optional dict mapping model names to train metric dicts.
Defaults to |
None
|
val_results
|
Mapping[str, Mapping[str, float]] | None
|
Optional dict mapping model names to val metric dicts.
Defaults to |
None
|
filename
|
str
|
Name of the output file. Defaults to |
'results.md'
|
precision
|
int
|
Decimal places for metric values. Defaults to |
4
|
Returns:
| Name | Type | Description |
|---|---|---|
path |
Path
|
Path to the written file. |
Source code in hypertorch/train/markdown_logger.py
__split_results()
¶
Split all accumulated metrics into test vs train/val groups.
Metrics are classified by their name prefix: - "test/" -> test_results - "train/" -> train_results - "val/*" -> val_results - anything else (e.g., "epoch") -> ignored
Returns:
| Name | Type | Description |
|---|---|---|
results |
dict[str, dict[str, float]]
|
Tuple of (test_results, train_results, val_results), where each is a dict |
dict[str, dict[str, float]]
|
mapping model names to their respective metric dicts. Models with no metrics |
|
dict[str, dict[str, float]]
|
in a category are excluded from that category's dict. |
Source code in hypertorch/train/markdown_logger.py
MultiModelTrainer
¶
A trainer class to handle training multiple models with individual trainers.
Attributes:
| Name | Type | Description |
|---|---|---|
model_configs |
list[ModelConfig]
|
Model configurations managed by the trainer. |
log_dir |
Path
|
Directory used for logs and default checkpoints. |
auto_start_tensorboard |
bool
|
Whether TensorBoard should be started automatically. |
tensorboard_port |
int
|
Port used by the auto-started TensorBoard server. |
auto_wait |
bool
|
Whether |
Source code in hypertorch/train/trainer.py
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 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 386 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 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | |
distributed_global_rank
property
¶
Return the global rank of the current process.
Returns:
| Name | Type | Description |
|---|---|---|
global_rank |
int
|
The global rank of the current process. |
is_global_zero
property
¶
Return whether the current process is the global zero process.
Check first if any of the trainers is the global zero, which covers the case where a custom strategy that handles distributed differently was provided. If no trainer is available, fall back to checking the global rank.
Returns:
| Name | Type | Description |
|---|---|---|
is_global_zero |
bool
|
|
models
property
¶
Return all configured Lightning modules.
Returns:
| Name | Type | Description |
|---|---|---|
models |
list[LightningModule]
|
List of configured models. |
__init__(model_configs, experiment_name=None, accelerator='auto', devices='auto', test_devices=None, strategy='auto', num_nodes=1, precision=None, max_epochs=None, min_epochs=None, max_steps=-1, min_steps=None, check_val_every_n_epoch=1, logger=None, default_root_dir=None, enable_autolog_hparams=True, log_every_n_steps=None, profiler=None, fast_dev_run=False, enable_checkpointing=True, enable_progress_bar=True, enable_model_summary=None, callbacks=None, checkpoint_callback_kwargs=None, auto_start_tensorboard=False, tensorboard_port=6006, auto_wait=False, **kwargs)
¶
Initialize trainers for one or more model configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_configs
|
list[ModelConfig]
|
A list of ModelConfig objects, each containing a model and its associated trainer (if any). |
required |
experiment_name
|
str | None
|
Name for this experiment run's log directory. When |
None
|
accelerator
|
str | Accelerator
|
Supports passing different accelerator types ("cpu", "gpu", "tpu", "hpu", "mps", "auto") as well as custom accelerator instances. |
'auto'
|
devices
|
list[int] | str | int
|
The devices to use. Can be set to a positive number (int or str), a
sequence of device indices (list or str), the value |
'auto'
|
test_devices
|
list[int] | str | int | None
|
Optional device configuration for automatically-created test trainers.
When set, |
None
|
strategy
|
str | Strategy
|
Supports different training strategies with aliases as well custom strategies.
Defaults to |
'auto'
|
num_nodes
|
int
|
Number of GPU nodes for distributed training. Defaults to |
1
|
precision
|
Any | None
|
Double precision (64, '64' or '64-true'),
full precision (32, '32' or '32-true'), 16bit mixed precision (16, '16', '16-mixed')
or bfloat16 mixed precision ('bf16', 'bf16-mixed').
Can be used on CPU, GPU, TPUs, or HPUs. Defaults to |
None
|
max_epochs
|
int | None
|
Stop training once this number of epochs is reached.
Disabled by default (None). If both max_epochs and max_steps are not specified,
defaults to |
None
|
min_epochs
|
int | None
|
Force training for at least these many epochs. Disabled by default (None). |
None
|
max_steps
|
int
|
Stop training after this number of steps. Disabled by default (-1).
If |
-1
|
min_steps
|
int | None
|
Force training for at least these number of steps.
Disabled by default ( |
None
|
check_val_every_n_epoch
|
int | None
|
Perform a validation loop after every |
1
|
logger
|
Logger | Iterable[Logger] | bool | None
|
Logger (or iterable collection of loggers) for experiment tracking. A |
None
|
default_root_dir
|
str | Path | None
|
Default path for logs and weights when no logger/ckpt_callback passed.
Defaults to |
None
|
enable_autolog_hparams
|
bool
|
Whether to log hyperparameters at the start of a run.
Defaults to |
True
|
log_every_n_steps
|
int | None
|
How often to log within steps.
Defaults to |
None
|
profiler
|
Profiler | str | None
|
To profile individual steps during training and assist in
identifying bottlenecks. Defaults to |
None
|
fast_dev_run
|
int | bool
|
Runs n if set to |
False
|
enable_checkpointing
|
bool
|
If |
True
|
enable_progress_bar
|
bool
|
Whether to enable the progress bar by default.
Defaults to |
True
|
enable_model_summary
|
bool | None
|
Whether to enable model summarization by default.
Defaults to |
None
|
callbacks
|
list[Callback] | Callback | None
|
Add a callback or list of callbacks.
Defaults to |
None
|
checkpoint_callback_kwargs
|
dict[str, Any] | None
|
Keyword arguments passed to the default
|
None
|
auto_start_tensorboard
|
bool
|
When |
False
|
tensorboard_port
|
int
|
Port for the auto-launched TensorBoard server.
Defaults to |
6006
|
auto_wait
|
bool
|
When |
False
|
kwargs
|
Any
|
max_time: Maximum wall-clock training time. Passed to Lightning's |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no model configurations are provided or numeric settings are invalid. |
Source code in hypertorch/train/trainer.py
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 | |
__enter__()
¶
Enter the trainer context manager.
Returns:
| Name | Type | Description |
|---|---|---|
trainer |
MultiModelTrainer
|
This trainer instance. |
__exit__(exc_type, exc_val, exc_tb)
¶
Exit the trainer context manager and finalize resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
Exception type from the context, if any, unused. |
required |
exc_val
|
BaseException | None
|
Exception value from the context, if any, unused. |
required |
exc_tb
|
Any
|
Exception traceback from the context, if any, unused. |
required |
Source code in hypertorch/train/trainer.py
__del__()
¶
Finalize external resources during object cleanup.
Source code in hypertorch/train/trainer.py
model(name, version='default')
¶
Return a configured model by name and version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Model name. |
required |
version
|
str
|
Model version. Defaults to |
'default'
|
Returns:
| Name | Type | Description |
|---|---|---|
model |
LightningModule | None
|
Matching model, or |
Source code in hypertorch/train/trainer.py
fit_all(train_dataloader=None, val_dataloader=None, datamodule=None, ckpt_path=None, verbose=True)
¶
Fit every trainable configured model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_dataloader
|
DataLoader | None
|
Shared training dataloader used when a model has no override.
Defaults to |
None
|
val_dataloader
|
DataLoader | None
|
Shared validation dataloader used when a model has no override.
Defaults to |
None
|
datamodule
|
LightningDataModule | None
|
Optional Lightning datamodule.
Defaults to |
None
|
ckpt_path
|
CkptStrategy | None
|
Optional checkpoint strategy or path.
Defaults to |
None
|
verbose
|
bool
|
Whether to print progress messages. Defaults to |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a trainable model has no trainer. |
Source code in hypertorch/train/trainer.py
test_all(dataloader=None, datamodule=None, ckpt_path=None, verbose=True, verbose_loop=True)
¶
Test every configured model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataloader
|
DataLoader | None
|
Shared test dataloader used when a model has no override.
Defaults to |
None
|
datamodule
|
LightningDataModule | None
|
Optional Lightning datamodule. Defaults to |
None
|
ckpt_path
|
CkptStrategy | None
|
Optional checkpoint strategy or path. Defaults to |
None
|
verbose
|
bool
|
Whether to print model-level progress messages. Defaults to |
True
|
verbose_loop
|
bool
|
Whether Lightning should print test-loop output. Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
test_results |
Mapping[str, TestResult]
|
Mapping from full model name to Lightning test metrics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a model has no trainer available for testing. |
Source code in hypertorch/train/trainer.py
finalize()
¶
Finalize trainer-managed external resources.
Source code in hypertorch/train/trainer.py
wait()
¶
Wait until the user presses Enter, keeping process alive.
If no process is running, this method does nothing.
Source code in hypertorch/train/trainer.py
__auto_start_tensorboard_if_enabled()
¶
Start TensorBoard when auto-start is enabled and available.
Source code in hypertorch/train/trainer.py
__is_separate_single_process_test_trainer(model_config, test_trainer)
¶
Check whether testing uses a separate single-process trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_config
|
ModelConfig
|
Model configuration being tested. |
required |
test_trainer
|
Trainer
|
Trainer selected for testing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
bool
|
|
Source code in hypertorch/train/trainer.py
__is_tensorboard_available()
¶
Check whether TensorBoard is importable.
Returns:
| Name | Type | Description |
|---|---|---|
available |
bool
|
|
__start_tensorboard_process()
¶
Start a TensorBoard subprocess for the trainer log directory.
Returns:
| Name | Type | Description |
|---|---|---|
process |
Popen | None
|
Started TensorBoard process, or |
Source code in hypertorch/train/trainer.py
__checkpoint_dir(model_config, model_index, has_duplicate_full_model_name)
¶
Resolve the checkpoint directory for a model configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_config
|
ModelConfig
|
Model configuration that owns the checkpoints. |
required |
model_index
|
int
|
Index of the model in |
required |
has_duplicate_full_model_name
|
bool
|
Whether the full model name is duplicated. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
checkpoint_dir |
Path
|
Directory for model checkpoints. |
Source code in hypertorch/train/trainer.py
__device(trainer)
¶
Return the root device string for a trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trainer
|
Trainer
|
Lightning trainer to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
device |
str
|
Root device string, or |
Source code in hypertorch/train/trainer.py
__full_model_name_counts(model_configs)
¶
Count occurrences of full model names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_configs
|
list[ModelConfig]
|
Model configurations to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
counts |
dict[str, int]
|
Mapping from full model name to occurrence count. |
Source code in hypertorch/train/trainer.py
__next_experiment_name(save_dir)
¶
Return the next available experiment directory name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
save_dir
|
Path
|
Base directory containing experiment directories. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
experiment_name |
Path
|
Next experiment directory name. |
Source code in hypertorch/train/trainer.py
__logdir(default_root_dir, experiment_name)
¶
Resolve the log directory for this trainer instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default_root_dir
|
str | Path | None
|
Optional root directory for logs. |
required |
experiment_name
|
str | None
|
Optional explicit experiment directory name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
log_dir |
Path
|
Resolved log directory. |
Source code in hypertorch/train/trainer.py
__setup_logger(model_config, logger)
¶
Resolve loggers for a model configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_config
|
ModelConfig
|
Model configuration being prepared. |
required |
logger
|
Logger | Iterable[Logger] | bool | None
|
User-provided logger configuration. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logger |
Logger | Iterable[Logger] | bool | None
|
User-provided logger configuration or default HyperTorch loggers. |
Source code in hypertorch/train/trainer.py
__setup_callbacks(model_config, model_index, has_duplicate_full_model_name, callbacks, enable_checkpointing)
¶
Resolve callbacks for a model configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_config
|
ModelConfig
|
Model configuration being prepared. |
required |
model_index
|
int
|
Index of the model in |
required |
has_duplicate_full_model_name
|
bool
|
Whether the full model name is duplicated. |
required |
callbacks
|
list[Callback] | Callback | None
|
User-provided callbacks. |
required |
enable_checkpointing
|
bool
|
Whether checkpointing is enabled. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callbacks |
list[Callback] | Callback | None
|
Resolved callbacks for the trainer. |
Source code in hypertorch/train/trainer.py
__should_skip_test_on_current_rank(model_config, test_trainer)
¶
Check whether the current rank should skip testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_config
|
ModelConfig
|
Model configuration being tested. |
required |
test_trainer
|
Trainer
|
Trainer selected for testing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
bool
|
|
Source code in hypertorch/train/trainer.py
__to_callback_list(callbacks)
¶
Normalize callback configuration to a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callbacks
|
list[Callback] | Callback | None
|
Optional callback, callback list, or |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callbacks |
list[Callback]
|
Callback list. |
Source code in hypertorch/train/trainer.py
__wait_for_distributed()
¶
Synchronize and tear down an initialized distributed process group.
Source code in hypertorch/train/trainer.py
colorize_metric_value(metric, value, text, metric_bounds, sort_order)
¶
Wrap a formatted metric value in a LaTex cell color command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
str
|
Metric name. |
required |
value
|
float
|
Numeric metric value. |
required |
text
|
str
|
Already formatted metric text. |
required |
metric_bounds
|
Mapping[str, tuple[float, float]] | None
|
Optional metric bounds used for color scaling. |
required |
sort_order
|
str
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
text |
str
|
Original or colorized LaTex cell text. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |