code: def build_encoder(cls, args, src_dict, embed_tokens):
      if (
          safe_hasattr(args, "encoder_attn_head_select")
          and args.encoder_attn_head_select
      ):
          return HeadSelectionTransformerEncoder(
              args, src_dict, embed_tokens
          )
      else:
          return TransformerEncoder(args, src_dict, embed_tokens)
  
imports: from typing import Any, List, Dict, Optional
  import torch
  import torch.nn
  from torch import Tensor
  from fairseq.utils import safe_hasattr
  from fairseq.models.transformer import TransformerModel, TransformerEncoder, TransformerDecoder
  from ..modules.attn_head_selector import AttnHeadSelector
  from ..modules.head_selection_transformer_layer import HeadSelectionTransformerEncoderLayer, HeadSelectionTransformerDecoderLayer
label_desc: Use image node_id 3 for calling the HeadSelectionTransformerModel obj's underlying member method code with example usage: obj.build_encoder(cls, args, src_dict, embed_tokens) and returns: HeadSelectionTransformerEncoder, TransformerEncoder