class_docstr: This replacer is used to prune huggingface transformers attention heads,
  it base on ``HuggingfaceModelParser`` to find the attention module,
  and prune heads with attention module built-in ``prune_heads`` interface.
  
  Parameters
  ----------
  model
      The transformer model, now nni officially support bert, bart, t5, vit.
  parser
      The model parser used to find the attention module.
      If the model passed in is not bert, bart, t5 or vit,
      please inherit ``nni.compression.utils.external.huggingface.HuggingfaceModelParser``
      to customize a new model parser and pass in.
class_docstr_tok: ["This","replacer","is","used","to","prune","huggingface","transformers","attention","heads",",","it","base","on","``","HuggingfaceModelParser","``","to","find","the","attention","module",",","and","prune","heads","with","attention","module","built-in","``","prune_heads","``","interface",".","Parameters","--","--","--","--","--","model","The","transformer","model",",","now","nni","officially","support","bert",",","bart",",","t5",",","vit",".","parser","The","model","parser","used","to","find","the","attention","module",".","If","the","model","passed","in","is","not","bert",",","bart",",","t5","or","vit",",","please","inherit","``","nni.compression.utils.external.huggingface.HuggingfaceModelParser","``","to","customize","a","new","model","parser","and","pass","in","."]
code: def __init__(
      self,
      model: torch.nn.Module,
      parser: HuggingfaceModelParser | None = None,
  ):
      self.parser = parser_factory(model) if parser is None else parser
      if self.parser is None:
          err_msg = f"Can not get the model parser of {type(model)}"
          raise RuntimeError(err_msg)
  
file_path: nni/nni/compression/utils/external/external_replacer.py
imports: from __future__ import annotations
  from collections import defaultdict
  import logging
  import re
  from typing import TYPE_CHECKING, List
  import torch
  from torch.utils._pytree import tree_map
  from .huggingface import parser_factory, HuggingfaceModelParser
  from ..attr import get_nested_attr
  from ...speedup.replacer import Replacer
label_desc: Use image node_id 1 to create a new TransformersAttentionReplacer object from inherited base classes: Replacer with example: obj = TransformersAttentionReplacer(model, parser)