class_docstr: Implements MASTER as described in paper: <https://arxiv.org/pdf/1910.02562.pdf>`_.
  Implementation based on the official Pytorch implementation: <https://github.com/wenwenyu/MASTER-pytorch>`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary, (without EOS, SOS, PAD)
      d_model: d parameter for the transformer decoder
      dff: depth of the pointwise feed-forward layer
      num_heads: number of heads for the mutli-head attention module
      num_layers: number of decoder layers to stack
      max_length: maximum length of character sequence handled by the model
      dropout: dropout probability of the decoder
      input_shape: size of the image inputs
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","MASTER","as","described","in","paper",":","<","https",":","\/\/arxiv.org\/pdf\/1910.02562.pdf",">","`","_",".","Implementation","based","on","the","official","Pytorch","implementation",":","<","https",":","\/\/github.com\/wenwenyu\/MASTER-pytorch",">","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary",",","(","without","EOS",",","SOS",",","PAD",")","d_model",":","d","parameter","for","the","transformer","decoder","dff",":","depth","of","the","pointwise","feed-forward","layer","num_heads",":","number","of","heads","for","the","mutli-head","attention","module","num_layers",":","number","of","decoder","layers","to","stack","max_length",":","maximum","length","of","character","sequence","handled","by","the","model","dropout",":","dropout","probability","of","the","decoder","input_shape",":","size","of","the","image","inputs","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
code: def make_source_and_target_mask(
      self, source: torch.Tensor, target: torch.Tensor
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      # borrowed and slightly modified from  https://github.com/wenwenyu/MASTER-pytorch
      # NOTE: nn.TransformerDecoder takes the inverse from this implementation
      # [True, True, True, ..., False, False, False] -> False is masked
      # (N, 1, 1, max_length)
      target_pad_mask = (target != self.vocab_size + 2).unsqueeze(1).unsqueeze(1)  # type: ignore[attr-defined]
      target_length = target.size(1)
      # sub mask filled diagonal with True = see and False = masked (max_length, max_length)
      # NOTE: onnxruntime tril/triu works only with float currently (onnxruntime 1.11.1 - opset 14)
      target_sub_mask = torch.tril(
          torch.ones(
              (target_length, target_length), device=source.device
          ),
          diagonal=0,
      ).to(dtype=torch.bool)
      # source mask filled with ones (max_length, positional_encoded_seq_len)
      source_mask = torch.ones(
          (target_length, source.size(1)),
          dtype=torch.uint8,
          device=source.device,
      )
      # combine the two masks into one (N, 1, max_length, max_length)
      target_mask = target_pad_mask & target_sub_mask
      return source_mask, target_mask.int()
  
imports: from copy import deepcopy
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision.models._utils import IntermediateLayerGetter
  from doctr.datasets import VOCABS
  from doctr.models.classification import magc_resnet31
  from doctr.models.modules.transformer import Decoder, PositionalEncoding
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from .base import _MASTER, _MASTERPostProcessor
label_desc: Use image node_id 2 for calling the MASTER obj's underlying member method code with example usage: obj.make_source_and_target_mask(source, target) and returns: source_mask,  target_mask