code: def _load_pytorch_trial_with_shims(
      context_dir: pathlib.Path,
      managed_training: bool,
      trial_cls_spec: str,
      config: Dict[str, Any],
      hparams: Dict[str, Any],
  ) -> Tuple[Type[pytorch.PyTorchTrial], pytorch.PyTorchTrialContext]:
      with det._local_execution_manager(context_dir):
          trial_class = cast(
              Type[pytorch.PyTorchTrial],
              load.trial_class_from_entrypoint(trial_cls_spec),
          )
  
          config = det.ExperimentConfig(
              det._make_local_execution_exp_config(
                  config,
                  "/tmp",
                  managed_training=managed_training,
                  test_mode=False,
              )
          )
          use_gpu, container_gpus, slot_ids = det._get_gpus(
              limit_gpus=False
          )
          fp16_compression = bool(
              config.get_optimizations_config().get(
                  "gradient_compression", False
              )
          )
          average_aggregated_gradients = bool(
              config.average_training_metrics_enabled()
          )
  
          trial_context = pytorch.PyTorchTrialContext(
              core_context=core._dummy_init(),
              trial_seed=config.experiment_seed(),
              hparams=hparams,
              slots_per_trial=config.slots_per_trial(),
              num_gpus=len(container_gpus),
              exp_conf=config,
              aggregation_frequency=int(
                  config.get_optimizations_config().get(
                      "aggregation_frequency", 1
                  )
              ),
              steps_completed=0,
              managed_training=managed_training,
              debug_enabled=False,
          )
          trial_context._set_default_gradient_compression(
              fp16_compression
          )
          trial_context._set_default_average_aggregated_gradients(
              average_aggregated_gradients
          )
  
      return trial_class, trial_context
  
file_path: determined/harness/determined/pytorch/_load.py
imports: import json
  import logging
  import pathlib
  import warnings
  from typing import Any, Dict, Optional, Tuple, Type, cast
  import torch
  import determined
  from determined import core, errors, load, pytorch, util
label_desc: Use image node_id 2 for calling a global function with example usage: _load_pytorch_trial_with_shims(context_dir, managed_training, trial_cls_spec, config, hparams) and returns: trial_class,  trial_context