class_docstr: Bi-Encoder model component. Encapsulates query/question and context/passage encoders.
      
code: def get_representation(
      sub_model,
      input_ids,
      attention_mask,
      position_ids,
      img_feat,
      img_pos_feat,
      img_masks,
      gather_index=None,
      fix_encoder=False,
  ):
      if fix_encoder:
          with torch.no_grad():
              sequence_output, pooled_output, hidden_states = sub_model(
                  input_ids,
                  attention_mask,
                  position_ids,
                  img_feat,
                  img_pos_feat,
                  img_masks,
                  gather_index,
              )
      else:
          sequence_output, pooled_output, hidden_states = sub_model(
              input_ids,
              attention_mask,
              position_ids,
              img_feat,
              img_pos_feat,
              img_masks,
              gather_index,
          )
  
      if sub_model.training:
          sequence_output.requires_grad_(requires_grad=True)
          pooled_output.requires_grad_(requires_grad=True)
  
      return sequence_output, pooled_output, hidden_states
  
file_path: towhee/towhee/models/lightning_dot/bi_encoder.py
imports: from typing import Any
  import torch
  from collections import defaultdict
  from torch import nn
label_desc: Use image node_id 2 for calling the BiEncoder obj's underlying member method code with example usage: obj.get_representation(sub_model, input_ids, attention_mask, position_ids, img_feat, img_pos_feat, img_masks, gather_index, fix_encoder) and returns: sequence_output,  pooled_output,  hidden_states