class_docstr: ContextWithImage Module.
  
  Encodes image features and context, and combines by summing or concatenation.
class_docstr_tok: ["ContextWithImage","Module",".","Encodes","image","features","and","context",",","and","combines","by","summing","or","concatenation","."]
docstr: In fp16 mode, either remove extra tokens or add new ones on to get to a multiple
  of 8.
docstr_tok: ["In","fp16","mode",",","either","remove","extra","tokens","or","add","new","ones","on","to","get","to","a","multiple","of","8","."]
code: def _fix_for_fp16(
      self, full_enc: torch.Tensor, full_mask: Optional[torch.Tensor]
  ) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
      """
      In fp16 mode, either remove extra tokens or add new ones on to get to a multiple
      of 8.
      """
  
      if full_mask is None:
          # full_mask is None corresponds to no input tokens, and in case there are no
          # tokens to add/remove to get a multiple of 8
          return full_enc, full_mask
  
      num_tokens_to_remove = full_enc.size(1) % 8
      if num_tokens_to_remove == 0:
          # Tensor already divisible by 8
          pass
      elif (~full_mask[:, -num_tokens_to_remove:].all()).item():
          # The tokens we'd like to remove are all padding, so subtract them from
          # the end
          full_enc = full_enc[:, :-1, :]
          full_mask = full_mask[:, :-1]
      else:
          # We can't subtract that many padding tokens, so add some to the end
          num_tokens_to_add = 8 - num_tokens_to_remove
          enc_extension = full_enc.new_full(
              size=(
                  full_enc.size(0),
                  num_tokens_to_add,
                  full_enc.size(2),
              ),
              fill_value=self.padding_idx,
          )
          mask_extension = full_mask.new_full(
              size=(full_mask.size(0), num_tokens_to_add),
              fill_value=self.padding_idx,
          )
          full_enc = torch.cat([full_enc, enc_extension], dim=1)
          full_mask = torch.cat([full_mask, mask_extension], dim=1)
      return full_enc, full_mask
  
imports: from enum import Enum
  from functools import reduce
  from typing import List, Tuple, Optional, Union
  import torch
  import torch.nn
  from parlai.agents.transformer.modules import TransformerGeneratorModel, TransformerEncoder
  from parlai.core.dict import DictionaryAgent
  from parlai.core.opt import Opt
label_desc: Use image node_id 9 for calling the ContextWithImageEncoder obj's underlying member method code with example usage: obj._fix_for_fp16(full_enc, full_mask) and returns: full_enc,  full_mask, full_enc,  full_mask