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: Replaces all nodes marked for replacement with new nodes.
docstr_tok: ["Replaces","all","nodes","marked","for","replacement","with","new","nodes","."]
code: def _replace_activation_quantizers(
      self, model: _fx.GraphModule
  ) -> _fx.GraphModule:
      """
      Replaces all nodes marked for replacement with new nodes.
      """
      replaced = set()
      for (
          node,
          new_act_post_process,
      ) in self._new_act_post_process.items():
          if node not in replaced:
              model.delete_submodule(node.target)
              model.add_submodule(node.target, new_act_post_process)
              replaced.add(node)
              # replace pointers to all modules which share this activation quantizer
              for child_node in self._modules_to_replace[node]:
                  if child_node not in replaced:
                      parent, child = _get_parent_child_name(
                          child_node.target
                      )
                      parent_mod = model.get_submodule(parent)
                      setattr(parent_mod, child, new_act_post_process)
                      replaced.add(child_node)
      model.recompile()
      return model
  
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 3 for calling the QATConfigurationHandler obj's underlying member method code with example usage: obj._replace_activation_quantizers(model) and returns: model