class_docstr: ``pytorch.Trainer`` is an abstraction on top of a vanilla PyTorch training loop that handles
  many training details under-the-hood, and exposes APIs for configuring training-related features
  such as automatic checkpointing, validation, profiling, metrics reporting, etc.
  
  ``Trainer`` must be initialized and called from within a ``pytorch.PyTorchTrialContext``.
class_docstr_tok: ["``","pytorch.Trainer","``","is","an","abstraction","on","top","of","a","vanilla","PyTorch","training","loop","that","handles","many","training","details","under-the-hood",",","and","exposes","APIs","for","configuring","training-related","features","such","as","automatic","checkpointing",",","validation",",","profiling",",","metrics","reporting",",","etc",".","``","Trainer","``","must","be","initialized","and","called","from","within","a","``","pytorch.PyTorchTrialContext","``","."]
docstr: Configures the Determined profiler. This functionality is only supported for on-cluster
  training. For local training mode, this method is a no-op.
  
  This method should only be called before .fit(), and only once within the scope of init().
  If called multiple times, the last call's configuration will be used.
  
  Arguments:
      sync_timings: (Optional) Specifies whether Determined should wait for all GPU kernel
          streams before considering a timing as ended. Defaults to true. Applies only for
          frameworks that collect timing metrics (currently just PyTorch).
      enabled: (Optional) Defines whether profiles should be collected or not. Defaults to
          false.
      begin_on_batch: (Optional) Specifies the batch on which profiling should begin.
          Defaults to 0.
      end_after_batch: (Optional) Specifies the batch after which profiling should end.
  
  .. note::
  
     Profiles are collected for a maximum of 5 minutes, regardless of the settings above.
docstr_tok: ["Configures","the","Determined","profiler",".","This","functionality","is","only","supported","for","on-cluster","training",".","For","local","training","mode",",","this","method","is","a","no-op",".","This","method","should","only","be","called","before",".fit","(",")",",","and","only","once","within","the","scope","of","init","(",")",".","If","called","multiple","times",",","the","last","call","'s","configuration","will","be","used",".","Arguments",":","sync_timings",":","(","Optional",")","Specifies","whether","Determined","should","wait","for","all","GPU","kernel","streams","before","considering","a","timing","as","ended",".","Defaults","to","true",".","Applies","only","for","frameworks","that","collect","timing","metrics","(","currently","just","PyTorch",")",".","enabled",":","(","Optional",")","Defines","whether","profiles","should","be","collected","or","not",".","Defaults","to","false",".","begin_on_batch",":","(","Optional",")","Specifies","the","batch","on","which","profiling","should","begin",".","Defaults","to","0.","end_after_batch",":","(","Optional",")","Specifies","the","batch","after","which","profiling","should","end",".","..","note",":",":","Profiles","are","collected","for","a","maximum","of","5","minutes",",","regardless","of","the","settings","above","."]
code: def configure_profiler(
      self,
      sync_timings: bool = True,
      enabled: bool = False,
      begin_on_batch: int = 0,
      end_after_batch: Optional[int] = None,
  ) -> None:
      """
      Configures the Determined profiler. This functionality is only supported for on-cluster
      training. For local training mode, this method is a no-op.
  
      This method should only be called before .fit(), and only once within the scope of init().
      If called multiple times, the last call's configuration will be used.
  
      Arguments:
          sync_timings: (Optional) Specifies whether Determined should wait for all GPU kernel
              streams before considering a timing as ended. Defaults to true. Applies only for
              frameworks that collect timing metrics (currently just PyTorch).
          enabled: (Optional) Defines whether profiles should be collected or not. Defaults to
              false.
          begin_on_batch: (Optional) Specifies the batch on which profiling should begin.
              Defaults to 0.
          end_after_batch: (Optional) Specifies the batch after which profiling should end.
  
      .. note::
  
         Profiles are collected for a maximum of 5 minutes, regardless of the settings above.
  
      """
      if self._local_training:
          self._det_profiler = profiler.DummyProfilerAgent()
          return
  
      assert self._info, "Determined profiler must be run on cluster."
  
      self._det_profiler = profiler.ProfilerAgent(
          trial_id=str(self._info.trial.trial_id),
          agent_id=self._info.agent_id,
          master_url=self._info.master_url,
          profiling_is_enabled=enabled,
          global_rank=self._core.distributed.get_rank(),
          local_rank=self._core.distributed.get_local_rank(),
          begin_on_batch=begin_on_batch,
          end_after_batch=end_after_batch,
          sync_timings=sync_timings,
      )
  
file_path: determined/harness/determined/pytorch/_trainer.py
imports: import contextlib
  import logging
  import random
  import sys
  from typing import Any, Dict, Iterator, Optional
  import numpy
  import torch
  import torch.distributed
  import determined
  from determined import core, gpu, horovod, profiler, pytorch
  from determined.horovod import hvd
label_desc: Use image node_id 2 for calling the Trainer obj's underlying member method code with example usage: obj.configure_profiler(sync_timings, enabled, begin_on_batch, end_after_batch) without return types