class_docstr: A `Trainer` is used to train a pytorch model.
  
  Args:
      model (`nn.Module`):
          A pytorch model.
      training_config (`TrainingConfig`):
          A `TrainingConfig` instance can be loaded from a yaml file.
      train_dataset (`Union[Dataset, TowheeDataSet]`):
          It can be a kind of `torch.utils.data.dataset.Dataset` or `TowheeDataSet`
      eval_dataset (`Union[Dataset, TowheeDataSet]`):
          The same as `train_dataset`, and it is not strictly necessary if you do not want to eval.
      train_dataloader (`Union[DataLoader, Iterable]`):
          When the `train_dataloader` is passed in, trainer will use it to load data
          instead of constructing by input dataset.
      eval_dataloader (`Union[DataLoader, Iterable]`):
          The same as `train_dataloader`, and it is not strictly necessary also.
      model_card (`ModelCard`):
          Model card may contain other information of a model, and it is not strictly necessary.
  
  Examples:
      >>> import torch
      >>> import torchvision.models as models
      >>> from towhee.trainer.trainer import Trainer
      >>> from towhee.trainer.training_config import TrainingConfig
      >>> from towhee import dataset
      >>> from torchvision import transforms
      >>> import warnings
      >>> warnings.filterwarnings("ignore")
      >>> model = models.resnet18()
      >>> fake_transform = transforms.Compose([transforms.ToTensor()])
      >>> train_data = dataset('fake', size=2, transform=fake_transform)
      >>> val_data = dataset('fake', size=1, transform=fake_transform)
      >>> training_config = TrainingConfig(output_dir="train_res",
      ...                                  tensorboard=None,
      ...                                  epoch_num=2,
      ...                                  batch_size=1,
      ...                                  dataloader_num_workers=0,
      ...                                  print_steps=1)
      >>> trainer = Trainer(model, training_config, train_dataset=train_data, eval_dataset=val_data)
      >>> type(trainer)
      <class 'towhee.trainer.trainer.Trainer'>
      >>> trainer.train()  # Some values below are not necessarily reproducible
      2022-03-01 19:01:54,314 - 8601085440 - trainer.py-trainer:324 - WARNING: TrainingConfig(...)
      epoch=1/2, global_step=1, epoch_loss=7.107283592224121, epoch_metric=0.0
      epoch=1/2, global_step=2, epoch_loss=6.959554195404053, epoch_metric=0.0
      epoch=1/2, eval_global_step=0, eval_epoch_loss=6.694866180419922, eval_epoch_metric=0.0
      epoch=2/2, global_step=3, epoch_loss=6.165490627288818, epoch_metric=0.0
      epoch=2/2, global_step=4, epoch_loss=6.197325706481934, epoch_metric=0.0
      epoch=2/2, eval_global_step=1, eval_epoch_loss=6.0876030921936035, eval_epoch_metric=0.0
      >>> trainer.train(resume_checkpoint_path="train_res/epoch_1")
      2022-03-01 19:01:57,004 - 8601085440 - trainer.py-trainer:324 - WARNING: TrainingConfig(...)
      epoch=2/2, global_step=1, epoch_loss=6.165490627288818, epoch_metric=0.0
      epoch=2/2, global_step=2, epoch_loss=6.277336120605469, epoch_metric=0.0
      epoch=2/2, eval_global_step=0, eval_epoch_loss=6.097333908081055, eval_epoch_metric=0.0
      >>> trainer.save(path="another_save_path")
      >>> trainer.load(path="another_save_path")
      >>> trainer.epoch
      2
      >>> model = models.resnet18()
      >>> inputs = [torch.randn(1, 3, 224, 224), torch.Tensor([1]).type(torch.LongTensor)]
      >>> model.eval()  # turn on eval mode
      ResNet(
      ...
      )
      >>> trainer.evaluate_step(model, inputs)
      {'eval_step_loss': 7.10837459564209, 'eval_epoch_loss': 6.350093841552734, 'eval_epoch_metric': 0.0}
      >>> trainer.update_metrics(model, inputs, torch.Tensor(1))
      (5.2800750732421875, 0.0)
      >>> trainer.compute_metric(model, inputs)
      0.0
      >>> trainer.evaluate(model, {"epoch": 1, "eval_global_step": 1})
      epoch=1/2, eval_global_step=1, eval_epoch_loss=5.654547214508057, eval_epoch_metric=0.0
      {'epoch': 1, 'eval_global_step': 2, 'eval_step_loss': 7.526906967163086, 'eval_epoch_loss': 5.654547214508057, 'eval_epoch_metric': 0.0}
      >>> trainer.predict(inputs[0]).shape
      torch.Size([1, 1000])
      >>> model.train()  # turn on train mode
      ResNet(
      ...
      )
      >>> trainer.train_step(model, inputs)
      {'step_loss': 7.10837459564209, 'epoch_loss': 5.862236976623535, 'epoch_metric': 0.0}
      >>> trainer.compute_loss(model, inputs)
      tensor(7.1084, grad_fn=<NllLossBackward>)
      >>>
      >>> from towhee.trainer.callback import Callback
      >>> from typing import Dict
      >>> class MyCallback(Callback):
      ...     def on_eval_begin(self, logs: Dict) -> Dict:
      ...         print("on_eval_begin...")
      ...
      >>> my_callback = MyCallback()
      >>> trainer.add_callback(my_callback)
      >>> trainer.evaluate(model, logs={"epoch": 1, "eval_global_step": 1})
      on_eval_begin...
      epoch=1/2, eval_global_step=1, eval_epoch_loss=6.070321083068848, eval_epoch_metric=0.0
      {'epoch': 1, 'eval_global_step': 2, 'eval_step_loss': 7.526906967163086, 'eval_epoch_loss': 6.070321083068848, 'eval_epoch_metric': 0.0}
docstr: Start to train.
  Args:
      resume_checkpoint_path (`int`):
          The path to start resume training.
docstr_tok: ["Start","to","train",".","Args",":","resume_checkpoint_path","(","`","int","`",")",":","The","path","to","start","resume","training","."]
code: def train(self, resume_checkpoint_path: Optional[str] = None):
      """
      Start to train.
      Args:
          resume_checkpoint_path (`int`):
              The path to start resume training.
      """
      self._run_train(resume_checkpoint_path)
  
imports: import math
  import os
  import torch
  from typing import Union, Any, Optional
  from pathlib import Path
  from collections.abc import Iterable
  from torch import nn
  from torch import optim
  from torch.optim import Optimizer
  from torch.utils.data.dataloader import DataLoader
  from torch.utils.data.dataset import Dataset
  from towhee.data.dataset.dataset import TowheeDataSet, TorchDataSet
  from towhee.trainer.callback import TensorBoardCallBack, ProgressBarCallBack, PrintCallBack, ModelCheckpointCallback, EarlyStoppingCallback, TrainerControl, Callback
  from towhee.trainer.metrics import get_metric_by_name
  from towhee.trainer.modelcard import ModelCard, MODEL_CARD_NAME
  from towhee.trainer.utils.trainer_utils import STATE_CHECKPOINT_NAME, MODEL_NAME, set_seed, reduce_value, is_main_process, send_to_device, unwrap_model, _construct_loss_from_config, _construct_optimizer_from_config, _construct_scheduler_from_config
  from towhee.trainer.training_config import TrainingConfig
  from towhee.utils.log import trainer_log
  from towhee.trainer.optimization.optimization import get_scheduler, get_warmup_steps
  from towhee.trainer.callback import CallbackList, _get_summary_writer_constructor
label_desc: Use image node_id 2 for calling the Trainer obj's underlying member method code with example usage: obj.train(resume_checkpoint_path) without return types