code: def train_loop_per_worker(config: dict):
      from torchvision.models import resnet18
  
      model = resnet18()
  
      # Checkpoint loading
      checkpoint: Optional[Checkpoint] = train.get_checkpoint()
      if checkpoint:
          with checkpoint.as_directory() as checkpoint_dir:
              model_state_dict = torch.load(
                  os.path.join(checkpoint_dir, "model.pt")
              )
              model.load_state_dict(model_state_dict)
  
      model = train.torch.prepare_model(model)
  
      train_ds = train.get_dataset_shard("train")
  
      for epoch in range(5):
          # Do some training...
  
          # Checkpoint saving
          with tempfile.TemporaryDirectory() as tmpdir:
              torch.save(
                  model.module.state_dict(),
                  os.path.join(tmpdir, "model.pt"),
              )
              train.report(
                  {"epoch": epoch},
                  checkpoint=Checkpoint.from_directory(tmpdir),
              )
  
file_path: ray/doc/source/train/doc_code/dl_guide.py
imports: import os
  import tempfile
  from typing import Dict, Optional
  import torch
  import ray
  from ray import train
  from ray.train import Checkpoint
  from ray.train.torch import TorchTrainer
  from ray.train.torch import TorchTrainer
label_desc: Use image node_id 2 for calling a global function with example usage: train_loop_per_worker(config) without return types