docstr: Tie some head weights with backend embeddings
docstr_tok: ["Tie","some","head","weights","with","backend","embeddings"]
code: def tie_weights(self):
      """Tie some head weights with backend embeddings"""
      text_embedding_idx = self.modality_type.index("text")
      if text_embedding_idx >= 0:
          for head in self.heads:
              if self.config.get("tie_weight_to_encoder", None):
                  encoder_key = self._find_unique_encoder_key(
                      self.config.tie_weight_to_encoder
                  )
                  logger.info(
                      f"Tie head weights to {encoder_key} encoder token embeddings"
                  )
                  if hasattr(self.encoders[encoder_key], "transformer"):
                      head.tie_weights(
                          self.encoders[
                              encoder_key
                          ].transformer.transformer.token_embedding
                      )
                  elif hasattr(
                      self.encoders[encoder_key], "embeddings"
                  ):
                      head.tie_weights(
                          self.encoders[
                              encoder_key
                          ].embeddings.word_embeddings
                      )
                  else:
                      raise NotImplementedError(
                          "Current encoder module arch not supported."
                      )
              else:
                  head.tie_weights(
                      self.backend.embeddings.token_embeddings[
                          text_embedding_idx
                      ]
                  )
  
imports: import logging
  from dataclasses import dataclass, field
  from typing import Dict, List, Optional
  import torch
  from mmf.common.registry import registry
  from mmf.models.transformers.base import BaseTransformer, BaseTransformerBackendConfig, BaseTransformerHead, BaseTransformerModalityConfig
  from mmf.models.transformers.heads.mlp import MLP
  from mmf.modules.encoders import ResNet152ImageEncoder
  from mmf.utils.build import build_encoder
  from omegaconf import MISSING, OmegaConf
  from torch import nn, Tensor
label_desc: Use image node_id 5 for calling the MMFTransformer obj's underlying member method code with example usage: obj.tie_weights() without return types