code: def dsat_reporting_context(
      core_context: det.core._context.Context,
      op: det.core._searcher.SearcherOperation,
      steps_completed: Optional[int] = None,
  ) -> Generator[None, None, None]:
      """
      Context manager required for using Determined AI DeepSpeed Autotune with Core API.
  
      The `forward` and `step` methods of the DeepSpeed model engine must be called inside of this
      context manager.
  
      Args:
          core_context: a `Context` instance created with `determined.core.init`
          op: the first `SearcherOperation` instance generated by `core_context.searcher.operations`
  
      """
      if steps_completed is None:
          steps_completed = op.length
      try:
          yield
      except SystemExit as se:
          model_profiling_path = pathlib.Path(
              _defaults.MODEL_INFO_PROFILING_PATH
          )
          autotuning_results_path = pathlib.Path(
              _defaults.AUTOTUNING_RESULTS_PATH
          )
          possible_paths = [
              model_profiling_path,
              autotuning_results_path,
          ]
          existing_paths = [p for p in possible_paths if p.exists()]
          # Exactly one of these files should be generated for each properly exited DS AT Trial.
          if len(existing_paths) == 1:
              path = existing_paths[0]
              add_gpu_info = path == model_profiling_path
              report_json_results(
                  core_context=core_context,
                  op=op,
                  steps_completed=steps_completed,
                  add_gpu_info=add_gpu_info,
                  path=path,
              )
          raise se
  
imports: import argparse
  import copy
  import json
  import logging
  import pathlib
  import random
  from contextlib import contextmanager
  from typing import Any, Dict, Generator, List, Optional, Union
  import filelock
  import torch
  import determined
  from determined.common import util
  from determined.pytorch.dsat import _defaults
  from determined.util import merge_dicts
label_desc: Use image node_id 7 for calling a global function with example usage: dsat_reporting_context(core_context, op, steps_completed) without return types