code: def initialize_attention_modules(self, model_args, for_eval=False):
      pretrain_mm_mlp_adapter = getattr(
          model_args, "pretrain_mm_mlp_adapter", None
      )
      pretrain_qformer = getattr(model_args, "pretrain_qformer", None)
      self.config.bert_type = getattr(
          model_args, "bert_type", "qformer"
      )
      self.config.num_query = getattr(model_args, "num_query", 32)
      self.config.compress_type = getattr(
          model_args, "compress_type", None
      )
  
      if "pretrain" in self.config.bert_type:
          # for qformer that use evaclip for prtrain
          att_feat_size = 1408
      else:
          att_feat_size = self.config.mm_hidden_size
      (
          self.vlm_att_tokenlizer,
          self.vlm_att_encoder,
          self.vlm_att_query,
      ) = self.init_bert(att_feat_size, truncation_side="left")
      self.vlm_att_projector = torch.nn.Linear(
          self.vlm_att_encoder.config.hidden_size,
          self.config.mm_hidden_size,
      )
      self.vlm_att_key_projector = torch.nn.Linear(
          self.config.mm_hidden_size, self.config.mm_hidden_size
      )
      self.vlm_att_val_projector = torch.nn.Linear(
          self.config.mm_hidden_size, self.config.hidden_size
      )
  
      if "raw" in self.config.bert_type:
          self.vlm_att_bert_proj = torch.nn.Linear(
              att_feat_size, self.vlm_att_encoder.config.hidden_size
          )
      elif (
          "pretrain" in self.config.bert_type
          and self.config.mm_hidden_size != att_feat_size
      ):
          self.vlm_att_bert_proj = torch.nn.Linear(
              self.config.mm_hidden_size, att_feat_size
          )
      else:
          self.vlm_att_bert_proj = None
  
      def get_w(weights, keyword):
          return {
              k.split(keyword + ".")[1]: v
              for k, v in weights.items()
              if keyword in k
          }
  
      if "qformer_pretrain" in self.config.bert_type:
          self.vlm_att_ln = torch.nn.LayerNorm(att_feat_size)
  
      if pretrain_qformer is not None:
          print("Loading pretrained qformer weights...")
          qformer_weight = torch.load(
              pretrain_qformer, map_location="cpu"
          )["model"]
          bert_weight = {
              _key: qformer_weight[_key]
              for _key in qformer_weight
              if "bert" in _key
          }
          self.vlm_att_encoder.load_state_dict(
              get_w(bert_weight, "Qformer")
          )
          self.vlm_att_ln.load_state_dict(
              get_w(qformer_weight, "ln_vision")
          )
          self.vlm_att_query.data = qformer_weight["query_tokens"]
  
      if "freeze_all" in self.config.bert_type:
          print("Freezing all qformer weights...")
          self.vlm_att_encoder.requires_grad_(False)
          self.vlm_att_ln.requires_grad_(False)
          self.vlm_att_query.requires_grad_(False)
          self.vlm_att_projector.requires_grad_(False)
          self.vlm_att_key_projector.requires_grad_(False)
          self.vlm_att_val_projector.requires_grad_(False)
      elif "freeze" in self.config.bert_type:
          print("Freezing pretrained qformer weights...")
          self.vlm_att_encoder.requires_grad_(False)
          self.vlm_att_ln.requires_grad_(False)
          self.vlm_att_query.requires_grad_(False)
  
      if pretrain_mm_mlp_adapter is not None:
          att_projector_weights = torch.load(
              pretrain_mm_mlp_adapter, map_location="cpu"
          )
      else:
          trainable_module = [
              "vlm_att_encoder",
              "vlm_att_projector",
              "vlm_att_key_projector",
              "vlm_att_val_projector",
              "vlm_att_query",
              "vlm_att_visual_proj",
              "vlm_att_ln",
          ]
          if hasattr(model_args, "model_name_or_path"):
              model_save_path = model_args.model_name_or_path
          else:
              model_save_path = model_args.model_path
          model_idx_path = getattr(
              model_args, "model_path", model_save_path
          )
          weight_file = json.load(
              open(
                  os.path.join(
                      model_idx_path, "pytorch_model.bin.index.json"
                  ),
                  "r",
              )
          )["weight_map"]
          model_path = set(
              [
                  weight_file[_key]
                  for _key in weight_file
                  if any(
                      [_module in _key for _module in trainable_module]
                  )
              ]
          )
          att_projector_weights = {}
          for _model in model_path:
              att_projector_weights.update(
                  torch.load(
                      os.path.join(model_idx_path, _model),
                      map_location="cpu",
                  )
              )
          if len(att_projector_weights) == 0:
              return
  
      bert_dict = get_w(att_projector_weights, "vlm_att_encoder")
      if (
          "bert.embeddings.position_ids" not in bert_dict
          and "raw_bert" not in self.config.bert_type
      ):
          bert_dict[
              "bert.embeddings.position_ids"
          ] = self.vlm_att_encoder.bert.embeddings.position_ids
      print("Loading pretrained weights...")
      self.vlm_att_encoder.load_state_dict(bert_dict)
      self.vlm_att_projector.load_state_dict(
          get_w(att_projector_weights, "vlm_att_projector")
      )
      self.vlm_att_key_projector.load_state_dict(
          get_w(att_projector_weights, "vlm_att_key_projector")
      )
      self.vlm_att_val_projector.load_state_dict(
          get_w(att_projector_weights, "vlm_att_val_projector")
      )
  
      if "qformer" in self.config.bert_type:
          print("Loading vlm_att_query weights...")
          self.vlm_att_query.data = att_projector_weights[
              "model.vlm_att_query"
          ]
          if "pretrain" in self.config.bert_type:
              print("Loading vlm_att_ln weights...")
              self.vlm_att_ln.load_state_dict(
                  get_w(att_projector_weights, "vlm_att_ln")
              )
  
      if self.vlm_att_bert_proj is not None:
          print("Loading vlm_att_bert_proj weights...")
          self.vlm_att_bert_proj.load_state_dict(
              get_w(att_projector_weights, "vlm_att_bert_proj")
          )
  
      if for_eval:
          weight_type = torch.float16
          device_type = self.mm_projector[0].weight.device
          self.vlm_att_encoder = self.vlm_att_encoder.to(
              device=device_type, dtype=weight_type
          )
          self.vlm_att_projector = self.vlm_att_projector.to(
              device=device_type, dtype=weight_type
          )
          self.vlm_att_key_projector = self.vlm_att_key_projector.to(
              device=device_type, dtype=weight_type
          )
          self.vlm_att_val_projector = self.vlm_att_val_projector.to(
              device=device_type, dtype=weight_type
          )
  
          if "qformer" in self.config.bert_type:
              self.vlm_att_query.data = self.vlm_att_query.data.to(
                  device=device_type, dtype=weight_type
              )
              if "pretrain" in self.config.bert_type:
                  self.vlm_att_ln = self.vlm_att_ln.to(
                      device=device_type, dtype=weight_type
                  )
  
          if self.vlm_att_bert_proj is not None:
              self.vlm_att_bert_proj = self.vlm_att_bert_proj.to(
                  device=device_type, dtype=weight_type
              )
  
imports: from abc import ABC, abstractmethod
  import os
  import json
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from transformers import BertTokenizer
  from transformers.models.bert.modeling_bert import BertLMHeadModel
  from .qformer import BertConfig
  from .qformer import BertLMHeadModel
  from .multimodal_encoder.builder import build_vision_tower
  from .multimodal_projector.builder import build_vision_projector
  from llamavid.constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX, DEFAULT_IMAGE_PATCH_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN
label_desc: Use image node_id 4 for calling the LLaMAVIDMetaModel obj's underlying member method code with example usage: obj.initialize_attention_modules(model_args, for_eval) and returns: unknown