class_docstr: Transformer decoder consisting of *cfg.decoder.layers* layers. Each layer
  is a :class:`TransformerDecoderLayer`.
  
  Args:
      cfg (argparse.Namespace): parsed command-line arguments
      dictionary (~fairseq.data.Dictionary): decoding dictionary
      embed_tokens (torch.nn.Embedding): output embedding
      no_encoder_attn (bool, optional): whether to attend to encoder outputs
          (default: False).
class_docstr_tok: ["Transformer","decoder","consisting","of","*","cfg.decoder.layers","*","layers",".","Each","layer","is","a",":","class",":","`","TransformerDecoderLayer","`",".","Args",":","cfg","(","argparse.Namespace",")",":","parsed","command-line","arguments","dictionary","(","~fairseq.data.Dictionary",")",":","decoding","dictionary","embed_tokens","(","torch.nn.Embedding",")",":","output","embedding","no_encoder_attn","(","bool",",","optional",")",":","whether","to","attend","to","encoder","outputs","(","default",":","False",")","."]
docstr: Similar to *forward* but only return features.
  
  Includes several features from "Jointly Learning to Align and
  Translate with Transformer Models" (Garg et al., EMNLP 2019).
  
  Args:
      full_context_alignment (bool, optional): don't apply
          auto-regressive mask to self-attention (default: False).
      alignment_layer (int, optional): return mean alignment over
          heads at this layer (default: last layer).
      alignment_heads (int, optional): only average alignment over
          this many heads (default: all heads).
  
  Returns:
      tuple:
          - the decoder's features of shape `(batch, tgt_len, embed_dim)`
          - a dictionary with any model-specific outputs
docstr_tok: ["Similar","to","*","forward","*","but","only","return","features",".","Includes","several","features","from","``","Jointly","Learning","to","Align","and","Translate","with","Transformer","Models","''","(","Garg","et","al.",",","EMNLP","2019",")",".","Args",":","full_context_alignment","(","bool",",","optional",")",":","do","n't","apply","auto-regressive","mask","to","self-attention","(","default",":","False",")",".","alignment_layer","(","int",",","optional",")",":","return","mean","alignment","over","heads","at","this","layer","(","default",":","last","layer",")",".","alignment_heads","(","int",",","optional",")",":","only","average","alignment","over","this","many","heads","(","default",":","all","heads",")",".","Returns",":","tuple",":","-","the","decoder","'s","features","of","shape","`","(","batch",",","tgt_len",",","embed_dim",")","`","-","a","dictionary","with","any","model-specific","outputs"]
code: def extract_features_scriptable(
      self,
      prev_output_tokens,
      encoder_out: Optional[Dict[str, List[Tensor]]],
      incremental_state: Optional[
          Dict[str, Dict[str, Optional[Tensor]]]
      ] = None,
      full_context_alignment: bool = False,
      alignment_layer: Optional[int] = None,
      alignment_heads: Optional[int] = None,
  ):
      """
      Similar to *forward* but only return features.
  
      Includes several features from "Jointly Learning to Align and
      Translate with Transformer Models" (Garg et al., EMNLP 2019).
  
      Args:
          full_context_alignment (bool, optional): don't apply
              auto-regressive mask to self-attention (default: False).
          alignment_layer (int, optional): return mean alignment over
              heads at this layer (default: last layer).
          alignment_heads (int, optional): only average alignment over
              this many heads (default: all heads).
  
      Returns:
          tuple:
              - the decoder's features of shape `(batch, tgt_len, embed_dim)`
              - a dictionary with any model-specific outputs
      """
      bs, slen = prev_output_tokens.size()
      if alignment_layer is None:
          alignment_layer = self.num_layers - 1
  
      enc: Optional[Tensor] = None
      padding_mask: Optional[Tensor] = None
      if (
          encoder_out is not None
          and len(encoder_out["encoder_out"]) > 0
      ):
          enc = encoder_out["encoder_out"][0]
      if (
          encoder_out is not None
          and len(encoder_out["encoder_padding_mask"]) > 0
      ):
          padding_mask = encoder_out["encoder_padding_mask"][0]
  
      # embed positions
      positions = None
      if self.embed_positions is not None:
          positions = self.embed_positions(
              prev_output_tokens, incremental_state=incremental_state
          )
  
      if incremental_state is not None:
          prev_output_tokens = prev_output_tokens[:, -1:]
          if positions is not None:
              positions = positions[:, -1:]
  
      # Prevent torchscript exporting issue for dynamic quant embedding
      prev_output_tokens = prev_output_tokens.contiguous()
      # embed tokens and positions
      x = self.embed_scale * self.embed_tokens(prev_output_tokens)
  
      if self.quant_noise is not None:
          x = self.quant_noise(x)
  
      if self.project_in_dim is not None:
          x = self.project_in_dim(x)
  
      if positions is not None:
          x += positions
  
      if self.layernorm_embedding is not None:
          x = self.layernorm_embedding(x)
  
      x = self.dropout_module(x)
  
      # B x T x C -> T x B x C
      x = x.transpose(0, 1)
  
      self_attn_padding_mask: Optional[Tensor] = None
      if (
          self.cross_self_attention
          or prev_output_tokens.eq(self.padding_idx).any()
      ):
          self_attn_padding_mask = prev_output_tokens.eq(
              self.padding_idx
          )
  
      # decoder layers
      attn: Optional[Tensor] = None
      inner_states: List[Optional[Tensor]] = [x]
      for idx, layer in enumerate(self.layers):
          if incremental_state is None and not full_context_alignment:
              self_attn_mask = self.buffered_future_mask(x)
          else:
              self_attn_mask = None
  
          x, layer_attn, _ = layer(
              x,
              enc,
              padding_mask,
              incremental_state,
              self_attn_mask=self_attn_mask,
              self_attn_padding_mask=self_attn_padding_mask,
              need_attn=bool((idx == alignment_layer)),
              need_head_weights=bool((idx == alignment_layer)),
          )
          inner_states.append(x)
          if layer_attn is not None and idx == alignment_layer:
              attn = layer_attn.float().to(x)
  
      if attn is not None:
          if alignment_heads is not None:
              attn = attn[:alignment_heads]
  
          # average probabilities over heads
          attn = attn.mean(dim=0)
  
      if self.layer_norm is not None:
          x = self.layer_norm(x)
  
      # T x B x C -> B x T x C
      x = x.transpose(0, 1)
  
      if self.project_out_dim is not None:
          x = self.project_out_dim(x)
  
      return x, {"attn": [attn], "inner_states": inner_states}
  
imports: import math
  from typing import Any, Dict, List, Optional
  import torch
  import torch.nn
  from torch import Tensor
  from fairseq import utils
  from fairseq.distributed import fsdp_wrap
  from fairseq.models import FairseqIncrementalDecoder
  from fairseq.models.transformer import TransformerConfig
  from fairseq.modules import AdaptiveSoftmax, BaseLayer, FairseqDropout, LayerDropModuleList, LayerNorm, PositionalEmbedding, SinusoidalPositionalEmbedding, transformer_layer
  from fairseq.modules.checkpoint_activations import checkpoint_wrapper
  from fairseq.modules.quant_noise import quant_noise
label_desc: Use image node_id 6 for calling the TransformerDecoderBase obj's underlying member method code with example usage: obj.extract_features_scriptable(prev_output_tokens, encoder_out, incremental_state, full_context_alignment, alignment_layer, alignment_heads) and returns: x,  dict