code: def test_callbacks(self, tmp_path: pathlib.Path) -> None:
      checkpoint_dir = tmp_path.joinpath("checkpoint")
      tensorboard_path = tmp_path.joinpath("tensorboard")
  
      hparams1 = dict(self.hparams)
      hparams1["global_batch_size"] = 2
      training_epochs = 2
      num_batches = (
          training_epochs
          * len(pytorch_onevar_model.OnesDataset())
          // hparams1["global_batch_size"]
      )
  
      (
          trial,
          trial_controller,
      ) = pytorch_utils.create_trial_and_trial_controller(
          trial_class=pytorch_onevar_model.OneVarTrialCallbacks,
          hparams=hparams1,
          checkpoint_dir=str(checkpoint_dir),
          tensorboard_path=tensorboard_path,
          max_batches=num_batches,
          min_checkpoint_batches=sys.maxsize,
          min_validation_batches=sys.maxsize,
          scheduling_unit=sys.maxsize,
      )
  
      trial_controller.run()
  
      # Expect 2 training epochs, 1 validation step, and one checkpoint step
      assert trial.counter.__dict__ == {
          "trial_startups": 1,
          "validation_steps_started": 1,
          "validation_steps_ended": 1,
          "checkpoints_written": 1,
          "checkpoints_uploaded": 1,
          "training_started_times": 1,
          "training_epochs_started": 2,
          "training_epochs_ended": 2,
          "training_workloads_ended": 1,
          "trial_shutdowns": 1,
      }
      assert trial.legacy_counter.__dict__ == {
          "legacy_on_training_epochs_start_calls": 2
      }
  
      (
          trial,
          trial_controller,
      ) = pytorch_utils.create_trial_and_trial_controller(
          trial_class=pytorch_onevar_model.OneVarTrialCallbacks,
          hparams=hparams1,
          checkpoint_dir=str(checkpoint_dir),
          tensorboard_path=tensorboard_path,
          max_batches=num_batches,
          min_checkpoint_batches=sys.maxsize,
          min_validation_batches=num_batches // 2,
          scheduling_unit=sys.maxsize,
      )
      trial_controller.run()
  
      # Expect 1 training step,
      # 2 validation steps (1 specified + 1 from training finish),
      # 2 checkpoint steps (1 from validation + 1 from training finish)
      assert trial.counter.__dict__ == {
          "trial_startups": 1,
          "validation_steps_started": 2,
          "validation_steps_ended": 2,
          "checkpoints_written": 2,
          "checkpoints_uploaded": 2,
          "training_started_times": 1,
          "training_epochs_started": 2,
          "training_epochs_ended": 2,
          "training_workloads_ended": 2,
          "trial_shutdowns": 1,
      }
      assert trial.legacy_counter.__dict__ == {
          "legacy_on_training_epochs_start_calls": 2
      }
  
      (
          trial,
          trial_controller,
      ) = pytorch_utils.create_trial_and_trial_controller(
          trial_class=pytorch_onevar_model.OneVarTrialCallbacks,
          hparams=hparams1,
          checkpoint_dir=str(checkpoint_dir),
          tensorboard_path=tensorboard_path,
          max_batches=num_batches,
          min_checkpoint_batches=num_batches // 2,
          min_validation_batches=sys.maxsize,
          scheduling_unit=sys.maxsize,
      )
      trial_controller.run()
  
      # Expect 2 training steps (1 from checkpoint + 1 from training finish),
      # 1 validation steps (1 from training finish),
      # 2 checkpoint steps (1 from specified + 1 from training finish)
      assert trial.counter.__dict__ == {
          "trial_startups": 1,
          "validation_steps_started": 1,
          "validation_steps_ended": 1,
          "checkpoints_written": 2,
          "checkpoints_uploaded": 2,
          "training_started_times": 1,
          "training_epochs_started": 2,
          "training_epochs_ended": 2,
          "training_workloads_ended": 2,
          "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 12 for calling the TestPyTorchTrial obj's underlying member method code with example usage: obj.test_callbacks(tmp_path) without return types