class_docstr: DocModel that's compatible with the new Model abstraction, which is responsible
  for describing which inputs it expects and arranging its input tensors.
class_docstr_tok: ["DocModel","that","'s","compatible","with","the","new","Model","abstraction",",","which","is","responsible","for","describing","which","inputs","it","expects","and","arranging","its","input","tensors","."]
code: def torchscriptify(self, tensorizers, traced_model):  # noqa
      output_layer = self.output_layer.torchscript_predictions()
  
      input_vocab = tensorizers["tokens"].vocab
      max_seq_len = tensorizers["tokens"].max_seq_len or -1
      scripted_tokenizer: Optional[jit.ScriptModule] = None
      try:
          scripted_tokenizer = tensorizers[
              "tokens"
          ].tokenizer.torchscriptify()
      except NotImplementedError:
          pass
      if scripted_tokenizer and isinstance(
          scripted_tokenizer, DoNothingTokenizer
      ):
          scripted_tokenizer = None
  
      """
          The input tensor packing memory is allocated/cached for different shapes,
          and max sequence length will help to reduce the number of different tensor
          shapes. We noticed that the TorchScript model could use 25G for offline
          inference on CPU without using max_seq_len.
          """
  
      class Model(jit.ScriptModule):
          def __init__(self):
              super().__init__()
              self.vocab = ScriptVocabulary(
                  input_vocab,
                  input_vocab.get_unk_index(),
                  input_vocab.get_pad_index(),
              )
              self.model = traced_model
              self.output_layer = output_layer
              self.pad_idx = jit.Attribute(
                  input_vocab.get_pad_index(), int
              )
              self.max_seq_len = jit.Attribute(max_seq_len, int)
              self.tokenizer = scripted_tokenizer
  
          @jit.script_method
          def forward(
              self,
              texts: Optional[List[str]] = None,
              multi_texts: Optional[List[List[str]]] = None,
              tokens: Optional[List[List[str]]] = None,
              languages: Optional[List[str]] = None,
          ):
              # PyTorch breaks with 2 'not None' checks right now.
              if texts is not None:
                  if tokens is not None:
                      raise RuntimeError(
                          "Can't set both tokens and texts"
                      )
                  if self.tokenizer is not None:
                      tokens = [
                          [t[0] for t in self.tokenizer.tokenize(text)]
                          for text in texts
                      ]
  
              if tokens is None:
                  raise RuntimeError("tokens is required")
  
              tokens = truncate_tokens(
                  tokens, self.max_seq_len, self.vocab.pad_token
              )
              seq_lens = make_sequence_lengths(tokens)
              word_ids = self.vocab.lookup_indices_2d(tokens)
              word_ids = pad_2d(word_ids, seq_lens, self.pad_idx)
              logits = self.model(
                  torch.tensor(word_ids), torch.tensor(seq_lens)
              )
              return self.output_layer(logits)
  
      class ModelWithDenseFeat(jit.ScriptModule):
          def __init__(self):
              super().__init__()
              self.vocab = ScriptVocabulary(
                  input_vocab,
                  input_vocab.get_unk_index(),
                  input_vocab.get_pad_index(),
              )
              self.normalizer = tensorizers["dense"].normalizer
              self.model = traced_model
              self.output_layer = output_layer
              self.pad_idx = jit.Attribute(
                  input_vocab.get_pad_index(), int
              )
              self.max_seq_len = jit.Attribute(max_seq_len, int)
              self.tokenizer = scripted_tokenizer
  
          @jit.script_method
          def forward(
              self,
              texts: Optional[List[str]] = None,
              multi_texts: Optional[List[List[str]]] = None,
              tokens: Optional[List[List[str]]] = None,
              languages: Optional[List[str]] = None,
              dense_feat: Optional[List[List[float]]] = None,
          ):
              # PyTorch breaks with 2 'not None' checks right now.
              if texts is not None:
                  if tokens is not None:
                      raise RuntimeError(
                          "Can't set both tokens and texts"
                      )
                  if self.tokenizer is not None:
                      tokens = [
                          [t[0] for t in self.tokenizer.tokenize(text)]
                          for text in texts
                      ]
  
              if tokens is None:
                  raise RuntimeError("tokens is required")
              if dense_feat is None:
                  raise RuntimeError("dense_feat is required")
  
              tokens = truncate_tokens(
                  tokens, self.max_seq_len, self.vocab.pad_token
              )
              seq_lens = make_sequence_lengths(tokens)
              word_ids = self.vocab.lookup_indices_2d(tokens)
              word_ids = pad_2d(word_ids, seq_lens, self.pad_idx)
              dense_feat = self.normalizer.normalize(dense_feat)
              logits = self.model(
                  torch.tensor(word_ids),
                  torch.tensor(seq_lens),
                  torch.tensor(dense_feat, dtype=torch.float),
              )
              return self.output_layer(logits)
  
      return ModelWithDenseFeat() if "dense" in tensorizers else Model()
  
imports: from typing import Dict, List, Optional, Union
  import torch
  from pytext.config.component import create_loss
  from pytext.data.tensorizers import ByteTokenTensorizer, FloatListTensorizer, LabelTensorizer, NumericLabelTensorizer, Tensorizer, TokenTensorizer, UidTensorizer, VocabConfig
  from pytext.data.tokenizers import DoNothingTokenizer
  from pytext.exporters.exporter import ModelExporter
  from pytext.loss import BinaryCrossEntropyLoss, BinaryCrossEntropyWithLogitsLoss, MultiLabelSoftMarginLoss
  from pytext.models.decoders.mlp_decoder import DecoderBase, MLPDecoder
  from pytext.models.embeddings import CharacterEmbedding, EmbeddingBase, EmbeddingList, WordEmbedding
  from pytext.models.model import Model
  from pytext.models.module import create_module
  from pytext.models.output_layers import ClassificationOutputLayer, OutputLayerBase, RegressionOutputLayer
  from pytext.models.output_layers.doc_classification_output_layer import BinaryClassificationOutputLayer, MulticlassOutputLayer, MultiLabelOutputLayer
  from pytext.models.representations.bilstm_doc_attention import BiLSTMDocAttention
  from pytext.models.representations.deepcnn import DeepCNNRepresentation
  from pytext.models.representations.docnn import DocNNRepresentation
  from pytext.models.representations.pure_doc_attention import PureDocAttention
  from pytext.models.representations.representation_base import RepresentationBase
  from pytext.torchscript.utils import make_byte_inputs, make_sequence_lengths, truncate_tokens
  from pytext.torchscript.vocab import ScriptVocabulary
  from pytext.utils.label import get_label_weights
  from pytext.utils.usage import log_class_usage
  from pytorch.text.fb.utils.transform_utils import pad_2d
  from torch import jit
label_desc: Use image node_id 8 for calling the DocModel obj's underlying member method code with example usage: obj.torchscriptify(tensorizers, traced_model) and returns: unknown, self, self