class_docstr: Implements a PARSeq architecture as described in `"Scene Text Recognition
  with Permuted Autoregressive Sequence Models" <https://arxiv.org/pdf/2207.06966>`_.
  Slightly modified implementation based on the official Pytorch implementation: <https://github.com/baudm/parseq/tree/main`_.
  
  Args:
  ----
      feature_extractor: the backbone serving as feature extractor
      vocab: vocabulary used for encoding
      embedding_units: number of embedding units
      max_length: maximum word length handled by the model
      dropout_prob: dropout probability for the decoder
      dec_num_heads: number of attention heads in the decoder
      dec_ff_dim: dimension of the feed forward layer in the decoder
      dec_ffd_ratio: depth multiplier for the feed forward layer in the decoder
      input_shape: input shape of the image
      exportable: onnx exportable returns only logits
      cfg: dictionary containing information about the model
class_docstr_tok: ["Implements","a","PARSeq","architecture","as","described","in","`","``","Scene","Text","Recognition","with","Permuted","Autoregressive","Sequence","Models","''","<","https",":","\/\/arxiv.org\/pdf\/2207.06966",">","`","_",".","Slightly","modified","implementation","based","on","the","official","Pytorch","implementation",":","<","https",":","\/\/github.com\/baudm\/parseq\/tree\/main","`","_",".","Args",":","--","--","feature_extractor",":","the","backbone","serving","as","feature","extractor","vocab",":","vocabulary","used","for","encoding","embedding_units",":","number","of","embedding","units","max_length",":","maximum","word","length","handled","by","the","model","dropout_prob",":","dropout","probability","for","the","decoder","dec_num_heads",":","number","of","attention","heads","in","the","decoder","dec_ff_dim",":","dimension","of","the","feed","forward","layer","in","the","decoder","dec_ffd_ratio",":","depth","multiplier","for","the","feed","forward","layer","in","the","decoder","input_shape",":","input","shape","of","the","image","exportable",":","onnx","exportable","returns","only","logits","cfg",":","dictionary","containing","information","about","the","model"]
code: def generate_permutations_attention_masks(
      self, permutation: torch.Tensor
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      # Generate source and target mask for the decoder attention.
      sz = permutation.shape[0]
      mask = torch.ones((sz, sz), device=permutation.device)
  
      for i in range(sz):
          query_idx = permutation[i]
          masked_keys = permutation[i + 1 :]
          mask[query_idx, masked_keys] = 0.0
      source_mask = mask[:-1, :-1].clone()
      mask[
          torch.eye(sz, dtype=torch.bool, device=permutation.device)
      ] = 0.0
      target_mask = mask[1:, :-1]
  
      return source_mask.int(), target_mask.int()
  
imports: import math
  from copy import deepcopy
  from itertools import permutations
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  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.modules.transformer import MultiHeadAttention, PositionwiseFeedForward
  from ...classification import vit_s
  from ...utils.pytorch import _bf16_to_float32, load_pretrained_params
  from .base import _PARSeq, _PARSeqPostProcessor
label_desc: Use image node_id 3 for calling the PARSeq obj's underlying member method code with example usage: obj.generate_permutations_attention_masks(permutation) and returns: source_mask,  target_mask