code: def __init__(
      self,
      dataset: MetaDataset,
      model: nn.Module,
      optimizer: partial,
      scheduler: Optional[partial],
      metrics: MeterDict,
      callbacks: List[Callback],
      log_dir: Union[Path, str],
      n_epochs: int,
      nb_epoch: Optional[int],
      batch_size: Union[int, Tuple[int, int]],
      n_loader_workers: int = 0,
      cuda_device: int = 0,
      debug: bool = False,
  ) -> None:
      self.dataset = dataset
      self.cuda_device = cuda_device if pt.cuda.is_available() else -1
      if self.cuda_device >= 0:
          pt.cuda.set_device(self.cuda_device)
          self.model = model.cuda(self.cuda_device)
      else:
          self.model = model.cpu()
      if is_distributed():
          device_ids = (
              None if self.cuda_device < 0 else [self.cuda_device]
          )
          self.model = DistributedDataParallel(
              self.model, device_ids=device_ids
          )
      self.optimizer = optimizer(self.model.parameters())
      if scheduler is None:
          self.scheduler = None
      else:
          self.scheduler = scheduler(self.optimizer)
      self.metrics = metrics
      self.register_callback(*callbacks)
      self.log_dir = (
          Path(log_dir) if isinstance(log_dir, str) else log_dir
      )
      self.n_epochs = n_epochs
      self.nb_epoch = nb_epoch
      if isinstance(batch_size, int):
          self.batch_size = self.eval_batch_size = batch_size
      else:
          self.batch_size, self.eval_batch_size = batch_size
      self.n_loader_workers = n_loader_workers
      self.debug = debug
  
      self.global_step = 0
      self._signal_exit = False
      self._signal_break = False
      self._signal_valid_break = False
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Optional, Union, Tuple, List, Iterator
  from pathlib import Path
  from functools import partial
  from copy import deepcopy
  import math
  import torch
  from torch import nn
  from torch.nn.parallel import DistributedDataParallel
  from tqdm import tqdm
  from .callback import Callback, CallbackList, Optimization, DebugStopper
  from .distributed import is_distributed, synchronize, is_main_process
label_desc: Use image node_id 1 to create a new Trainer object from inherited base classes: object with example: obj = Trainer(dataset, model, optimizer, scheduler, metrics, callbacks, log_dir, n_epochs, nb_epoch, batch_size, n_loader_workers, cuda_device, debug)