class_docstr: BLIP2 T5 model.
  Supported model types:
      - pretrain_flant5xl: pretrained model with FlanT5-XL
      - pretrain_flant5xl_vitL: pretrained model with FlanT5-XL
      - pretrain_flant5xxl: pretrained model with FlanT5-XXL
      - caption_coco_flant5xl: fintuned image captioning model with FlanT5-XL
  Usage:
      >>> from lavis.models import load_model
      >>> model = load_model("blip2_t5", "pretrain_flant5xl")
class_docstr_tok: ["BLIP2","T5","model",".","Supported","model","types",":","-","pretrain_flant5xl",":","pretrained","model","with","FlanT5-XL","-","pretrain_flant5xl_vitL",":","pretrained","model","with","FlanT5-XL","-","pretrain_flant5xxl",":","pretrained","model","with","FlanT5-XXL","-","caption_coco_flant5xl",":","fintuned","image","captioning","model","with","FlanT5-XL","Usage",":",">",">",">","from","lavis.models","import","load_model",">",">",">","model","=","load_model","(","``","blip2_t5","''",",","``","pretrain_flant5xl","''",")"]
docstr: apply_lemmatizer: when set to True, postprocess predict_answers() result with lemmas.
docstr_tok: ["apply_lemmatizer",":","when","set","to","True",",","postprocess","predict_answers","(",")","result","with","lemmas","."]
code: def __init__(
      self,
      vit_model="eva_clip_g",
      img_size=224,
      drop_path_rate=0,
      use_grad_checkpoint=False,
      vit_precision="fp16",
      freeze_vit=True,
      num_query_token=32,
      t5_model="google/flan-t5-xl",
      prompt="",
      max_txt_len=32,
      apply_lemmatizer=False,
  ):
      """
      apply_lemmatizer: when set to True, postprocess predict_answers() result with lemmas.
      """
      super().__init__()
  
      self.tokenizer = self.init_tokenizer()
  
      self.visual_encoder, self.ln_vision = self.init_vision_encoder(
          vit_model,
          img_size,
          drop_path_rate,
          use_grad_checkpoint,
          vit_precision,
      )
      if freeze_vit:
          for name, param in self.visual_encoder.named_parameters():
              param.requires_grad = False
          self.visual_encoder = self.visual_encoder.eval()
          self.visual_encoder.train = disabled_train
          logging.info("freeze vision encoder")
  
      self.Qformer, self.query_tokens = self.init_Qformer(
          num_query_token, self.visual_encoder.num_features
      )
      self.Qformer.cls = None
      self.Qformer.bert.embeddings.word_embeddings = None
      self.Qformer.bert.embeddings.position_embeddings = None
      for layer in self.Qformer.bert.encoder.layer:
          layer.output = None
          layer.intermediate = None
  
      self.t5_tokenizer = T5TokenizerFast.from_pretrained(t5_model)
      t5_config = T5Config.from_pretrained(t5_model)
      t5_config.dense_act_fn = "gelu"
      self.t5_model = T5ForConditionalGeneration.from_pretrained(
          t5_model, config=t5_config
      )
  
      for name, param in self.t5_model.named_parameters():
          param.requires_grad = False
          param.data = param.data.bfloat16()
  
      self.t5_proj = nn.Linear(
          self.Qformer.config.hidden_size,
          self.t5_model.config.hidden_size,
      )
  
      self.max_txt_len = max_txt_len
      self.prompt = prompt
  
      self._apply_lemmatizer = apply_lemmatizer
      self._lemmatizer = None
  
file_path: lavis/lavis/models/blip2_models/blip2_t5.py
imports: import logging
  import torch
  import torch.nn
  from torch.cuda.amp import autocast
  from transformers import T5TokenizerFast
  from lavis.common.registry import registry
  from lavis.models.blip2_models.blip2 import Blip2Base, disabled_train
  from lavis.models.blip2_models.modeling_t5 import T5Config, T5ForConditionalGeneration
label_desc: Use image node_id 1 to create a new Blip2T5 object from inherited base classes: Blip2Base with example: obj = Blip2T5(vit_model, img_size, drop_path_rate, use_grad_checkpoint, vit_precision, freeze_vit, num_query_token, t5_model, prompt, max_txt_len, apply_lemmatizer)