class_docstr: Used to average stats over multiple FunctionEvent objects.
class_docstr_tok: ["Used","to","average","stats","over","multiple","FunctionEvent","objects","."]
code: def add(self, other):
      if self.key is None:
          # First function being recorded as part of FunctionEventAvg, propagate
          # fields.
          self.key = other.key
          self.node_id = other.node_id
          self.is_async = other.is_async
          self.is_remote = other.is_remote
          self.cpu_parent = other.cpu_parent
          self.cpu_children = other.cpu_children
  
          self.input_shapes = other.input_shapes
          self.stack = other.stack
          self.scope = other.scope
          self.device_type = other.device_type
          self.is_legacy = other.is_legacy
          self.use_device = other.use_device
  
      assert isinstance(other, (FunctionEvent, FunctionEventAvg))
      assert other.key == self.key
      self.cpu_time_total += other.cpu_time_total
      self.cuda_time_total += other.cuda_time_total
      self.privateuse1_time_total += other.privateuse1_time_total
      self.self_cpu_time_total += other.self_cpu_time_total
      self.self_cuda_time_total += other.self_cuda_time_total
      self.self_privateuse1_time_total += (
          other.self_privateuse1_time_total
      )
      self.cpu_memory_usage += other.cpu_memory_usage
      self.cuda_memory_usage += other.cuda_memory_usage
      self.privateuse1_memory_usage += other.privateuse1_memory_usage
      self.self_cpu_memory_usage += other.self_cpu_memory_usage
      self.self_cuda_memory_usage += other.self_cuda_memory_usage
      self.self_privateuse1_memory_usage += (
          other.self_privateuse1_memory_usage
      )
      self.count += other.count
      if self.flops is None:
          self.flops = other.flops
      elif other.flops is not None:
          self.flops += other.flops
      return self
  
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 2 for calling the FunctionEventAvg obj's underlying member method code with example usage: obj.add(other) and returns: self