Configurations¶
Core Configuration¶
Data configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Optional[List[str]]
|
A list of strings with the names of the target column(s). It is mandatory for all except SSL tasks. |
None
|
continuous_cols |
List
|
Column names of the numeric fields. Defaults to [] |
list()
|
categorical_cols |
List
|
Column names of the categorical fields to treat differently. Defaults to [] |
list()
|
date_columns |
List
|
(Column name, Freq, Format) tuples of the date fields. For eg. a field named introduction_date and with a monthly frequency like "2023-12" should have an entry ('intro_date','M','%Y-%m') |
list()
|
encode_date_columns |
bool
|
Whether to encode the derived variables from date |
True
|
validation_split |
Optional[float]
|
Percentage of Training rows to keep aside as validation. Used only if Validation Data is not given separately |
0.2
|
continuous_feature_transform |
Optional[str]
|
Whether to transform the features before
modelling. By default, it is turned off. Choices are: [ |
None
|
normalize_continuous_features |
bool
|
Flag to normalize the input features(continuous) |
True
|
quantile_noise |
int
|
NOT IMPLEMENTED. If specified fits QuantileTransformer on data with added gaussian noise with std = :quantile_noise: * data.std ; this will cause discrete values to be more separable. Please note that this transformation does NOT apply gaussian noise to the resulting data, the noise is only applied for QuantileTransformer |
0
|
num_workers |
Optional[int]
|
The number of workers used for data loading. For windows always set to 0 |
0
|
pin_memory |
bool
|
Whether to pin memory for data loading. |
True
|
handle_unknown_categories |
bool
|
Whether to handle unknown or new values in categorical columns as unknown |
True
|
handle_missing_values |
bool
|
Whether to handle missing values in categorical columns as unknown |
True
|
dataloader_kwargs |
Dict[str, Any]
|
Additional kwargs to be passed to PyTorch DataLoader. See https://pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader |
dict()
|
Source code in src/pytorch_tabular/config/config.py
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 |
|
Base Model configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task |
str
|
Specify whether the problem is regression or classification. |
required |
head |
Optional[str]
|
The head to be used for the model. Should be one of the heads defined in
|
'LinearHead'
|
head_config |
Optional[Dict]
|
The config as a dict which defines the head. If left empty, will be initialized as default linear head. |
lambda: {'layers': ''}()
|
embedding_dims |
Optional[List]
|
The dimensions of the embedding for each categorical column as a list of tuples (cardinality, embedding_dim). If left empty, will infer using the cardinality of the categorical column using the rule min(50, (x + 1) // 2) |
None
|
embedding_dropout |
float
|
Dropout to be applied to the Categorical Embedding. Defaults to 0.0 |
0.0
|
batch_norm_continuous_input |
bool
|
If True, we will normalize the continuous layer by passing it through a BatchNorm layer. |
True
|
virtual_batch_size |
Optional[int]
|
If not None, all BatchNorms will be converted to GhostBatchNorm's with the specified virtual batch size. Defaults to None |
None
|
learning_rate |
float
|
The learning rate of the model. Defaults to 1e-3. |
0.001
|
loss |
Optional[str]
|
The loss function to be applied. By Default, it is MSELoss for regression and CrossEntropyLoss for classification. Unless you are sure what you are doing, leave it at MSELoss or L1Loss for regression and CrossEntropyLoss for classification |
None
|
metrics |
Optional[List[str]]
|
the list of metrics you need to track during training. The metrics
should be one of the functional metrics implemented in |
None
|
metrics_prob_input |
Optional[bool]
|
Is a mandatory parameter for classification metrics defined in the config. This defines whether the input to the metric function is the probability or the class. Length should be same as the number of metrics. Defaults to None. |
None
|
metrics_params |
Optional[List]
|
The parameters to be passed to the metrics function. |
None
|
target_range |
Optional[List]
|
The range in which we should limit the output variable. Currently ignored for multi-target regression. Typically used for Regression problems. If left empty, will not apply any restrictions |
None
|
seed |
int
|
The seed for reproducibility. Defaults to 42 |
42
|
Source code in src/pytorch_tabular/config/config.py
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 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
|
Base SSLModel Configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encoder_config |
Optional[ModelConfig]
|
The config of the encoder to be used for the model. Should be one of the model configs defined in PyTorch Tabular |
None
|
decoder_config |
Optional[ModelConfig]
|
The config of decoder to be used for the model. Should be one of the model configs defined in PyTorch Tabular. Defaults to nn.Identity |
None
|
embedding_dims |
Optional[List]
|
The dimensions of the embedding for each categorical column as a list of tuples (cardinality, embedding_dim). If left empty, will infer using the cardinality of the categorical column using the rule min(50, (x + 1) // 2) |
None
|
embedding_dropout |
float
|
Dropout to be applied to the Categorical Embedding. Defaults to 0.1 |
0.1
|
batch_norm_continuous_input |
bool
|
If True, we will normalize the continuous layer by passing it through a BatchNorm layer. |
True
|
virtual_batch_size |
Optional[int]
|
If not None, all BatchNorms will be converted to GhostBatchNorm's with the specified virtual batch size. Defaults to None |
None
|
learning_rate |
float
|
The learning rate of the model. Defaults to 1e-3 |
0.001
|
seed |
int
|
The seed for reproducibility. Defaults to 42 |
42
|
Source code in src/pytorch_tabular/config/config.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
|
Trainer configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size |
int
|
Number of samples in each batch of training |
64
|
data_aware_init_batch_size |
int
|
Number of samples in each batch of training for the data-aware initialization, when applicable. Defaults to 2000 |
2000
|
fast_dev_run |
bool
|
runs n if set to |
False
|
max_epochs |
int
|
Maximum number of epochs to be run |
10
|
min_epochs |
Optional[int]
|
Force training for at least these many epochs. 1 by default |
1
|
max_time |
Optional[int]
|
Stop training after this amount of time has passed. Disabled by default (None) |
None
|
accelerator |
Optional[str]
|
The accelerator to use for training. Can be one of
'cpu','gpu','tpu','ipu', 'mps', 'auto'. Defaults to 'auto'.
Choices are: [ |
'auto'
|
devices |
Optional[int]
|
Number of devices to train on (int). -1 uses all available devices. By default, uses all available devices (-1) |
-1
|
devices_list |
Optional[List[int]]
|
List of devices to train on (list). If specified, takes
precedence over |
None
|
accumulate_grad_batches |
int
|
Accumulates grads every k batches or as set up in the dict. Trainer also calls optimizer.step() for the last indivisible step number. |
1
|
auto_lr_find |
bool
|
Runs a learning rate finder algorithm when calling trainer.tune(), to find optimal initial learning rate. |
False
|
auto_select_gpus |
bool
|
If enabled and |
True
|
check_val_every_n_epoch |
int
|
Check val every n train epochs. |
1
|
gradient_clip_val |
float
|
Gradient clipping value |
0.0
|
overfit_batches |
float
|
Uses this much data of the training set. If nonzero, will use the same training set for validation and testing. If the training dataloaders have shuffle=True, Lightning will automatically disable it. Useful for quickly debugging or trying to overfit on purpose. |
0.0
|
deterministic |
bool
|
If true enables cudnn.deterministic. Might make your system slower, but ensures reproducibility. |
False
|
profiler |
Optional[str]
|
To profile individual steps during training and assist in identifying
bottlenecks. None, simple or advanced, pytorch. Choices are:
[ |
None
|
early_stopping |
Optional[str]
|
The loss/metric that needed to be monitored for early stopping. If None, there will be no early stopping |
'valid_loss'
|
early_stopping_min_delta |
float
|
The minimum delta in the loss/metric which qualifies as an improvement in early stopping |
0.001
|
early_stopping_mode |
str
|
The direction in which the loss/metric should be optimized. Choices are:
[ |
'min'
|
early_stopping_patience |
int
|
The number of epochs to wait until there is no further improvements in loss/metric |
3
|
early_stopping_kwargs |
Optional[Dict]
|
Additional keyword arguments for the early stopping callback. See the documentation for the PyTorch Lightning EarlyStopping callback for more details. |
lambda: {}()
|
checkpoints |
Optional[str]
|
The loss/metric that needed to be monitored for checkpoints. If None, there will be no checkpoints |
'valid_loss'
|
checkpoints_path |
str
|
The path where the saved models will be |
'saved_models'
|
checkpoints_every_n_epochs |
int
|
Number of training steps between checkpoints |
1
|
checkpoints_name |
Optional[str]
|
The name under which the models will be saved. If left blank,
first it will look for |
None
|
checkpoints_mode |
str
|
The direction in which the loss/metric should be optimized |
'min'
|
checkpoints_save_top_k |
int
|
The number of best models to save |
1
|
checkpoints_kwargs |
Optional[Dict]
|
Additional keyword arguments for the checkpoints callback. See the documentation for the PyTorch Lightning ModelCheckpoint callback for more details. |
lambda: {}()
|
load_best |
bool
|
Flag to load the best model saved during training |
True
|
track_grad_norm |
int
|
Track and Log Gradient Norms in the logger. -1 by default means no tracking. 1 for the L1 norm, 2 for L2 norm, etc. |
-1
|
progress_bar |
str
|
Progress bar type. Can be one of: |
'rich'
|
precision |
int
|
Precision of the model. Can be one of: |
32
|
seed |
int
|
Seed for random number generators. Defaults to 42 |
42
|
trainer_kwargs |
Dict[str, Any]
|
Additional kwargs to be passed to PyTorch Lightning Trainer. See https://pytorch-lightning.readthedocs.io/en/latest/api/pytorch_lightning.trainer.html#pytorch_lightning.trainer.Trainer |
dict()
|
Source code in src/pytorch_tabular/config/config.py
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 |
|
Experiment configuration. Experiment Tracking with WandB and Tensorboard.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_name |
str
|
The name of the project under which all runs will be logged. For Tensorboard this defines the folder under which the logs will be saved and for W&B it defines the project name |
MISSING
|
run_name |
Optional[str]
|
The name of the run; a specific identifier to recognize the run. If left blank, will be assigned an auto-generated name |
None
|
exp_watch |
Optional[str]
|
The level of logging required. Can be |
None
|
log_target |
str
|
Determines where logging happens - Tensorboard or W&B. Choices are:
[ |
'tensorboard'
|
log_logits |
bool
|
Turn this on to log the logits as a histogram in W&B |
False
|
exp_log_freq |
int
|
step count between logging of gradients and parameters. |
100
|
Source code in src/pytorch_tabular/config/config.py
Optimizer and Learning Rate Scheduler configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
optimizer |
str
|
Any of the standard optimizers from torch.optim or provide full python path, for example "torch_optimizer.RAdam". |
'Adam'
|
optimizer_params |
Dict
|
The parameters for the optimizer. If left blank, will use default parameters. |
lambda: {}()
|
lr_scheduler |
Optional[str]
|
The name of the LearningRateScheduler to use, if any, from
torch.optim.lr_scheduler. If None, will not use any scheduler. Defaults to |
None
|
lr_scheduler_params |
Optional[Dict]
|
The parameters for the LearningRateScheduler. If left blank, will use default parameters. |
lambda: {}()
|
lr_scheduler_monitor_metric |
Optional[str]
|
Used with ReduceLROnPlateau, where the plateau is decided based on this metric |
'valid_loss'
|
Source code in src/pytorch_tabular/config/config.py
Source code in src/pytorch_tabular/config/config.py
__init__(exp_version_manager='.pt_tmp/exp_version_manager.yml')
¶
The manages the versions of the experiments based on the name. It is a simple dictionary(yaml) based lookup. Primary purpose is to avoid overwriting of saved models while running the training without changing the experiment name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exp_version_manager |
str
|
The path of the yml file which acts as version control. Defaults to ".pt_tmp/exp_version_manager.yml". |
'.pt_tmp/exp_version_manager.yml'
|
Source code in src/pytorch_tabular/config/config.py
Head Configuration¶
In addition to these core classes, we also have config classes for heads
A model class for Linear Head configuration; serves as a template and documentation. The models take a dictionary as input, but if there are keys which are not present in this model class, it'll throw an exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layers |
str
|
Hyphen-separated number of layers and units in the classification/regression head. E.g. 32-64-32. Default is just a mapping from intput dimension to output dimension |
''
|
activation |
str
|
The activation type in the classification head. The default activation in PyTorch like ReLU, TanH, LeakyReLU, etc. https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity |
'ReLU'
|
dropout |
float
|
probability of a classification element to be zeroed. |
0.0
|
use_batch_norm |
bool
|
Flag to include a BatchNorm layer after each Linear Layer+DropOut |
False
|
initialization |
str
|
Initialization scheme for the linear layers. Defaults to |
'kaiming'
|
Source code in src/pytorch_tabular/models/common/heads/config.py
MixtureDensityHead configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_gaussian |
int
|
Number of Gaussian Distributions in the mixture model. Defaults to 1 |
1
|
sigma_bias_flag |
bool
|
Whether to have a bias term in the sigma layer. Defaults to False |
False
|
mu_bias_init |
Optional[List]
|
To initialize the bias parameter of the mu layer to predefined cluster centers. Should be a list with the same length as number of gaussians in the mixture model. It is highly recommended to set the parameter to combat mode collapse. Defaults to None |
None
|
weight_regularization |
Optional[int]
|
Whether to apply L1 or L2 Norm to the MDN layers. Defaults
to L2. Choices are: [ |
2
|
lambda_sigma |
Optional[float]
|
The regularization constant for weight regularization of sigma layer. Defaults to 0.1 |
0.1
|
lambda_pi |
Optional[float]
|
The regularization constant for weight regularization of pi layer. Defaults to 0.1 |
0.1
|
lambda_mu |
Optional[float]
|
The regularization constant for weight regularization of mu layer. Defaults to 0 |
0
|
softmax_temperature |
Optional[float]
|
The temperature to be used in the gumbel softmax of the mixing coefficients. Values less than one leads to sharper transition between the multiple components. Defaults to 1 |
1
|
n_samples |
int
|
Number of samples to draw from the posterior to get prediction. Defaults to 100 |
100
|
central_tendency |
str
|
Which measure to use to get the point prediction. Defaults to mean. Choices
are: [ |
'mean'
|
speedup_training |
bool
|
Turning on this parameter does away with sampling during training which speeds up training, but also doesn't give you visibility on train metrics. Defaults to False |
False
|
log_debug_plot |
bool
|
Turning on this parameter plots histograms of the mu, sigma, and pi layers in addition to the logits(if log_logits is turned on in experment config). Defaults to False |
False
|
input_dim |
int
|
The input dimensions to the head. This will be automatically filled in while
initializing from the |
None
|
Source code in src/pytorch_tabular/models/common/heads/config.py
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 |
|