class_docstr: Decoder based on Multilingual BART
  Set the initial weights and configuration with a pretrained multilingual BART model,
  and modify the detailed configurations as a Nougat decoder
  
  Args:
      decoder_layer:
          Number of layers of BARTDecoder
      max_position_embeddings:
          The maximum sequence length to be trained
      name_or_path:
          Name of a pretrained model name either registered in huggingface.co. or saved in local,
          otherwise, `facebook/mbart-large-50` will be set (using `transformers`)
class_docstr_tok: ["Decoder","based","on","Multilingual","BART","Set","the","initial","weights","and","configuration","with","a","pretrained","multilingual","BART","model",",","and","modify","the","detailed","configurations","as","a","Nougat","decoder","Args",":","decoder_layer",":","Number","of","layers","of","BARTDecoder","max_position_embeddings",":","The","maximum","sequence","length","to","be","trained","name_or_path",":","Name","of","a","pretrained","model","name","either","registered","in","huggingface.co",".","or","saved","in","local",",","otherwise",",","`","facebook\/mbart-large-50","`","will","be","set","(","using","`","transformers","`",")"]
docstr: Resize position embeddings
  Truncate if sequence length of MBart backbone is greater than given max_length,
  else interpolate to max_length
code: def resize_bart_abs_pos_emb(
      weight: torch.Tensor, max_length: int
  ) -> torch.Tensor:
      """
      Resize position embeddings
      Truncate if sequence length of MBart backbone is greater than given max_length,
      else interpolate to max_length
      """
      if weight.shape[0] > max_length:
          weight = weight[:max_length, ...]
      else:
          weight = (
              F.interpolate(
                  weight.permute(1, 0).unsqueeze(0),
                  size=max_length,
                  mode="linear",
                  align_corners=False,
              )
              .squeeze(0)
              .permute(1, 0)
          )
      return weight
  
imports: import logging
  import math
  import os
  from typing import List, Optional, Union
  from collections import defaultdict
  from pathlib import Path
  import numpy
  from PIL import Image
  import cv2
  import timm
  import torch
  import torch.nn
  import torch.nn.functional
  from PIL import ImageOps
  from timm.models.swin_transformer import SwinTransformer
  from torchvision.transforms.functional import resize, rotate
  from transformers import PreTrainedTokenizerFast, StoppingCriteria, StoppingCriteriaList, MBartConfig, MBartForCausalLM
  from transformers.file_utils import ModelOutput
  from transformers.modeling_utils import PretrainedConfig, PreTrainedModel
  from nougat.postprocessing import postprocess
  from nougat.transforms import train_transform, test_transform
label_desc: Use image node_id 5 for calling the BARTDecoder obj's underlying member method code with example usage: obj.resize_bart_abs_pos_emb(weight, max_length) and returns: weight