code: def initialize_vision_tokenizer(
      self, model_args, tokenizer, add_region_feature=False
  ):
      if model_args.mm_use_im_patch_token:
          tokenizer.add_tokens(
              [DEFAULT_IMAGE_PATCH_TOKEN], special_tokens=True
          )
          self.resize_token_embeddings(len(tokenizer))
  
      if add_region_feature:
          num_region_fea_tokens = tokenizer.add_tokens(
              [DEFAULT_REGION_FEA_TOKEN], special_tokens=True
          )
          self.config.im_region_fea_token = (
              tokenizer.convert_tokens_to_ids(
                  [DEFAULT_REGION_FEA_TOKEN]
              )[0]
          )
          self.resize_token_embeddings(len(tokenizer))
  
      if model_args.mm_use_im_start_end:
          num_new_tokens = tokenizer.add_tokens(
              [DEFAULT_IM_START_TOKEN, DEFAULT_IM_END_TOKEN],
              special_tokens=True,
          )
          self.resize_token_embeddings(len(tokenizer))
  
          if add_region_feature:
              num_new_tokens = num_new_tokens + num_region_fea_tokens
  
          if num_new_tokens > 0:
              input_embeddings = self.get_input_embeddings().weight.data
              output_embeddings = (
                  self.get_output_embeddings().weight.data
              )
  
              input_embeddings_avg = input_embeddings[
                  :-num_new_tokens
              ].mean(dim=0, keepdim=True)
              output_embeddings_avg = output_embeddings[
                  :-num_new_tokens
              ].mean(dim=0, keepdim=True)
  
              input_embeddings[-num_new_tokens:] = input_embeddings_avg
              output_embeddings[
                  -num_new_tokens:
              ] = output_embeddings_avg
  
          if model_args.tune_mm_mlp_adapter:
              for p in self.get_input_embeddings().parameters():
                  p.requires_grad = True
              for p in self.get_output_embeddings().parameters():
                  p.requires_grad = False
  
          if model_args.pretrain_mm_mlp_adapter:
              mm_projector_weights = torch.load(
                  model_args.pretrain_mm_mlp_adapter, map_location="cpu"
              )
              embed_tokens_weight = mm_projector_weights[
                  "model.embed_tokens.weight"
              ]
              if add_region_feature:
                  num_new_tokens = (
                      num_new_tokens - num_region_fea_tokens
                  )
              assert num_new_tokens == 2
              if input_embeddings.shape == embed_tokens_weight.shape:
                  input_embeddings[
                      -num_new_tokens:
                  ] = embed_tokens_weight[-num_new_tokens:]
              elif embed_tokens_weight.shape[0] == num_new_tokens:
                  input_embeddings[
                      -num_new_tokens:
                  ] = embed_tokens_weight
              else:
                  raise ValueError(
                      f"Unexpected embed_tokens_weight shape. Pretrained: {embed_tokens_weight.shape}. Current: {input_embeddings.shape}. Numer of new tokens: {num_new_tokens}."
                  )
      elif model_args.mm_use_im_patch_token:
          if model_args.tune_mm_mlp_adapter:
              for p in self.get_input_embeddings().parameters():
                  p.requires_grad = False
              for p in self.get_output_embeddings().parameters():
                  p.requires_grad = False
  
imports: from abc import ABC, abstractmethod
  import torch
  import torch.nn
  import torch.nn.functional
  import math
  from .multimodal_encoder.builder import build_vision_tower
  import pdb
  from ferret.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 6 for calling the FERRETMetaForCausalLM obj's underlying member method code with example usage: obj.initialize_vision_tokenizer(model_args, tokenizer, add_region_feature) without return types