
import math
from typing import Optional

import numpy as np
import torch
from torch import nn

from .activations import get_activation


def  A__ (       __lowerCamelCase,  __lowerCamelCase,  __lowerCamelCase = False,  __lowerCamelCase = 1,  __lowerCamelCase = 1,  __lowerCamelCase = 1_00_00,  ):
   assert len(timesteps.shape						) == 1, "Timesteps should be a 1d-array"

   SCREAMING_SNAKE_CASE_	=      embedding_dim // 2
   SCREAMING_SNAKE_CASE_	=      -math.log(__lowerCamelCase						) * torch.arange(
       start=0,  end=__lowerCamelCase,  dtype=torch.floataa,  device=timesteps.device						)
   SCREAMING_SNAKE_CASE_	=      exponent / (half_dim - downscale_freq_shift)

   SCREAMING_SNAKE_CASE_	=      torch.exp(__lowerCamelCase						)
   SCREAMING_SNAKE_CASE_	=      timesteps[:, None].float() * emb[None, :]

   # scale embeddings
   SCREAMING_SNAKE_CASE_	=      scale * emb

   # concat sine and cosine embeddings
   SCREAMING_SNAKE_CASE_	=      torch.cat([torch.sin(__lowerCamelCase						), torch.cos(__lowerCamelCase						)],  dim=-1						)

   # flip sine and cosine embeddings
   if flip_sin_to_cos:
      SCREAMING_SNAKE_CASE_	=      torch.cat([emb[:, half_dim:], emb[:, :half_dim]],  dim=-1						)

   # zero pad
   if embedding_dim % 2 == 1:
      SCREAMING_SNAKE_CASE_	=      torch.nn.functional.pad(__lowerCamelCase,  (0, 1, 0, 0)						)
   return emb


def  A__ (       __lowerCamelCase,  __lowerCamelCase,  __lowerCamelCase=False,  __lowerCamelCase=0						):
   SCREAMING_SNAKE_CASE_	=      np.arange(__lowerCamelCase,  dtype=np.floataa						)
   SCREAMING_SNAKE_CASE_	=      np.arange(__lowerCamelCase,  dtype=np.floataa						)
   SCREAMING_SNAKE_CASE_	=      np.meshgrid(__lowerCamelCase,  __lowerCamelCase						)  # here w goes first
   SCREAMING_SNAKE_CASE_	=      np.stack(__lowerCamelCase,  axis=0						)

   SCREAMING_SNAKE_CASE_	=      grid.reshape([2, 1, grid_size, grid_size]						)
   SCREAMING_SNAKE_CASE_	=      get_ad_sincos_pos_embed_from_grid(__lowerCamelCase,  __lowerCamelCase						)
   if cls_token and extra_tokens > 0:
      SCREAMING_SNAKE_CASE_	=      np.concatenate([np.zeros([extra_tokens, embed_dim]						), pos_embed],  axis=0						)
   return pos_embed


def  A__ (       __lowerCamelCase,  __lowerCamelCase						):
   if embed_dim % 2 != 0:
      raise ValueError('''embed_dim must be divisible by 2'''						)

   # use half of dimensions to encode grid_h
   SCREAMING_SNAKE_CASE_	=      get_ad_sincos_pos_embed_from_grid(embed_dim // 2,  grid[0]						)  # (H*W, D/2)
   SCREAMING_SNAKE_CASE_	=      get_ad_sincos_pos_embed_from_grid(embed_dim // 2,  grid[1]						)  # (H*W, D/2)

   SCREAMING_SNAKE_CASE_	=      np.concatenate([emb_h, emb_w],  axis=1						)  # (H*W, D)
   return emb


def  A__ (       __lowerCamelCase,  __lowerCamelCase						):
   if embed_dim % 2 != 0:
      raise ValueError('''embed_dim must be divisible by 2'''						)

   SCREAMING_SNAKE_CASE_	=      np.arange(embed_dim // 2,  dtype=np.floataa						)
   omega /= embed_dim / 2.0
   SCREAMING_SNAKE_CASE_	=      1.0 / 1_00_00**omega  # (D/2,)

   SCREAMING_SNAKE_CASE_	=      pos.reshape(-1						)  # (M,)
   SCREAMING_SNAKE_CASE_	=      np.einsum('''m,d->md''',  __lowerCamelCase,  __lowerCamelCase						)  # (M, D/2), outer product

   SCREAMING_SNAKE_CASE_	=      np.sin(__lowerCamelCase						)  # (M, D/2)
   SCREAMING_SNAKE_CASE_	=      np.cos(__lowerCamelCase						)  # (M, D/2)

   SCREAMING_SNAKE_CASE_	=      np.concatenate([emb_sin, emb_cos],  axis=1						)  # (M, D)
   return emb





class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A=224 ,     _A=224 ,     _A=16 ,     _A=3 ,     _A=768 ,     _A=False ,     _A=True ,     _A=True ,     )				->				Any:
          super().__init__()

          SCREAMING_SNAKE_CASE_	=      (height // patch_size) * (width // patch_size)
          SCREAMING_SNAKE_CASE_	=      flatten
          SCREAMING_SNAKE_CASE_	=      layer_norm

          SCREAMING_SNAKE_CASE_	=      nn.Convad(
              _A ,     _A ,     kernel_size=(patch_size, patch_size) ,     stride=_A ,     bias=_A	)
          if layer_norm:
             SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A ,     elementwise_affine=_A ,     eps=1E-6	)
          else:
             SCREAMING_SNAKE_CASE_	=      None

          SCREAMING_SNAKE_CASE_	=      get_ad_sincos_pos_embed(_A ,     int(num_patches**0.5	)	)
          self.register_buffer('''pos_embed''' ,     torch.from_numpy(_A	).float().unsqueeze(0	) ,     persistent=_A	)




       def     _UpperCamelCase	(							self ,     _A	)				->				str:
          SCREAMING_SNAKE_CASE_	=      self.proj(_A	)
          if self.flatten:
             SCREAMING_SNAKE_CASE_	=      latent.flatten(2	).transpose(1 ,     2	)  # BCHW -> BNC
          if self.layer_norm:
             SCREAMING_SNAKE_CASE_	=      self.norm(_A	)
          return latent + self.pos_embed







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A = "silu" ,     _A = None ,     _A = None ,     _A=None ,     )				->				Optional[Any]:
          super().__init__()

          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)

          if cond_proj_dim is not None:
             SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A ,     bias=_A	)
          else:
             SCREAMING_SNAKE_CASE_	=      None

          SCREAMING_SNAKE_CASE_	=      get_activation(_A	)

          if out_dim is not None:
             SCREAMING_SNAKE_CASE_	=      out_dim
          else:
             SCREAMING_SNAKE_CASE_	=      time_embed_dim
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)

          if post_act_fn is None:
             SCREAMING_SNAKE_CASE_	=      None
          else:
             SCREAMING_SNAKE_CASE_	=      get_activation(_A	)




       def     _UpperCamelCase	(							self ,     _A ,     _A=None	)				->				Union[str, Any]:
          if condition is not None:
             SCREAMING_SNAKE_CASE_	=      sample + self.cond_proj(_A	)
          SCREAMING_SNAKE_CASE_	=      self.linear_a(_A	)

          if self.act is not None:
             SCREAMING_SNAKE_CASE_	=      self.act(_A	)

          SCREAMING_SNAKE_CASE_	=      self.linear_a(_A	)

          if self.post_act is not None:
             SCREAMING_SNAKE_CASE_	=      self.post_act(_A	)
          return sample







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A	)				->				Dict:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      num_channels
          SCREAMING_SNAKE_CASE_	=      flip_sin_to_cos
          SCREAMING_SNAKE_CASE_	=      downscale_freq_shift




       def     _UpperCamelCase	(							self ,     _A	)				->				Optional[Any]:
          SCREAMING_SNAKE_CASE_	=      get_timestep_embedding(
              _A ,     self.num_channels ,     flip_sin_to_cos=self.flip_sin_to_cos ,     downscale_freq_shift=self.downscale_freq_shift ,     )
          return t_emb







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A = 256 ,     _A = 1.0 ,     _A=True ,     _A=True ,     _A=False	)				->				Optional[int]:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      nn.Parameter(torch.randn(_A	) * scale ,     requires_grad=_A	)
          SCREAMING_SNAKE_CASE_	=      log
          SCREAMING_SNAKE_CASE_	=      flip_sin_to_cos

          if set_W_to_weight:
             # to delete later
             SCREAMING_SNAKE_CASE_	=      nn.Parameter(torch.randn(_A	) * scale ,     requires_grad=_A	)

             SCREAMING_SNAKE_CASE_	=      self.W




       def     _UpperCamelCase	(							self ,     _A	)				->				List[str]:
          if self.log:
             SCREAMING_SNAKE_CASE_	=      torch.log(_A	)

          SCREAMING_SNAKE_CASE_	=      x[:, None] * self.weight[None, :] * 2 * np.pi

          if self.flip_sin_to_cos:
             SCREAMING_SNAKE_CASE_	=      torch.cat([torch.cos(_A	), torch.sin(_A	)] ,     dim=-1	)
          else:
             SCREAMING_SNAKE_CASE_	=      torch.cat([torch.sin(_A	), torch.cos(_A	)] ,     dim=-1	)
          return out







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A ,     _A ,     )				->				Tuple:
          super().__init__()

          SCREAMING_SNAKE_CASE_	=      height
          SCREAMING_SNAKE_CASE_	=      width
          SCREAMING_SNAKE_CASE_	=      num_embed
          SCREAMING_SNAKE_CASE_	=      embed_dim

          SCREAMING_SNAKE_CASE_	=      nn.Embedding(self.num_embed ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.Embedding(self.height ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.Embedding(self.width ,     _A	)




       def     _UpperCamelCase	(							self ,     _A	)				->				Optional[int]:
          SCREAMING_SNAKE_CASE_	=      self.emb(_A	)

          SCREAMING_SNAKE_CASE_	=      self.height_emb(torch.arange(self.height ,     device=index.device	).view(1 ,     self.height	)	)

          # 1 x H x D -> 1 x H x 1 x D
          SCREAMING_SNAKE_CASE_	=      height_emb.unsqueeze(2	)

          SCREAMING_SNAKE_CASE_	=      self.width_emb(torch.arange(self.width ,     device=index.device	).view(1 ,     self.width	)	)

          # 1 x W x D -> 1 x 1 x W x D
          SCREAMING_SNAKE_CASE_	=      width_emb.unsqueeze(1	)

          SCREAMING_SNAKE_CASE_	=      height_emb + width_emb

          # 1 x H x W x D -> 1 x L xD
          SCREAMING_SNAKE_CASE_	=      pos_emb.view(1 ,     self.height * self.width ,     -1	)

          SCREAMING_SNAKE_CASE_	=      emb + pos_emb[:, : emb.shape[1], :]

          return emb







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A	)				->				Tuple:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      dropout_prob > 0
          SCREAMING_SNAKE_CASE_	=      nn.Embedding(num_classes + use_cfg_embedding ,     _A	)
          SCREAMING_SNAKE_CASE_	=      num_classes
          SCREAMING_SNAKE_CASE_	=      dropout_prob



       def     _UpperCamelCase	(							self ,     _A ,     _A=None	)				->				Union[str, Any]:
          if force_drop_ids is None:
             SCREAMING_SNAKE_CASE_	=      torch.rand(labels.shape[0] ,     device=labels.device	) < self.dropout_prob
          else:
             SCREAMING_SNAKE_CASE_	=      torch.tensor(force_drop_ids == 1	)
          SCREAMING_SNAKE_CASE_	=      torch.where(_A ,     self.num_classes ,     _A	)
          return labels




       def     _UpperCamelCase	(							self ,     _A ,     _A=None	)				->				Optional[Any]:
          SCREAMING_SNAKE_CASE_	=      self.dropout_prob > 0
          if (self.training and use_dropout) or (force_drop_ids is not None):
             SCREAMING_SNAKE_CASE_	=      self.token_drop(_A ,     _A	)
          SCREAMING_SNAKE_CASE_	=      self.embedding_table(_A	)
          return embeddings







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A = 1024 ,     _A = 768 ,     _A = 768 ,     _A = 10 ,     )				->				Optional[Any]:
          super().__init__()

          SCREAMING_SNAKE_CASE_	=      num_image_text_embeds
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     self.num_image_text_embeds * cross_attention_dim	)
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)




       def     _UpperCamelCase	(							self ,     _A ,     _A	)				->				str:
          SCREAMING_SNAKE_CASE_	=      text_embeds.shape[0]

          # image
          SCREAMING_SNAKE_CASE_	=      self.image_embeds(_A	)
          SCREAMING_SNAKE_CASE_	=      image_text_embeds.reshape(_A ,     self.num_image_text_embeds ,     -1	)

          # text
          SCREAMING_SNAKE_CASE_	=      self.text_proj(_A	)

          return torch.cat([image_text_embeds, text_embeds] ,     dim=1	)







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A = 768 ,     _A = 768 ,     _A = 32 ,     )				->				Optional[Any]:
          super().__init__()

          SCREAMING_SNAKE_CASE_	=      num_image_text_embeds
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     self.num_image_text_embeds * cross_attention_dim	)
          SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A	)




       def     _UpperCamelCase	(							self ,     _A	)				->				Optional[int]:
          SCREAMING_SNAKE_CASE_	=      image_embeds.shape[0]

          # image
          SCREAMING_SNAKE_CASE_	=      self.image_embeds(_A	)
          SCREAMING_SNAKE_CASE_	=      image_embeds.reshape(_A ,     self.num_image_text_embeds ,     -1	)
          SCREAMING_SNAKE_CASE_	=      self.norm(_A	)
          return image_embeds







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A=0.1	)				->				Optional[int]:
          super().__init__()

          SCREAMING_SNAKE_CASE_	=      Timesteps(num_channels=256 ,     flip_sin_to_cos=_A ,     downscale_freq_shift=1	)
          SCREAMING_SNAKE_CASE_	=      TimestepEmbedding(in_channels=256 ,     time_embed_dim=_A	)
          SCREAMING_SNAKE_CASE_	=      LabelEmbedding(_A ,     _A ,     _A	)




       def     _UpperCamelCase	(							self ,     _A ,     _A ,     _A=None	)				->				Optional[Any]:
          SCREAMING_SNAKE_CASE_	=      self.time_proj(_A	)
          SCREAMING_SNAKE_CASE_	=      self.timestep_embedder(timesteps_proj.to(dtype=_A	)	)  # (N, D)

          SCREAMING_SNAKE_CASE_	=      self.class_embedder(_A	)  # (N, D)

          SCREAMING_SNAKE_CASE_	=      timesteps_emb + class_labels  # (N, D)

          return conditioning







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A = 64	)				->				Any:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A	)
          SCREAMING_SNAKE_CASE_	=      AttentionPooling(_A ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A	)




       def     _UpperCamelCase	(							self ,     _A	)				->				str:
          SCREAMING_SNAKE_CASE_	=      self.norma(_A	)
          SCREAMING_SNAKE_CASE_	=      self.pool(_A	)
          SCREAMING_SNAKE_CASE_	=      self.proj(_A	)
          SCREAMING_SNAKE_CASE_	=      self.norma(_A	)
          return hidden_states







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A = 768 ,     _A = 768 ,     _A = 1536	)				->				Union[str, Any]:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A	)
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)




       def     _UpperCamelCase	(							self ,     _A ,     _A	)				->				Tuple:
          # text
          SCREAMING_SNAKE_CASE_	=      self.text_proj(_A	)
          SCREAMING_SNAKE_CASE_	=      self.text_norm(_A	)

          # image
          SCREAMING_SNAKE_CASE_	=      self.image_proj(_A	)

          return time_image_embeds + time_text_embeds







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A = 768 ,     _A = 1536	)				->				Optional[int]:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A	)




       def     _UpperCamelCase	(							self ,     _A	)				->				Union[str, Any]:
          # image
          SCREAMING_SNAKE_CASE_	=      self.image_proj(_A	)
          SCREAMING_SNAKE_CASE_	=      self.image_norm(_A	)
          return time_image_embeds







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A = 768 ,     _A = 1536	)				->				Tuple:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A	)
          SCREAMING_SNAKE_CASE_	=      nn.LayerNorm(_A	)
          SCREAMING_SNAKE_CASE_	=      nn.Sequential(
              nn.Convad(3 ,     16 ,     3 ,     padding=1	) ,     nn.SiLU() ,     nn.Convad(16 ,     16 ,     3 ,     padding=1	) ,     nn.SiLU() ,     nn.Convad(16 ,     32 ,     3 ,     padding=1 ,     stride=2	) ,     nn.SiLU() ,     nn.Convad(32 ,     32 ,     3 ,     padding=1	) ,     nn.SiLU() ,     nn.Convad(32 ,     96 ,     3 ,     padding=1 ,     stride=2	) ,     nn.SiLU() ,     nn.Convad(96 ,     96 ,     3 ,     padding=1	) ,     nn.SiLU() ,     nn.Convad(96 ,     256 ,     3 ,     padding=1 ,     stride=2	) ,     nn.SiLU() ,     nn.Convad(256 ,     4 ,     3 ,     padding=1	) ,     )




       def     _UpperCamelCase	(							self ,     _A ,     _A	)				->				str:
          # image
          SCREAMING_SNAKE_CASE_	=      self.image_proj(_A	)
          SCREAMING_SNAKE_CASE_	=      self.image_norm(_A	)
          SCREAMING_SNAKE_CASE_	=      self.input_hint_block(_A	)
          return time_image_embeds, hint







class 				UpperCamelCase__		(	nn.Module	):






       """simple docstring"""


       def __init__(							self ,     _A ,     _A ,     _A=None	)				->				Dict:
          super().__init__()
          SCREAMING_SNAKE_CASE_	=      dtype
          SCREAMING_SNAKE_CASE_	=      nn.Parameter(torch.randn(1 ,     _A	) / embed_dim**0.5	)
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A ,     dtype=self.dtype	)
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A ,     dtype=self.dtype	)
          SCREAMING_SNAKE_CASE_	=      nn.Linear(_A ,     _A ,     dtype=self.dtype	)
          SCREAMING_SNAKE_CASE_	=      num_heads
          SCREAMING_SNAKE_CASE_	=      embed_dim // self.num_heads




       def     _UpperCamelCase	(							self ,     _A	)				->				str:
          SCREAMING_SNAKE_CASE_	, SCREAMING_SNAKE_CASE_	, SCREAMING_SNAKE_CASE_	=      x.size()

          def shape(_A	):
             # (bs, length, width) --> (bs, length, n_heads, dim_per_head)
             SCREAMING_SNAKE_CASE_	=      x.view(_A ,     -1 ,     self.num_heads ,     self.dim_per_head	)
             # (bs, length, n_heads, dim_per_head) --> (bs, n_heads, length, dim_per_head)
             SCREAMING_SNAKE_CASE_	=      x.transpose(1 ,     2	)
             # (bs, n_heads, length, dim_per_head) --> (bs*n_heads, length, dim_per_head)
             SCREAMING_SNAKE_CASE_	=      x.reshape(bs * self.num_heads ,     -1 ,     self.dim_per_head	)
             # (bs*n_heads, length, dim_per_head) --> (bs*n_heads, dim_per_head, length)
             SCREAMING_SNAKE_CASE_	=      x.transpose(1 ,     2	)
             return x

          SCREAMING_SNAKE_CASE_	=      x.mean(dim=1 ,     keepdim=_A	) + self.positional_embedding.to(x.dtype	)
          SCREAMING_SNAKE_CASE_	=      torch.cat([class_token, x] ,     dim=1	)  # (bs, length+1, width)

          # (bs*n_heads, class_token_length, dim_per_head)
          SCREAMING_SNAKE_CASE_	=      shape(self.q_proj(_A	)	)
          # (bs*n_heads, length+class_token_length, dim_per_head)
          SCREAMING_SNAKE_CASE_	=      shape(self.k_proj(_A	)	)
          SCREAMING_SNAKE_CASE_	=      shape(self.v_proj(_A	)	)

          # (bs*n_heads, class_token_length, length+class_token_length):
          SCREAMING_SNAKE_CASE_	=      1 / math.sqrt(math.sqrt(self.dim_per_head	)	)
          SCREAMING_SNAKE_CASE_	=      torch.einsum('''bct,bcs->bts''' ,     q * scale ,     k * scale	)  # More stable with f16 than dividing afterwards
          SCREAMING_SNAKE_CASE_	=      torch.softmax(weight.float() ,     dim=-1	).type(weight.dtype	)

          # (bs*n_heads, dim_per_head, class_token_length)
          SCREAMING_SNAKE_CASE_	=      torch.einsum('''bts,bcs->bct''' ,     _A ,     _A	)

          # (bs, length+1, width)
          SCREAMING_SNAKE_CASE_	=      a.reshape(_A ,     -1 ,     1	).transpose(1 ,     2	)

          return a[:, 0, :]  # cls_token




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__UpperCAmelCase   						=     {
    "configuration_donut_swin": ["DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP", "DonutSwinConfig"],
    "processing_donut": ["DonutProcessor"],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __UpperCAmelCase   						=     [
       "DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
       "DonutSwinModel",
       "DonutSwinPreTrainedModel",
   ]

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   __UpperCAmelCase   						=     ["DonutFeatureExtractor"]
   __UpperCAmelCase   						=     ["DonutImageProcessor"]


if TYPE_CHECKING:
   from .configuration_donut_swin import DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, DonutSwinConfig
   from .processing_donut import DonutProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_donut_swin import (
          DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
          DonutSwinModel,
          DonutSwinPreTrainedModel,
      )

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_donut import DonutFeatureExtractor
      from .image_processing_donut import DonutImageProcessor

else:
   import sys

   __UpperCAmelCase   						=     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


