code: def test_trainer_callbacks(
      self, monkeypatch: monkeypatch.MonkeyPatch, tmp_path: pathlib.Path
  ) -> None:
      # there is no direct way to set tensorboard path in Trainer API
      def mock_get_tensorboard_path(
          dummy: typing.Dict[str, typing.Any]
      ) -> pathlib.Path:
          return tmp_path.joinpath("tensorboard")
  
      monkeypatch.setattr(
          pytorch.PyTorchTrialContext,
          "get_tensorboard_path",
          mock_get_tensorboard_path,
      )
  
      max_epochs = 2
      checkpoint_batches = 5
      validation_batches = 10
  
      with pytorch.init(hparams=self.hparams) as train_context:
          trial = pytorch_onevar_model.OneVarTrialCallbacks(
              train_context
          )
          trainer = pytorch.Trainer(trial, train_context)
          trainer.fit(
              max_length=pytorch.Epoch(2),
              checkpoint_period=pytorch.Batch(checkpoint_batches),
              validation_period=pytorch.Batch(validation_batches),
          )
  
      # Expect epochs * epoch_len / period if last batch is end of epoch,
      # else + 1 for last checkpoint/validation
      total_batches = max_epochs * train_context._epoch_len
      checkpoint_periods, batches_remaining = divmod(
          total_batches, checkpoint_batches
      )
      checkpoints = (
          checkpoint_periods + 1
          if batches_remaining > 0
          else checkpoint_periods
      )
      validation_periods, batches_remaining = divmod(
          total_batches, validation_batches
      )
      validations = (
          validation_periods + 1
          if batches_remaining > 0
          else validation_periods
      )
  
      workload_steps = max(checkpoints, validations)
  
      assert trial.counter.__dict__ == {
          "trial_startups": 1,
          "validation_steps_started": validations,
          "validation_steps_ended": validations,
          "checkpoints_written": checkpoints,
          "checkpoints_uploaded": checkpoints,
          "training_started_times": 1,
          "training_epochs_started": max_epochs,
          "training_epochs_ended": max_epochs,
          "training_workloads_ended": workload_steps,
          "trial_shutdowns": 1,
      }
  
      assert trial.legacy_counter.__dict__ == {
          "legacy_on_training_epochs_start_calls": 2
      }
  
imports: import contextlib
  import importlib
  import io
  import os
  import pathlib
  import sys
  import typing
  from unittest import mock
  import numpy
  import pytest
  import torch
  from _pytest import monkeypatch
  from torch.distributed import launcher
  import determined
  from determined import pytorch
  from tests.experiment import pytorch_utils, utils
  from tests.experiment.fixtures import pytorch_onevar_model
label_desc: Use image node_id 25 for calling the TestPyTorchTrial obj's underlying member method code with example usage: obj.test_trainer_callbacks(monkeypatch, tmp_path) and returns: tmp_path