Learning-rate search
See the guide.
LRSearchConfig
dataclass
LRSearchConfig(probe_steps=150, probe_eval_steps=None, confirm=True, early_stop=True, max_probes=12, resolution='coarse', factor=10.0, min_ratio=None, lr_bounds=(1e-12, 10.0), center_window=True, max_window_probes=4, probe_seeds=1, keep_probe_artifacts=False, verbose=False)
Options of the learning-rate search.
Set it as TrainingArguments(learning_rate="tune", lr_search_config=LRSearchConfig(...)) or pass single fields
to trainer.tune_learning_rate(...). factor, min_ratio, max_probes, resolution, lr_bounds,
center_window and max_window_probes are those of :class:LRSearch.
confirm
class-attribute
instance-attribute
Re-run a converged probe at the full max_steps before accepting it (one extra full run).
early_stop
class-attribute
instance-attribute
End a probe as soon as it is decisively collapsed or diverged.
keep_probe_artifacts
class-attribute
instance-attribute
Keep the probe checkpoints (default: only each probe's training.json).
probe_eval_steps
class-attribute
instance-attribute
Evaluation interval inside a probe (default: probe_steps // 6).
probe_seeds
class-attribute
instance-attribute
Seeds a probe may try. Some regimes (the GRADIEND pair) drift to a common pole for one seed and converge for
another, so a single-seed probe can report collapsed or degrading at a learning rate that multi-seed
training (max_seeds > 1) converges at. With probe_seeds > 1 a probe that ends collapsed or degrading
is repeated with the next seeds (seed + 1, ...) and the best run is kept (converged first, then the highest
score). frozen, slow and diverged probes are not repeated: another seed does not change their verdict.
probe_steps
class-attribute
instance-attribute
Steps of each short probe run. None trains every probe for the full max_steps.
verbose
class-attribute
instance-attribute
Show the full training log of every probe. By default the search logs one line per probe.
__post_init__
Source code in gradiend/trainer/core/lr_search.py
tune_learning_rate
tune_learning_rate(trainer, initial_lr, *, experiment_dir, config=None, precheck=None, metadata=None, **train_overrides)
Search the learning rate of trainer and write lr_search.json into experiment_dir.
Most users call :meth:Trainer.tune_learning_rate() <gradiend.trainer.trainer.Trainer.tune_learning_rate> or set
TrainingArguments(learning_rate="tune") instead; this is the function behind both.
Each probe trains one seed into <experiment_dir>/lr_search/<probe|confirm>_<lr> (no cache
reuse), always from the trainer's original base model, with max_steps=config.probe_steps. With
config.confirm a converged probe is re-run at the trainer's configured max_steps before it
is accepted. With config.early_stop a probe ends as soon as it is decisively collapsed or
diverged (:class:ProbeStopCallback). precheck runs once before the first probe (use
:func:~gradiend.trainer.core.signal_checks.assert_signal_diverse on stacked inputs) for extra checks.
Probe checkpoints are deleted after each probe (only training.json is kept) unless
config.keep_probe_artifacts. metadata (e.g. the first guess and probe length) is stored next to the
result in lr_search.json so a later run can tell whether a finished search still applies. The search options
are those of :class:LRSearchConfig (probe_seeds > 1 repeats a collapsed or degrading probe with
the next seeds); train_overrides are passed to every probe's trainer.train.
Source code in gradiend/trainer/core/lr_search.py
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 | |
LRSearch
LRSearch(run, initial_lr, *, factor=10.0, min_ratio=None, max_probes=12, resolution='coarse', lr_bounds=(1e-12, 10.0), confirm=None, classify=classify_probe, center_window=True, max_window_probes=4, refine_fine=True, max_refine_probes=3, confirm_slow=True)
Bracket-and-bisect controller over a probe function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run
|
Callable[[float], ProbeResult]
|
|
required |
initial_lr
|
float
|
first guess (use a readable value such as |
required |
factor
|
float
|
expansion step while no bracket exists (10 by default). |
10.0
|
min_ratio
|
Optional[float]
|
optional extra stop: the bracket is also closed once |
None
|
max_probes
|
int
|
budget for the bracketing phase. On exhaustion the status is |
12
|
resolution
|
str
|
|
'coarse'
|
lr_bounds
|
Tuple[float, float]
|
never propose an LR outside |
(1e-12, 10.0)
|
confirm
|
Optional[Callable[[float], ProbeResult]]
|
optional |
None
|
center_window
|
bool
|
once a probe converges, walk outward along the grid until the neighbours stop converging and return the convergent LR closest (in log space) to the window's centre, instead of the first hit, which may sit on the edge of the stable range. |
True
|
max_window_probes
|
int
|
extra probes allowed for that walk (separate from |
4
|
refine_fine
|
bool
|
when a |
True
|
max_refine_probes
|
int
|
probe budget for that fine refinement. |
3
|
confirm_slow
|
bool
|
before reporting |
True
|
Source code in gradiend/trainer/core/lr_search.py
_bracket
(highest 'too low' LR below the lowest 'too high' LR, lowest 'too high' LR).
Source code in gradiend/trainer/core/lr_search.py
_converged_result
Source code in gradiend/trainer/core/lr_search.py
_next_lr
Source code in gradiend/trainer/core/lr_search.py
_norm
staticmethod
_probe
Source code in gradiend/trainer/core/lr_search.py
_still_improving_slow_probe
Highest-LR slow probe below the bracket's high end whose score ended at its best.
Source code in gradiend/trainer/core/lr_search.py
_tried
_walk_window
Follow the grid from first_lr while neighbours keep converging; return (LRs, budget left).
Source code in gradiend/trainer/core/lr_search.py
search
Source code in gradiend/trainer/core/lr_search.py
LRSearchResult
dataclass
from_dict
classmethod
Inverse of :meth:to_dict (e.g. for a stored lr_search.json).
Source code in gradiend/trainer/core/lr_search.py
plot
Plot what the search did.
Every probe (a short training run) is one dot at its learning rate, numbered in the order it ran and coloured by
its state: blue too low, green converged, orange/red too high. The top panel shows the convergence score
(the correlation of the encoded value with the class) the probe reached; the bottom panel the weaker of the two
class means. A probe converges only if both reach their threshold (dotted lines). The green band is the
convergent range, the dashed line the chosen learning rate, and a ring marks a probe that was re-run for the full
max_steps. Needs matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Optional[str]
|
Optional path to save the figure to. |
None
|
show
|
bool
|
Whether to call |
True
|
title
|
Optional[str]
|
Optional title (default: the search status and the chosen learning rate). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The matplotlib figure. |
Source code in gradiend/trainer/core/lr_search.py
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 | |