class_docstr: Prepares the model for QAT by inserting weight and activation quantizers as
  specified in qconfig_mapping.
  
  Implements additional graph passes on a prepared module returned by prepare_qat_fx.
class_docstr_tok: ["Prepares","the","model","for","QAT","by","inserting","weight","and","activation","quantizers","as","specified","in","qconfig_mapping",".","Implements","additional","graph","passes","on","a","prepared","module","returned","by","prepare_qat_fx","."]
docstr: Marks an activation post process layer (activation quantizer) for replacement.
docstr_tok: ["Marks","an","activation","post","process","layer","(","activation","quantizer",")","for","replacement","."]
code: def _mark_act_post_process_for_replacement(
      self,
      node: _fx.Node,
      model: _fx.GraphModule,
      new_act_post_process: _Optional[_aoquant.FakeQuantize] = None,
  ):
      """
      Marks an activation post process layer (activation quantizer) for replacement.
      """
      shared_qparam_nodes = []
      if len(node.users) == 1:
          next_node = list(node.users.keys())[0]
          next_module = _find_module(model, next_node)
          if _is_activation_post_process(next_module) and _is_quantized(
              next_module
          ):
              module_to_replace_id = id(
                  model.get_submodule(next_node.target)
              )
              # Some mods share the activation quantizer being replaced here,
              # so we collect all those mods here so that those can be pointed to
              # the new replaced module
              for child_node in self._act_quant_groups[
                  module_to_replace_id
              ]:
                  consumer_node = child_node.args[0]
                  if consumer_node.op == "call_module":
                      child_mod = _find_module(model, consumer_node)
                      if type(child_mod) in self._share_qparams_ops:
                          shared_qparam_nodes.append(child_node)
                          self._modules_to_replace[child_node] = []
                  elif consumer_node.op == "call_function":
                      if (
                          consumer_node.target
                          in self._share_qparams_ops
                      ):
                          shared_qparam_nodes.append(child_node)
                          self._modules_to_replace[child_node] = []
              self._modules_to_replace[next_node] = shared_qparam_nodes
              if new_act_post_process is None:
                  new_act_post_process = _get_affine_act_post_process(
                      next_module
                  )
              self._new_act_post_process[
                  next_node
              ] = new_act_post_process
  
imports: from collections import defaultdict
  from typing import Any
  from typing import Optional
  import torch
  import torch.ao.quantization
  import torch.fx
  import torch.nn
  import torch.nn.intrinsic
  import torch.nn.intrinsic.qat
  from torch.ao.quantization.backend_config import BackendConfig
  from torch.ao.quantization.fx.custom_config import PrepareCustomConfig
  from torch.quantization.quantize_fx import prepare_qat_fx
  import coremltools.optimize.torch.quantization.modules.qat_modules
  from coremltools.optimize.torch._utils.torch_utils import get_parent_child_name
  from coremltools.optimize.torch.quantization._backend_config import _fixed_qparams_modules
  from coremltools.optimize.torch.quantization._utils import CombinationOpType
  from coremltools.optimize.torch.quantization._utils import combine_op_type
  from coremltools.optimize.torch.quantization._utils import find_module
  from coremltools.optimize.torch.quantization._utils import find_target
  from coremltools.optimize.torch.quantization._utils import get_share_qparams_ops
  from coremltools.optimize.torch.quantization._utils import group_activation_quantization_modules_by_id
  from coremltools.optimize.torch.quantization._utils import is_activation_post_process
  from coremltools.optimize.torch.quantization._utils import is_quantized
  from coremltools.optimize.torch.quantization.quantization_config import QuantizationScheme
label_desc: Use image node_id 4 for calling the QATConfigurationHandler obj's underlying member method code with example usage: obj._mark_act_post_process_for_replacement(node, model, new_act_post_process) without return types