code: def set_logs(
      *,
      all: Optional[int] = None,
      dynamo: Optional[int] = None,
      aot: Optional[int] = None,
      autograd: Optional[int] = None,
      dynamic: Optional[int] = None,
      inductor: Optional[int] = None,
      distributed: Optional[int] = None,
      dist_c10d: Optional[int] = None,
      dist_ddp: Optional[int] = None,
      dist_fsdp: Optional[int] = None,
      onnx: Optional[int] = None,
      bytecode: bool = False,
      aot_graphs: bool = False,
      aot_joint_graph: bool = False,
      ddp_graphs: bool = False,
      graph: bool = False,
      graph_code: bool = False,
      graph_breaks: bool = False,
      graph_sizes: bool = False,
      guards: bool = False,
      recompiles: bool = False,
      recompiles_verbose: bool = False,
      trace_source: bool = False,
      trace_call: bool = False,
      output_code: bool = False,
      schedule: bool = False,
      perf_hints: bool = False,
      post_grad_graphs: bool = False,
      onnx_diagnostics: bool = False,
      fusion: bool = False,
      overlap: bool = False,
      export: Optional[int] = None,
      modules: Optional[Dict[str, Union[int, bool]]] = None,
  ):
      """
      Sets the log level for individual components and toggles individual log
      artifact types.
  
      .. warning:: This feature is a prototype and may have compatibility
          breaking changes in the future.
  
      .. note:: The ``TORCH_LOGS`` environment variable has complete precedence
          over this function, so if it was set, this function does nothing.
  
      A component is a set of related features in PyTorch. All of the log
      messages emitted from a given component have their own log levels. If the
      log level of a particular message has priority greater than or equal to its
      component's log level setting, it is emitted. Otherwise, it is supressed.
      This allows you to, for instance, silence large groups of log messages that
      are not relevant to you and increase verbosity of logs for components that
      are relevant. The expected log level values, ordered from highest to lowest
      priority, are:
  
          * ``logging.CRITICAL``
          * ``logging.ERROR``
          * ``logging.WARNING``
          * ``logging.INFO``
          * ``logging.DEBUG``
          * ``logging.NOTSET``
  
      See documentation for the Python ``logging`` module for more information on
      log levels: `<https://docs.python.org/3/library/logging.html#logging-levels>`_
  
      An artifact is a particular type of log message. Each artifact is assigned
      to a parent component. A component can emit many different kinds of
      artifacts. In general, an artifact is emitted if either its corresponding
      setting in the argument list below is turned on or if its parent component
      is set to a log level less than or equal to the log level of the artifact.
  
      Keyword args:
          all (:class:`Optional[int]`):
              The default log level for all components. Default: ``logging.WARN``
  
          dynamo (:class:`Optional[int]`):
              The log level for the TorchDynamo component. Default: ``logging.WARN``
  
          aot (:class:`Optional[int]`):
              The log level for the AOTAutograd component. Default: ``logging.WARN``
  
          autograd (:class:`Optional[int]`):
              The log level for autograd. Default: ``logging.WARN``
  
          inductor (:class:`Optional[int]`):
              The log level for the TorchInductor component. Default: ``logging.WARN``
  
          dynamic (:class:`Optional[int]`):
              The log level for dynamic shapes. Default: ``logging.WARN``
  
          distributed (:class:`Optional[int]`):
              Whether to log c10d communication operations and other debug info from PyTorch Distributed components.
              Default: ``logging.WARN``
  
          dist_c10d (:class:`Optional[int]`):
              Whether to log c10d communication operations related debug info in PyTorch Distributed components.
              Default: ``logging.WARN``
  
          dist_ddp (:class:`Optional[int]`):
              Whether to log debug info related to ``DistributedDataParallel``(DDP) from PyTorch Distributed components.
              Default: ``logging.WARN``
  
          dist_fsdp (:class:`Optional[int]`):
              Whether to log debug info related to ``FullyShardedDataParallel``(FSDP) in PyTorch Distributed components.
              Default: ``logging.WARN``
  
          onnx (:class:`Optional[int]`):
              The log level for the ONNX exporter component. Default: ``logging.WARN``
  
          bytecode (:class:`bool`):
              Whether to emit the original and generated bytecode from TorchDynamo.
              Default: ``False``
  
          aot_graphs (:class:`bool`):
              Whether to emit the graphs generated by AOTAutograd. Default: ``False``
  
          aot_joint_graph (:class:`bool`):
              Whether to emit the joint forward-backward graph generated by AOTAutograd. Default: ``False``
  
          ddp_graphs (:class:`bool`):
              Whether to emit graphs generated by DDPOptimizer. Default: ``False``
  
          graph (:class:`bool`):
              Whether to emit the graph captured by TorchDynamo in tabular format.
              Default: ``False``
  
          graph_code (:class:`bool`):
              Whether to emit the python source of the graph captured by TorchDynamo.
              Default: ``False``
  
          graph_breaks (:class:`bool`):
              Whether to emit the graph breaks encountered by TorchDynamo.
              Default: ``False``
  
          graph_sizes (:class:`bool`):
              Whether to emit tensor sizes of the graph captured by TorchDynamo.
              Default: ``False``
  
          guards (:class:`bool`):
              Whether to emit the guards generated by TorchDynamo for each compiled
              function. Default: ``False``
  
          recompiles (:class:`bool`):
              Whether to emit a guard failure reason and message every time
              TorchDynamo recompiles a function. Default: ``False``
  
          recompiles_verbose (:class:`bool`):
              Whether to emit all guard failure reasons when TorchDynamo recompiles
              a function, even those that are not actually run. Default: ``False``
  
          trace_source (:class:`bool`):
              Whether to emit when TorchDynamo begins tracing a new line. Default: ``False``
  
          trace_call (:class:`bool`):
              Whether to emit detailed line location when TorchDynamo creates an FX node
              corresponding to function call. Python 3.11+ only. Default: ``False``
  
          output_code (:class:`bool`):
              Whether to emit the TorchInductor output code. Default: ``False``
  
          schedule (:class:`bool`):
              Whether to emit the TorchInductor schedule. Default: ``False``
  
          perf_hints (:class:`bool`):
              Whether to emit the TorchInductor perf hints. Default: ``False``
  
          post_grad_graphs (:class:`bool`):
              Whether to emit the graphs generated by after post grad passes. Default: ``False``
  
          onnx_diagnostics (:class:`bool`):
              Whether to emit the ONNX exporter diagnostics in logging. Default: ``False``
  
          fusion (:class:`bool`):
              Whether to emit detailed Inductor fusion decisions. Default: ``False``
  
          overlap (:class:`bool`):
              Whether to emit detailed Inductor compute/comm overlap decisions. Default: ``False``
  
          export (:class:`Optional[int]`):
              The log level for export. Default: ``logging.WARN``
  
          modules (dict):
              This argument provides an alternate way to specify the above log
              component and artifact settings, in the format of a keyword args
              dictionary given as a single argument. There are two cases
              where this is useful (1) if a new log component or artifact has
              been registered but a keyword argument for it has not been added
              to this function and (2) if the log level for an unregistered module
              needs to be set. This can be done by providing the fully-qualified module
              name as the key, with the log level as the value. Default: ``None``
  
  
      Example::
  
          >>> # xdoctest: +SKIP
          >>> import logging
  
          # The following changes the "dynamo" component to emit DEBUG-level
          # logs, and to emit "graph_code" artifacts.
  
          >>> torch._logging.set_logs(dynamo=logging.DEBUG, graph_code=True)
  
          # The following enables the logs for a different module
  
          >>> torch._logging.set_logs(modules={"unregistered.module.name": logging.DEBUG})
      """
      # ignore if env var is set
      if LOG_ENV_VAR in os.environ:
          log.warning(
              "Using TORCH_LOGS environment variable for log settings, ignoring call to set_logs"
          )
          return
  
      log_state.clear()
  
      modules = modules or {}
  
      def _set_logs(**kwargs):
          for alias, val in itertools.chain(kwargs.items(), modules.items()):  # type: ignore[union-attr]
              if val is None:
                  continue
  
              if log_registry.is_artifact(alias):
                  if not isinstance(val, bool):
                      raise ValueError(
                          f"Expected bool to enable artifact {alias}, received {val}"
                      )
  
                  if val:
                      log_state.enable_artifact(alias)
              elif (
                  log_registry.is_log(alias)
                  or alias in log_registry.child_log_qnames
              ):
                  if val not in logging._levelToName:
                      raise ValueError(
                          f"Unrecognized log level for log {alias}: {val}, valid level values "
                          f"are: {','.join([str(k) for k in logging._levelToName.keys()])}"
                      )
  
                  log_state.enable_log(
                      log_registry.log_alias_to_log_qnames.get(
                          alias, alias
                      ),
                      val,
                  )
              else:
                  raise ValueError(
                      f"Unrecognized log or artifact name passed to set_logs: {alias}"
                  )
  
          _init_logs()
  
      _set_logs(
          torch=all,
          dynamo=dynamo,
          aot=aot,
          autograd=autograd,
          inductor=inductor,
          dynamic=dynamic,
          bytecode=bytecode,
          aot_graphs=aot_graphs,
          aot_joint_graph=aot_joint_graph,
          ddp_graphs=ddp_graphs,
          distributed=distributed,
          dist_c10d=dist_c10d,
          dist_ddp=dist_ddp,
          dist_fsdp=dist_fsdp,
          graph=graph,
          graph_code=graph_code,
          graph_breaks=graph_breaks,
          graph_sizes=graph_sizes,
          guards=guards,
          recompiles=recompiles,
          recompiles_verbose=recompiles_verbose,
          trace_source=trace_source,
          trace_call=trace_call,
          output_code=output_code,
          schedule=schedule,
          perf_hints=perf_hints,
          post_grad_graphs=post_grad_graphs,
          onnx=onnx,
          onnx_diagnostics=onnx_diagnostics,
          fusion=fusion,
          overlap=overlap,
          export=export,
      )
  
imports: import functools
  import itertools
  import logging
  import os
  import re
  from dataclasses import dataclass, field
  from importlib import __import__
  from typing import Dict, List, Optional, Set, Union
  from weakref import WeakSet
  import torch._guards
  import torch.distributed
label_desc: Use image node_id 1 for calling a global function with example usage: set_logs() without return types