class_docstr: TokenizerModelAdapter moves input onto device and adds batch dimension
class_docstr_tok: ["TokenizerModelAdapter","moves","input","onto","device","and","adds","batch","dimension"]
docstr: Moves input onto device and adds batch dimension.
  
  Args:
      x (Any): Tokenizer output. As we script the combined model, we need to
      hint the type of the input argument of the adapter module which TorchScript
      identified as Any. Chosing a more restrictive type lets the scripting fail.
  
  Returns:
      (Tensor): On device text tensor with batch dimension
docstr_tok: ["Moves","input","onto","device","and","adds","batch","dimension",".","Args",":","x","(","Any",")",":","Tokenizer","output",".","As","we","script","the","combined","model",",","we","need","to","hint","the","type","of","the","input","argument","of","the","adapter","module","which","TorchScript","identified","as","Any",".","Chosing","a","more","restrictive","type","lets","the","scripting","fail",".","Returns",":","(","Tensor",")",":","On","device","text","tensor","with","batch","dimension"]
code: def forward(self, tokens: Any) -> torch.Tensor:
      """
      Moves input onto device and adds batch dimension.
  
      Args:
          x (Any): Tokenizer output. As we script the combined model, we need to
          hint the type of the input argument of the adapter module which TorchScript
          identified as Any. Chosing a more restrictive type lets the scripting fail.
  
      Returns:
          (Tensor): On device text tensor with batch dimension
      """
      tokens = F.to_tensor(tokens, padding_value=self._padding_idx).to(
          self._dummy_param.device
      )
      # If a single sample is tokenized we need to add the batch dimension
      if len(tokens.shape) < 2:
          return tokens.unsqueeze(0)
      return tokens
  
file_path: serve/examples/text_classification_with_scriptable_tokenizer/script_tokenizer_and_model.py
imports: import argparse
  from typing import Any
  import torch
  import torchtext.functional
  import torchtext.transforms
  from torch import nn
  from torch.hub import load_state_dict_from_url
  from torchtext.models import XLMR_BASE_ENCODER, RobertaClassificationHead
label_desc: Use image node_id 2 for calling the TokenizerModelAdapter obj's underlying member method code with example usage: obj.forward(tokens) and returns: tokens, tokens