trainerERA5_multistep_concat
============================

.. py:module:: trainerERA5_multistep_concat


Attributes
----------

.. autoapisummary::

   trainerERA5_multistep_concat.logger


Classes
-------

.. autoapisummary::

   trainerERA5_multistep_concat.Trainer


Module Contents
---------------

.. py:data:: logger

.. py:class:: Trainer(model: torch.nn.Module, rank: int)

   Bases: :py:obj:`credit.trainers.base_trainer.BaseTrainer`


   Trainer class for handling the training, validation, and checkpointing of models.

   This class is responsible for executing the training loop, validating the model
   on a separate dataset, and managing checkpoints during training. It supports
   both single-GPU and distributed (FSDP, DDP) training.

   .. attribute:: model

      The model to be trained.

      :type: torch.nn.Module

   .. attribute:: rank

      The rank of the process in distributed training.

      :type: int

   .. attribute:: module

      If True, use model with module parallelism (default: False).

      :type: bool


   .. py:method:: train_one_epoch(epoch, conf, trainloader, optimizer, criterion, scaler, scheduler, metrics)

      Trains the model for one epoch.

      :param epoch: Current epoch number.
      :type epoch: int
      :param conf: Configuration dictionary containing training settings.
      :type conf: dict
      :param trainloader: DataLoader for the training dataset.
      :type trainloader: DataLoader
      :param optimizer: Optimizer used for training.
      :type optimizer: torch.optim.Optimizer
      :param criterion: Loss function used for training.
      :type criterion: callable
      :param scaler: Gradient scaler for mixed precision training.
      :type scaler: torch.cuda.amp.GradScaler
      :param scheduler: Learning rate scheduler.
      :type scheduler: torch.optim.lr_scheduler._LRScheduler
      :param metrics: Function to compute metrics for evaluation.
      :type metrics: callable

      :returns: Dictionary containing training metrics and loss for the epoch.
      :rtype: dict



   .. py:method:: validate(epoch, conf, valid_loader, criterion, metrics)

      Validates the model on the validation dataset.

      :param epoch: Current epoch number.
      :type epoch: int
      :param conf: Configuration dictionary containing validation settings.
      :type conf: dict
      :param valid_loader: DataLoader for the validation dataset.
      :type valid_loader: DataLoader
      :param criterion: Loss function used for validation.
      :type criterion: callable
      :param metrics: Function to compute metrics for evaluation.
      :type metrics: callable

      :returns: Dictionary containing validation metrics and loss for the epoch.
      :rtype: dict



