Skip to content

Trainers

TabularTrainer

__init__

__init__(
    model: TabularModel, dp_budget: DpBudget | None = None
) -> None

Trainer for a TabularModel.

Parameters:

Name Type Description Default
model TabularModel

A TabularModel instance.

required
dp_budget DpBudget | None

The (eps, delta)-budget for differentially private (DP) training. If None (the default), the training will not be differentially private. Available only for single table datasets.

None

train

train(
    dataset: TabularDataset,
    n_epochs: int | None = None,
    n_steps: int | None = None,
    batch_size: int = 0,
    lr: float = 0.0,
    memory: int = 0,
    valid: Validation | None = None,
    hooks: Sequence[TrainHook] = (),
    accumulate_grad: int = 1,
    dp_step: DpStep | None = None,
    world_size: int = 0,
) -> None

Train the TabularModel with the input TabularDataset.

Parameters:

Name Type Description Default
dataset TabularDataset

The training data, as a TabularDataset object.

required
n_epochs int | None

The number of training epochs. One and only one of n_epochs and n_steps must be provided.

None
n_steps int | None

The number of training steps. One and only one of n_epochs and n_steps must be provided.

None
batch_size int

The size of a batch of data during training. When it is not specified the user must provide the argument memory.

0
lr float

The learning rate. If it is 0 the optimal value for the learning rate is automatically determined.

0.0
memory int

The available memory in MB that is used to automatically compute the optimal value of the batch size.

0
valid Validation | None

A Validation object. If None, no validation is performed.

None
hooks Sequence[TrainHook]

A sequence of custom TrainHook objects.

()
accumulate_grad int

The number of gradient accumulation steps. If equal to 1, the weights are updated at each step.

1
dp_step DpStep | None

Data for differentially private step. Must be provided if and only if the trainer has a DP-budget.

None
world_size int

Number of GPUs where to distribute the training. If 0, the training is performed on a single device, on the current device of the TabularTrainer object.

0

save

save(path: Path | str) -> None

Save the TabularTrainer to a checkpoint at the given path.

load classmethod

load(path: Path | str) -> TabularTrainer

Load the TabularTrainer from the checkpoint at the given path.

TextTrainer

__init__

__init__(model: TextModel) -> None

Trainer for a TextModel.

Parameters:

Name Type Description Default
model TextModel

A TextModel instance.

required

train

train(
    dataset: TextDataset,
    n_epochs: int | None = None,
    n_steps: int | None = None,
    batch_size: int = 0,
    lr: float = 0.0,
    memory: int = 0,
    valid: Validation | None = None,
    hooks: Sequence[TrainHook] = (),
    accumulate_grad: int = 1,
    world_size: int = 0,
) -> None

Train the TextModel with the input TextDataset.

Parameters:

Name Type Description Default
dataset TextDataset

The training data, as a TextDataset object.

required
n_epochs int | None

The number of training epochs. One and only one of n_epochs and n_steps must be provided.

None
n_steps int | None

The number of training steps. One and only one of n_epochs and n_steps must be provided.

None
batch_size int

The size of a batch of data during training. When it is not specified the user must provide the argument memory.

0
lr float

The learning rate. If it is 0 the optimal value for the learning rate is automatically determined.

0.0
memory int

The available memory in MB that is used to automatically compute the optimal value of the batch size.

0
valid Validation | None

A Validation object. If None, no validation is performed.

None
hooks Sequence[TrainHook]

A sequence of custom TrainHook objects.

()
accumulate_grad int

The number of gradient accumulation steps. If equal to 1, the weights are updated at each step.

1
world_size int

Number of GPUs where to distribute the training. If 0, the training is performed on a single device, on the current device of the TextTrainer object.

0

save

save(path: Path | str) -> None

Save the TextTrainer to a checkpoint at the given path.

load classmethod

load(path: Path | str) -> TextTrainer

Load the TextTrainer from the checkpoint at the given path.