Skip to content

GPUlayer 0.10.0

Choose a tag to compare

@antonellof antonellof released this 07 Nov 17:00
· 34 commits to main since this release

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 a torchmetrics.Metric raised TypeError. 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) and Trainer(max_time=...) silently stopped after one epoch,
    because max_epochs defaulted to 1; Trainer(min_epochs=5) stopped after one too. The
    default is now max_epochs=None: epochs are unlimited when max_steps or max_time is
    set, and otherwise one epoch (or min_epochs), as before. Migration: runs with
    max_steps larger than one epoch now train longer; max_epochs=None passed explicitly
    meant 1000 epochs and now follows these rules (pass max_epochs=1000); max_epochs=-1
    meant 1000 and now means no limit, as in Lightning.
  • Fix: fit(ckpt_path="last") and "best" raised FileNotFoundError. "last" is now the
    newest last*.ckpt of the Trainer, its ModelCheckpoint folders and the run folder (also
    on a rerun, and in launched jobs); with none, training starts from scratch, as in Lightning.
  • Fix: ModelCheckpoint() monitored val_loss by default, and failed in a model that logged
    another name. The default is now monitor=None (keep the latest), as in Lightning.
    Migration: pass monitor="val_loss" to keep the best by that name.
  • Fix: a URL as default_root_dir, ModelCheckpoint(dirpath=...) or save_checkpoint path
    was written to a local folder named s3:, with no error, so a checkpoint could vanish with
    the machine. Those paths, ckpt_path, load_from_checkpoint and CSVLogger(save_dir=...)
    now go through fsspec (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.log options were ignored. on_step with on_epoch now gives <name>_step and
    <name>_epoch (so EarlyStopping("val_loss_epoch") works), logger=False keeps a value from
    the loggers, and trainer.progress_bar_metrics and logged_metrics hold what Lightning's do.
    Loggers get Lightning's rows: steps from 0 (a value logged at global_step 2 is step 1), an
    epoch column on every row, no epoch_seconds, and evaluation's per-step values under their
    own counter. Values logged in on_*_epoch_end are combined across processes.
    Migration: trainer.callback_metrics no longer has epoch and epoch_seconds, and a
    name logged per step in training_step holds its last value (Lightning's), not the epoch
    mean: log it with on_epoch=True and monitor <name>_epoch for the mean, or read
    trainer.history. callback_metrics is cleared when fit, validate or test starts.
  • Fix: with val_check_interval, validation also ran after the last batch of each epoch, and
    ending a run with max_steps within an epoch validated once more. Validation now runs at
    the interval's multiples only (with val_check_interval=3 and 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 newest last.ckpt on 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
    reason preempted, and POST /v1/worker/tasks/{id}/checkpoint. A job with resume needs 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.md said 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
    StatefulDataLoader is 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 after fit skipped an epoch; fit now reads
    Lightning's loop state. GPUlayer checkpoints load with Lightning's load_from_checkpoint, and
    gpulayer.pytorch.utilities.to_lightning_checkpoint writes one for Lightning's fit.
    Migration: after fit, and in on_train_end, trainer.current_epoch now counts the
    epochs run (Lightning's meaning): one more than before. New checkpoints have next_epoch.
  • Fix (Trainer, Lightning semantics):
    • training_step(self, dataloader_iter) raised TypeError; the step now pulls its own
      batches as (batch, batch_idx, dataloader_idx). In training_step only.
    • None from training_step skipped on_train_batch_end, which now runs with empty
      outputs, and the batch counts in global_step. Migration: step counts of models that
      skip batches go up; schedulers and max_steps count those steps too.
    • on_before_zero_grad ran after the optimizer step; it now runs before backward. When no
      model or callback overrides it or optimizer_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 .grad inside
      training_step.
    • A second fit with 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.log errors 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.strategy has barrier, broadcast, reduce, all_gather,
    reduce_boolean_decision, root_device, the ranks, lightning_module and optimizers;
    trainer.fit_loop (max_epochs can be set), validate_loop, test_loop, predict_loop,
    val_check_batch, lightning_module; Module.hparams_initial, prepare_data_per_node.
    Migration: trainer.max_steps is -1 without a limit (was None); limit_*_batches default
    to 1.0 (were None); num_val_batches and num_test_batches are always lists; with one loader
    trainer.val_dataloaders is that loader, not a list.
  • Docs: "every public name has a counterpart" was overstated. scripts/compare_api.py reads
    source and missed instance attributes such as fit_loop, what classes inherit such as
    hparams_initial, and that trainer.strategy lacked 58 of the 60 attributes of Lightning's.
    Names are now compared on live objects in tests/conformance.
  • New: notebooks. Trainer(devices=N) in a Jupyter kernel forks one process per device and
    returns the weights, instead of packaging the folder of ipykernel_launcher.py (all of
    site-packages) as a job. launch() from a notebook now explains itself. ddp_notebook and
    ddp_fork are 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. An sbatch script or srun --pty bash is 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 strict xfails.
    pip install -e '.[conformance]' adds what it needs.

https://claude.ai/code/session_01JDdTtJNArexH5Jtvd6Bojr