code: def parser_factory(model: Module) -> HuggingfaceModelParser | None:
      if TRANSFORMERS_INSTALLED and isinstance(model, PreTrainedModel):
          cls2parser = {
              BartConfig: HuggingfaceBartParser,
              BertConfig: HuggingfaceBertParser,
              DistilBertConfig: HuggingfaceDistilBertParser,
              T5Config: HuggingfaceT5Parser,
              ViTConfig: HuggingfaceViTParser,
          }
          type2parser = {
              "bart": HuggingfaceBartParser,
              "bert": HuggingfaceBertParser,
              "distilbert": HuggingfaceDistilBertParser,
              "t5": HuggingfaceT5Parser,
              "vit": HuggingfaceViTParser,
          }
  
          if hasattr(model, "config_class"):
              parser = cls2parser.get(getattr(model, "config_class"))
          elif hasattr(model, "model_type"):
              parser = type2parser.get(getattr(model, "model_type"))
          else:
              parser = None
  
          return parser
      else:
          return None
  
imports: from __future__ import annotations
  import logging
  import re
  from typing import Tuple
  from torch.nn import Module
  from nni.compression.utils import get_nested_attr
label_desc: Use image node_id 1 for calling a global function with example usage: parser_factory(model) and returns: parser, None