tuning¶
tune_batch_size ¶
tune_batch_size(
trainer,
module,
datamodule=None,
*,
effective_batch_size,
pin_path=None,
num_devices=None,
batch_arg="batch_size",
retune=False,
**scale_kwargs,
)
Pin the effective batch; find the largest fitting device batch, set accumulation.
Runs Tuner.scale_batch_size once to find the largest device batch that
fits (found_max), then chooses device_batch = the largest divisor of
effective_batch_size / num_devices that is <= found_max and sets
trainer.accumulate_grad_batches accordingly. Because device_batch
divides the per-device target exactly, the realized effective batch always
equals effective_batch_size on any hardware — no drift.
found_max (the raw hardware probe) is written to pin_path; a later run
reads it and skips the search, re-deriving device_batch/accumulation for
that run's effective_batch_size/num_devices. retune=True forces a
fresh search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effective_batch_size
|
int
|
The pinned, hardware-independent quantity
|
required |
pin_path
|
str, Path, or None
|
Sidecar YAML storing |
None
|
num_devices
|
int or None
|
Defaults to |
None
|
batch_arg
|
str
|
Attribute on the module (or datamodule) the tuner scales and this helper
sets; forwarded to the tuner as |
'batch_size'
|
retune
|
bool
|
Ignore any existing pin and search again. |
False
|
**scale_kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
BatchPin
|
|
tune_learning_rate ¶
tune_learning_rate(
trainer,
module,
datamodule=None,
*,
pin_path=None,
lr_attr="lr",
retune=False,
**lr_find_kwargs,
)
Record-and-pin Lightning's LR finder.
Runs Tuner.lr_find once, writes the suggested learning rate to
pin_path, and sets module.<lr_attr>. A later call reads the pin and
skips the (stochastic) range test; retune=True forces a fresh search.
Learning rate is hardware-independent, so there is no device math.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pin_path
|
str, Path, or None
|
Sidecar YAML. Defaults to |
None
|
lr_attr
|
str
|
Attribute on the module set to the found learning rate. |
'lr'
|
retune
|
bool
|
Ignore any existing pin and search again. |
False
|
**lr_find_kwargs
|
Forwarded to |
{}
|