code: def get_trunk_forward_outputs(
      feat: torch.Tensor,
      out_feat_keys: List[str],
      feature_blocks: nn.ModuleDict,
      feature_mapping: Dict[str, str] = None,
      use_checkpointing: bool = False,
      checkpointing_splits: int = 2,
  ) -> List[torch.Tensor]:
      """
      Args:
          feat: model input.
          out_feat_keys: a list/tuple with the feature names of the features that
              the function should return. By default the last feature of the network
              is returned.
          feature_blocks: ModuleDict containing feature blocks in the model
          feature_mapping: an optional correspondence table in between the requested
              feature names and the model's.
  
      Returns:
          out_feats: a list with the asked output features placed in the same order as in
          `out_feat_keys`.
      """
  
      # Sanitize inputs
      if feature_mapping is not None:
          out_feat_keys = [feature_mapping[f] for f in out_feat_keys]
  
      out_feat_keys, max_out_feat = parse_out_keys_arg(
          out_feat_keys, list(feature_blocks.keys())
      )
  
      # Forward pass over the trunk
      unique_out_feats = {}
      unique_out_feat_keys = list(set(out_feat_keys))
  
      # FIXME: Ideally this should only be done once at construction time
      if use_checkpointing:
          feature_blocks = checkpoint_trunk(
              feature_blocks, unique_out_feat_keys, checkpointing_splits
          )
  
          # If feat is the first input to the network, it doesn't have requires_grad,
          # which will make checkpoint's backward function not being called. So we need
          # to set it to true here.
          feat.requires_grad = True
  
      # Go through the blocks, and save the features as we go
      # NOTE: we are not doing several forward passes but instead just checking
      # whether the feature is requested to be returned.
      for i, (feature_name, feature_block) in enumerate(
          feature_blocks.items()
      ):
          # The last chunk has to be non-volatile
          if use_checkpointing and i < len(feature_blocks) - 1:
              # Un-freeze the running stats in any BN layer
              for m in filter(
                  lambda x: isinstance(x, _bn_cls),
                  feature_block.modules(),
              ):
                  m.track_running_stats = m.training
  
              feat = checkpoint(feature_block, feat, use_reentrant=True)
  
              # Freeze the running stats in any BN layer
              # the checkpointing process will have to do another FW pass
              for m in filter(
                  lambda x: isinstance(x, _bn_cls),
                  feature_block.modules(),
              ):
                  m.track_running_stats = False
          else:
              feat = feature_block(feat)
  
          # This feature is requested, store. If the same feature is requested several
          # times, we return the feature several times.
          if feature_name in unique_out_feat_keys:
              unique_out_feats[feature_name] = feat
  
          # Early exit if all the features have been collected
          if i == max_out_feat and not use_checkpointing:
              break
  
      # now return the features as requested by the user. If there are no duplicate keys,
      # return as is.
      if len(unique_out_feat_keys) == len(out_feat_keys):
          return list(unique_out_feats.values())
  
      output_feats = []
      for key_name in out_feat_keys:
          output_feats.append(unique_out_feats[key_name])
      return output_feats
  
imports: import logging
  import math
  import warnings
  from enum import Enum
  from typing import Dict, List, Tuple
  import torch
  import torch.distributed
  import torch.nn
  import torch.nn.functional
  from torch.nn.modules.utils import _ntuple
  from torch.utils.checkpoint import checkpoint
  from vissl.data.collators.collator_helper import MultiDimensionalTensor
  from vissl.utils.activation_checkpointing import checkpoint_trunk
  from vissl.utils.env import get_machine_local_and_dist_rank
  from vissl.utils.misc import is_apex_available
label_desc: Use image node_id 13 for calling a global function with example usage: get_trunk_forward_outputs(feat, out_feat_keys, feature_blocks, feature_mapping, use_checkpointing, checkpointing_splits) and returns: output_feats, list