class_docstr: Determines whether there are significant outliers in activation data around a certain layer.
  
  This is ideally used in conjunction with information on stationary vs. non-stationary distribution:
      If the data is stationary, and there are significant outliers, then we want to flag them
      We want to do this on a per channel basis for detecting outliers
  
  Determines whether activation data is flagged as outlier based on if data is stationary and:
      p_r = avg(100th percentile / "reference_percentile"th percentile)
      where:
          p_r is average percentile ratio across all batches in the epoch
          reference_percentile is a percentile values between 0 and 100 exclusive
  
      if p_r is above some threshold, then we consider the activations to have significant outliers
  
  Args:
      ratio_threshold (float, optional): The threshold for p_r to determine if there are outliers in activations
          Should be >= 1
          Default: 3.5
      reference_percentile (float, optional): The denominator to find the relative scale of the 100th percentile
          Should be between 0 and 1
          Default: 0.975
      fraction_batches_used_threshold (float, optional): Threshold of fraction of batches per channel to determine outlier
          If fraction is below this, we deem number of samples used to calculate outliers as insignificant and alert user
          regardless of whether we detected outliers or not in channel to take a closer look at channel results
          Should be between 0 and 1
          Default: 0.95
      ch_axis (int, optional): The channel axis being observed to determine input weight equalization
          Default: 1
  
  * :attr:`ratio_threshold`: The threshold for p_r to determine if there are outliers in activations
      The p_r value (average ratio of 100th percentile/reference_percentile) is compared to ratio_threshold
      If it is significantly greater, then we consider it an outlier
      This threshold was calculated based on the ratio of the percentiles in a normal distribution
      The calculations behind value choice: https://drive.google.com/file/d/1N2wdtXWI-kOH8S7HH4-PYB_NmqzZil4p/view?usp=sharing
  
  * :attr:`reference_percentile`: The denominator of the top fraction to find the relative scale of the 100th percentile
      Should be between 0 and 1
      The calculations behind value choice: https://drive.google.com/file/d/1N2wdtXWI-kOH8S7HH4-PYB_NmqzZil4p/view?usp=sharing
  
  * :attr:`fraction_batches_used_threshold`: The fraction of batches to determine outliers for each channel should be above this
      Some batches may not be used because of 0-based errors, so this is to ensure a good amount of the total batches are used
      Should be between 0 and 1
  
  * :attr:`ch_axis`: The channel axis being observed to determine outliers
  
  * :attr:`DEFAULT_PRE_OBSERVER_NAME`: The name of the pre-observer to be inserted for this detector
class_docstr_tok: ["Determines","whether","there","are","significant","outliers","in","activation","data","around","a","certain","layer",".","This","is","ideally","used","in","conjunction","with","information","on","stationary","vs.","non-stationary","distribution",":","If","the","data","is","stationary",",","and","there","are","significant","outliers",",","then","we","want","to","flag","them","We","want","to","do","this","on","a","per","channel","basis","for","detecting","outliers","Determines","whether","activation","data","is","flagged","as","outlier","based","on","if","data","is","stationary","and",":","p_r","=","avg","(","100th","percentile","\/","``","reference_percentile","''","th","percentile",")","where",":","p_r","is","average","percentile","ratio","across","all","batches","in","the","epoch","reference_percentile","is","a","percentile","values","between","0","and","100","exclusive","if","p_r","is","above","some","threshold",",","then","we","consider","the","activations","to","have","significant","outliers","Args",":","ratio_threshold","(","float",",","optional",")",":","The","threshold","for","p_r","to","determine","if","there","are","outliers","in","activations","Should","be",">","=","1","Default",":","3.5","reference_percentile","(","float",",","optional",")",":","The","denominator","to","find","the","relative","scale","of","the","100th","percentile","Should","be","between","0","and","1","Default",":","0.975","fraction_batches_used_threshold","(","float",",","optional",")",":","Threshold","of","fraction","of","batches","per","channel","to","determine","outlier","If","fraction","is","below","this",",","we","deem","number","of","samples","used","to","calculate","outliers","as","insignificant","and","alert","user","regardless","of","whether","we","detected","outliers","or","not","in","channel","to","take","a","closer","look","at","channel","results","Should","be","between","0","and","1","Default",":","0.95","ch_axis","(","int",",","optional",")",":","The","channel","axis","being","observed","to","determine","input","weight","equalization","Default",":","1","*",":","attr",":","`","ratio_threshold","`",":","The","threshold","for","p_r","to","determine","if","there","are","outliers","in","activations","The","p_r","value","(","average","ratio","of","100th","percentile\/reference_percentile",")","is","compared","to","ratio_threshold","If","it","is","significantly","greater",",","then","we","consider","it","an","outlier","This","threshold","was","calculated","based","on","the","ratio","of","the","percentiles","in","a","normal","distribution","The","calculations","behind","value","choice",":","https",":","\/\/drive.google.com\/file\/d\/1N2wdtXWI-kOH8S7HH4-PYB_NmqzZil4p\/view","?","usp=sharing","*",":","attr",":","`","reference_percentile","`",":","The","denominator","of","the","top","fraction","to","find","the","relative","scale","of","the","100th","percentile","Should","be","between","0","and","1","The","calculations","behind","value","choice",":","https",":","\/\/drive.google.com\/file\/d\/1N2wdtXWI-kOH8S7HH4-PYB_NmqzZil4p\/view","?","usp=sharing","*",":","attr",":","`","fraction_batches_used_threshold","`",":","The","fraction","of","batches","to","determine","outliers","for","each","channel","should","be","above","this","Some","batches","may","not","be","used","because","of","0-based","errors",",","so","this","is","to","ensure","a","good","amount","of","the","total","batches","are","used","Should","be","between","0","and","1","*",":","attr",":","`","ch_axis","`",":","The","channel","axis","being","observed","to","determine","outliers","*",":","attr",":","`","DEFAULT_PRE_OBSERVER_NAME","`",":","The","name","of","the","pre-observer","to","be","inserted","for","this","detector"]
docstr: Helper function for generate_detector_report that does the generation of the dictionary.
  This process is done as specified in generate_detector_report documentation
  
  Args:
      model (GraphModule): The prepared and calibrated GraphModule with inserted ModelReportObservers
  
  Returns a dict mapping relevant module fqns to:
      whether there were outliers found in activation before
      the number of batches used for each channel
      whether fraction of applicable batches used is above fraction_batches_used_threshold
      their p_r metric compared to the threshold
      the threshold used to make the recommendation
      the reference_percentile used to make the recommendation
      the channel axis used to determine individual channels
      the constant batch counts per channel
      the per channel max values
docstr_tok: ["Helper","function","for","generate_detector_report","that","does","the","generation","of","the","dictionary",".","This","process","is","done","as","specified","in","generate_detector_report","documentation","Args",":","model","(","GraphModule",")",":","The","prepared","and","calibrated","GraphModule","with","inserted","ModelReportObservers","Returns","a","dict","mapping","relevant","module","fqns","to",":","whether","there","were","outliers","found","in","activation","before","the","number","of","batches","used","for","each","channel","whether","fraction","of","applicable","batches","used","is","above","fraction_batches_used_threshold","their","p_r","metric","compared","to","the","threshold","the","threshold","used","to","make","the","recommendation","the","reference_percentile","used","to","make","the","recommendation","the","channel","axis","used","to","determine","individual","channels","the","constant","batch","counts","per","channel","the","per","channel","max","values"]
code: def _generate_info_dict(self, model: GraphModule) -> Dict[str, Dict]:
      r"""
      Helper function for generate_detector_report that does the generation of the dictionary.
      This process is done as specified in generate_detector_report documentation
  
      Args:
          model (GraphModule): The prepared and calibrated GraphModule with inserted ModelReportObservers
  
      Returns a dict mapping relevant module fqns to:
          whether there were outliers found in activation before
          the number of batches used for each channel
          whether fraction of applicable batches used is above fraction_batches_used_threshold
          their p_r metric compared to the threshold
          the threshold used to make the recommendation
          the reference_percentile used to make the recommendation
          the channel axis used to determine individual channels
          the constant batch counts per channel
          the per channel max values
      """
      # return dictionary mapping observer fqns to desired info
      info_dict: Dict[str, Dict] = {}
  
      for fqn, module in model.named_modules():
          # if module is supported and it has a pre-observer
          if self._supports_report_gen(module):
              # get pre observer for the module
              pre_obs: ModelReportObserver = getattr(
                  module, self.DEFAULT_PRE_OBSERVER_NAME
              )
  
              # get the number of batches and calculated ratio thresholds
              num_batches: torch.Tensor = (
                  pre_obs.percentile_batches_tracked
              )
              average_ratios: torch.Tensor = (
                  pre_obs.average_percentile_ratio
              )
              channel_batch_cnts: torch.Tensor = (
                  pre_obs.constant_channels
              )
              total_batches: int = pre_obs.num_batches_tracked
  
              # also get the max values
              max_vals: torch.Tensor = pre_obs.max_val
  
              # we have to specifically modify how we are recording negative ratio for pre-relu layers
              for index, ratio_val in enumerate(average_ratios):
                  # check if we have a negative ratio
                  # a ratio might be negative if we have a situation where the 100th percentile is
                  # > 0 while the nth percentile is < 0, in which case this would not be detected
                  # as an outlier. Since we care more about magnitude, we make it positive.
                  if ratio_val.item() < 0:
                      # first make it positive
                      average_ratios[index] = -ratio_val
  
                  if ratio_val.item() < 1:
                      # if it's less than 1 we have the flip it as well
                      average_ratios[index] = 1 / ratio_val
  
              outlier_calcs = self._calculate_outlier_info(
                  average_ratios, num_batches, total_batches
              )
  
              # calculate whether ratios were outliers
              info_dict[fqn] = {
                  self.CHANNEL_AXIS_KEY: self.ch_axis,
                  self.REF_PERCENTILE_KEY: self.reference_percentile,
                  self.RATIO_THRES_KEY: self.ratio_threshold,
                  self.COMP_METRIC_KEY: average_ratios,
                  self.NUM_BATCHES_KEY: num_batches,
                  self.OUTLIER_KEY: outlier_calcs[self.OUTLIER_KEY],
                  self.IS_SUFFICIENT_BATCHES_KEY: outlier_calcs[
                      self.IS_SUFFICIENT_BATCHES_KEY
                  ],
                  self.CONSTANT_COUNTS_KEY: channel_batch_cnts,
                  self.MAX_VALS_KEY: max_vals,
              }
  
      return info_dict
  
imports: from typing import Any, Dict, Set, Tuple, Callable, List
  import torch
  import torch.nn
  import torch.ao.nn.qat
  from abc import ABC, abstractmethod
  from torch.ao.quantization.fake_quantize import FakeQuantize
  from torch.ao.quantization.fx.graph_module import GraphModule
  from torch.ao.quantization.fx._model_report.model_report_observer import ModelReportObserver
  from torch.ao.quantization.qconfig import QConfig, default_qconfig, _assert_valid_qconfig
  from torch.ao.quantization.observer import ObserverBase, default_dynamic_quant_observer, default_per_channel_weight_observer, default_observer, default_weight_observer
  from torch.ao.quantization.fx._equalize import default_equalization_qconfig, EqualizationQConfig
  from torch.ao.quantization.observer import _is_activation_post_process
label_desc: Use image node_id 8 for calling the OutlierDetector obj's underlying member method code with example usage: obj._generate_info_dict(model) and returns: info_dict