docstr: Similar to test_amp but with gradient aggregation.
code: def test_amp_with_gradient_aggregation(
      self, tmp_path: pathlib.Path, trial_class
  ) -> None:
      """Similar to test_amp but with gradient aggregation."""
      tensorboard_path = tmp_path.joinpath("tensorboard")
  
      if (
          trial_class is pytorch_onevar_model.OneVarApexAMPTrial
          and not HAVE_APEX
      ):
          pytest.skip("Apex not available")
  
      # The assertions logic in make_amp_workloads require a batch size of one
      hparams = dict(self.hparams)
      hparams["global_batch_size"] = 1
      aggregation_frequency = 2
  
      exp_config = utils.make_default_exp_config(
          hparams,
          scheduling_unit=1,
          searcher_metric=trial_class._searcher_metric,
      )
  
      (
          trial,
          trial_controller,
      ) = pytorch_utils.create_trial_and_trial_controller(
          exp_config=exp_config,
          trial_class=trial_class,
          hparams=hparams,
          trial_seed=self.trial_seed,
          expose_gpus=True,
          max_batches=20 * aggregation_frequency,
          min_validation_batches=1,
          min_checkpoint_batches=sys.maxsize,
          tensorboard_path=tensorboard_path,
          aggregation_frequency=aggregation_frequency,
      )
      trial_controller.run()
  
      metrics_callback = trial.metrics_callback
      training_metrics = metrics_callback.training_metrics
  
      amp_metrics_test(
          trial_class, training_metrics, agg_freq=aggregation_frequency
      )
  
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 22 for calling the TestPyTorchTrial obj's underlying member method code with example usage: obj.test_amp_with_gradient_aggregation(tmp_path, trial_class) without return types