class_docstr: Nougat: Neural Optical UnderstandinG for Academic documents.
  The encoder converts an image of an academic document into a series of embeddings.
  Then, the decoder generates a sequence of tokens based on encoder's output.
  This sequence can be translated into a structured markup language format.
class_docstr_tok: ["Nougat",":","Neural","Optical","UnderstandinG","for","Academic","documents",".","The","encoder","converts","an","image","of","an","academic","document","into","a","series","of","embeddings",".","Then",",","the","decoder","generates","a","sequence","of","tokens","based","on","encoder","'s","output",".","This","sequence","can","be","translated","into","a","structured","markup","language","format","."]
docstr: Instantiate a pretrained nougat model from a pre-trained model configuration
  
  Args:
      model_path:
          Name of a pretrained model name either registered in huggingface.co. or saved in local.
code: def from_pretrained(
      cls,
      model_path: Union[str, bytes, os.PathLike],
      *model_args,
      **kwargs,
  ):
      r"""
      Instantiate a pretrained nougat model from a pre-trained model configuration
  
      Args:
          model_path:
              Name of a pretrained model name either registered in huggingface.co. or saved in local.
      """
      model = super(NougatModel, cls).from_pretrained(
          model_path, *model_args, **kwargs
      )
  
      # truncate or interpolate position embeddings of decoder
      max_length = kwargs.get(
          "max_length", model.config.max_position_embeddings
      )
      if (
          max_length != model.config.max_position_embeddings
      ):  # if max_length of trained model differs max_length you want to train
          model.decoder.model.model.decoder.embed_positions.weight = torch.nn.Parameter(
              model.decoder.resize_bart_abs_pos_emb(
                  model.decoder.model.model.decoder.embed_positions.weight,
                  max_length
                  + 2,  # https://github.com/huggingface/transformers/blob/v4.11.3/src/transformers/models/mbart/modeling_mbart.py#L118-L119
              )
          )
          model.config.max_position_embeddings = max_length
  
      return model
  
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 NougatModel obj's underlying member method code with example usage: obj.from_pretrained(cls, model_path) and returns: model