class_docstr: A list of Events (for pretty printing).
class_docstr_tok: ["A","list","of","Events","(","for","pretty","printing",")","."]
docstr: Averages all function events over their keys.
  
  Args:
      group_by_input_shapes: group entries by
          (event name, input shapes) rather than just event name.
          This is useful to see which input shapes contribute to the runtime
          the most and may help with size-specific optimizations or
          choosing the best candidates for quantization (aka fitting a roof line)
  
      group_by_stack_n: group by top n stack trace entries
  
  Returns:
      An EventList containing FunctionEventAvg objects.
docstr_tok: ["Averages","all","function","events","over","their","keys",".","Args",":","group_by_input_shapes",":","group","entries","by","(","event","name",",","input","shapes",")","rather","than","just","event","name",".","This","is","useful","to","see","which","input","shapes","contribute","to","the","runtime","the","most","and","may","help","with","size-specific","optimizations","or","choosing","the","best","candidates","for","quantization","(","aka","fitting","a","roof","line",")","group_by_stack_n",":","group","by","top","n","stack","trace","entries","Returns",":","An","EventList","containing","FunctionEventAvg","objects","."]
code: def key_averages(
      self, group_by_input_shapes=False, group_by_stack_n=0
  ):
      """Averages all function events over their keys.
  
      Args:
          group_by_input_shapes: group entries by
              (event name, input shapes) rather than just event name.
              This is useful to see which input shapes contribute to the runtime
              the most and may help with size-specific optimizations or
              choosing the best candidates for quantization (aka fitting a roof line)
  
          group_by_stack_n: group by top n stack trace entries
  
      Returns:
          An EventList containing FunctionEventAvg objects.
      """
      assert self._tree_built
      stats: Dict[Tuple[str, ...], FunctionEventAvg] = defaultdict(
          FunctionEventAvg
      )
  
      def get_key(
          event, group_by_input_shapes, group_by_stack_n
      ) -> Tuple[str, ...]:
          key = [
              str(event.key),
              str(event.node_id),
              str(event.device_type),
              str(event.is_legacy),
          ]
          if group_by_input_shapes:
              key.append(str(event.input_shapes))
          if group_by_stack_n > 0:
              key += event.stack[:group_by_stack_n]
          return tuple(key)
  
      for evt in self:
          stats[
              get_key(evt, group_by_input_shapes, group_by_stack_n)
          ].add(evt)
  
      avg_list = EventList(
          stats.values(),
          use_cuda=self._use_cuda,
          use_device=self._use_device,
          profile_memory=self._profile_memory,
          with_flops=self._with_flops,
      )
      for evt in avg_list:
          evt.stack = evt.stack[:group_by_stack_n]
          if not group_by_input_shapes:
              evt.input_shapes = ""
      return avg_list
  
imports: import bisect
  import itertools
  import math
  from collections import defaultdict, namedtuple
  from operator import attrgetter
  from typing import Any, Dict, List, Optional, Tuple
  import torch
  from torch.autograd import DeviceType
label_desc: Use image node_id 12 for calling the EventList obj's underlying member method code with example usage: obj.key_averages(group_by_input_shapes, group_by_stack_n) and returns: avg_list, tuple