Repository navigation
GPUlayer 0.10.0
Makes the Trainer behave like PyTorch Lightning, not only look like it: tests/conformance runs
the same code on both. Step time is unchanged on an M2 Pro CPU, -1.7% to +0.3% over four runs
(benchmarks/results/2026-11-07-m2pro-parity-fixes/). Read the Migration notes.
- Fix:
self.log(name, metric)with atorchmetrics.MetricraisedTypeError. The Trainer
now computes the metric once at the end of the epoch or evaluation and resets it; the
metric syncs across processes itself. No new dependency, and no added cost for tensors. - Fix:
Trainer(max_steps=N)andTrainer(max_time=...)silently stopped after one epoch,
becausemax_epochsdefaulted to 1;Trainer(min_epochs=5)stopped after one too. The
default is nowmax_epochs=None: epochs are unlimited whenmax_stepsormax_timeis
set, and otherwise one epoch (ormin_epochs), as before. Migration: runs with
max_stepslarger than one epoch now train longer;max_epochs=Nonepassed explicitly
meant 1000 epochs and now follows these rules (passmax_epochs=1000);max_epochs=-1
meant 1000 and now means no limit, as in Lightning. - Fix:
fit(ckpt_path="last")and"best"raisedFileNotFoundError."last"is now the
newestlast*.ckptof the Trainer, itsModelCheckpointfolders and the run folder (also
on a rerun, and in launched jobs); with none, training starts from scratch, as in Lightning. - Fix:
ModelCheckpoint()monitoredval_lossby default, and failed in a model that logged
another name. The default is nowmonitor=None(keep the latest), as in Lightning.
Migration: passmonitor="val_loss"to keep the best by that name. - Fix: a URL as
default_root_dir,ModelCheckpoint(dirpath=...)orsave_checkpointpath
was written to a local folder nameds3:, with no error, so a checkpoint could vanish with
the machine. Those paths,ckpt_path,load_from_checkpointandCSVLogger(save_dir=...)
now go throughfsspec(new extra:gpulayer[remote]), and a URL that cannot be served is
an error when the object is created. URLs with a password are refused. Tested with fsspec's
in-memory filesystem, not yet against S3, GCS or Azure. - Fix:
self.logoptions were ignored.on_stepwithon_epochnow gives<name>_stepand
<name>_epoch(soEarlyStopping("val_loss_epoch")works),logger=Falsekeeps a value from
the loggers, andtrainer.progress_bar_metricsandlogged_metricshold what Lightning's do.
Loggers get Lightning's rows: steps from 0 (a value logged atglobal_step2 is step 1), an
epochcolumn on every row, noepoch_seconds, and evaluation's per-step values under their
own counter. Values logged inon_*_epoch_endare combined across processes.
Migration:trainer.callback_metricsno longer hasepochandepoch_seconds, and a
name logged per step intraining_stepholds its last value (Lightning's), not the epoch
mean: log it withon_epoch=Trueand monitor<name>_epochfor the mean, or read
trainer.history.callback_metricsis cleared whenfit,validateorteststarts. - Fix: with
val_check_interval, validation also ran after the last batch of each epoch, and
ending a run withmax_stepswithin an epoch validated once more. Validation now runs at
the interval's multiples only (withval_check_interval=3and 10 batches: after 3, 6 and 9),
as in Lightning. - New: automatic resume (ADR-0025).
launch(max_attempts=N)and
Trainer(launch_options={"max_attempts": N})keep the job's newestlast.ckpton the control
plane while it runs, without making training wait, and start the next attempt from it after a
lost worker or a SIGTERM. Distributed jobs can now retry: the whole group restarts from the
checkpoint, after every rank of the old attempt has stopped. New:JobSpec.resume, the retry
reasonpreempted, andPOST /v1/worker/tasks/{id}/checkpoint. A job withresumeneeds 0.10
workers; other jobs run on any worker. Tested with real processes on one machine; not yet on
a reclaimed cloud VM.from-lightning.mdsaid SLURM's requeue was not needed, which
overstated what 0.9 did: retries started over. - New: exact resume. Checkpoints hold the random number generators and, in one process, a
resumed run gives bit-identical weights to one that never stopped (tested on CPU with dropout
and shuffling, at epoch ends and within an epoch). A run resumed within an epoch used to read
the trained batches again, in a new order, so some samples repeated and others were skipped;
it now rebuilds the order and skips them in the sampler, without reading them.torchdata's
StatefulDataLoaderis saved and restored, as in Lightning. Across processes the data order
is exact; each rank's own random numbers are not restored. - Fix: checkpoints work both ways with Lightning. A Lightning checkpoint saved within an epoch
lost the rest of that epoch, and one saved afterfitskipped an epoch;fitnow reads
Lightning's loop state. GPUlayer checkpoints load with Lightning'sload_from_checkpoint, and
gpulayer.pytorch.utilities.to_lightning_checkpointwrites one for Lightning'sfit.
Migration: afterfit, and inon_train_end,trainer.current_epochnow counts the
epochs run (Lightning's meaning): one more than before. New checkpoints havenext_epoch. - Fix (Trainer, Lightning semantics):
training_step(self, dataloader_iter)raisedTypeError; the step now pulls its own
batches as(batch, batch_idx, dataloader_idx). Intraining_steponly.Nonefromtraining_stepskippedon_train_batch_end, which now runs with empty
outputs, and the batch counts inglobal_step. Migration: step counts of models that
skip batches go up; schedulers andmax_stepscount those steps too.on_before_zero_gradran after the optimizer step; it now runs before backward. When no
model or callback overrides it oroptimizer_zero_grad, gradients are still freed after
on_train_batch_end, before the next forward pass, which Lightning does not do: peak memory
stays lower and nothing can observe the difference except code reading.gradinside
training_step.- A second
fitwith the same Trainer trained again. It now continues from where the first
stopped, so with its limits reached it does nothing, as in Lightning. Migration: raise
max_epochs, or use a new Trainer. self.logerrors as in Lightning: a tensor of several values (it was averaged), a call in
a hook nothing collects from (setup,configure_optimizers,on_fit_start,
on_fit_end,on_train_end,on_validation_end,on_test_end,teardown, ...), and the
same name twice in a step with different options.
- New:
trainer.strategyhasbarrier,broadcast,reduce,all_gather,
reduce_boolean_decision,root_device, the ranks,lightning_moduleandoptimizers;
trainer.fit_loop(max_epochscan be set),validate_loop,test_loop,predict_loop,
val_check_batch,lightning_module;Module.hparams_initial,prepare_data_per_node.
Migration:trainer.max_stepsis -1 without a limit (was None);limit_*_batchesdefault
to 1.0 (were None);num_val_batchesandnum_test_batchesare always lists; with one loader
trainer.val_dataloadersis that loader, not a list. - Docs: "every public name has a counterpart" was overstated.
scripts/compare_api.pyreads
source and missed instance attributes such asfit_loop, what classes inherit such as
hparams_initial, and thattrainer.strategylacked 58 of the 60 attributes of Lightning's.
Names are now compared on live objects intests/conformance. - New: notebooks.
Trainer(devices=N)in a Jupyter kernel forks one process per device and
returns the weights, instead of packaging the folder ofipykernel_launcher.py(all of
site-packages) as a job.launch()from a notebook now explains itself.ddp_notebookand
ddp_forkare accepted. Linux only, tested in CI against a real Jupyter kernel on CPU; not
run on a GPU. On macOS it stops with an explanation, because forks of a kernel crash there. - New: SLURM. Under
srun, tasks train in place with SLURM's ranks and the first node as
rendezvous, where each task used to submit its own job. Ansbatchscript orsrun --pty bashis not taken for a task. Simulated with SLURM's variables on one machine; not run on a
cluster. With--gpus-per-task, each task uses its only visible GPU. - New CI job and
tests/conformance: the same code runs on PyTorch Lightning and on the
Trainer and must behave the same; differences not fixed yet are listed as strictxfails.
pip install -e '.[conformance]'adds what it needs.