
import flax.linen as nn
import jax
import jax.numpy as jnp



class 		UpperCamelCase__  (	nn.Module   ):
   _SCREAMING_SNAKE_CASE				:							Optional[Any]     	=				42
   _SCREAMING_SNAKE_CASE				:							List[str]     	=				jnp.floataa
   def 				lowerCAmelCase      (self			: Optional[int]       ):
    __a			:  Optional[int]		    =  nn.Conv(
        self.out_channels ,    kernel_size=(3, 3) ,    strides=(1, 1) ,    padding=((1, 1), (1, 1)) ,    dtype=self.dtype ,    )







   def __call__(self			: int ,    snake_case_			: Dict       ):
    __a			:  List[Any]		    =  hidden_states.shape
    __a			:  Union[str, Any]		    =  jax.image.resize(
        snake_case_ ,    shape=(batch, height * 2, width * 2, channels) ,    method='''nearest''' ,    )
    __a			:  Optional[Any]		    =  self.conv(snake_case_       )
    return hidden_states





class 		UpperCamelCase__  (	nn.Module   ):
   _SCREAMING_SNAKE_CASE				:							Tuple     	=				42
   _SCREAMING_SNAKE_CASE				:							List[Any]     	=				jnp.floataa
   def 				lowerCAmelCase      (self			: List[Any]       ):
    __a			:  List[str]		    =  nn.Conv(
        self.out_channels ,    kernel_size=(3, 3) ,    strides=(2, 2) ,    padding=((1, 1), (1, 1)) ,    dtype=self.dtype ,    )







   def __call__(self			: Dict ,    snake_case_			: str       ):
    # pad = ((0, 0), (0, 1), (0, 1), (0, 0))  # pad height and width dim
    # hidden_states = jnp.pad(hidden_states, pad_width=pad)
    __a			:  List[Any]		    =  self.conv(snake_case_       )
    return hidden_states





class 		UpperCamelCase__  (	nn.Module   ):
   _SCREAMING_SNAKE_CASE				:							int     	=				42
   _SCREAMING_SNAKE_CASE				:							Any     	=				None
   _SCREAMING_SNAKE_CASE				:							List[str]     	=				0.0
   _SCREAMING_SNAKE_CASE				:							Optional[int]     	=				None
   _SCREAMING_SNAKE_CASE				:							Any     	=				jnp.floataa
   def 				lowerCAmelCase      (self			: Union[str, Any]       ):
    __a			:  Optional[int]		    =  self.in_channels if self.out_channels is None else self.out_channels

    __a			:  Union[str, Any]		    =  nn.GroupNorm(num_groups=3_2 ,    epsilon=1E-5       )
    __a			:  str		    =  nn.Conv(
        snake_case_ ,    kernel_size=(3, 3) ,    strides=(1, 1) ,    padding=((1, 1), (1, 1)) ,    dtype=self.dtype ,    )

    __a			:  Any		    =  nn.Dense(snake_case_ ,    dtype=self.dtype       )

    __a			:  Optional[Any]		    =  nn.GroupNorm(num_groups=3_2 ,    epsilon=1E-5       )
    __a			:  Union[str, Any]		    =  nn.Dropout(self.dropout_prob       )
    __a			:  Dict		    =  nn.Conv(
        snake_case_ ,    kernel_size=(3, 3) ,    strides=(1, 1) ,    padding=((1, 1), (1, 1)) ,    dtype=self.dtype ,    )

    __a			:  Optional[Any]		    =  self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

    __a			:  Tuple		    =  None
    if use_nin_shortcut:
     __a			:  List[Any]		    =  nn.Conv(
         snake_case_ ,    kernel_size=(1, 1) ,    strides=(1, 1) ,    padding='''VALID''' ,    dtype=self.dtype ,    )







   def __call__(self			: Tuple ,    snake_case_			: Optional[Any] ,    snake_case_			: int ,    snake_case_			: Optional[Any]=True       ):
    __a			:  List[Any]		    =  hidden_states
    __a			:  Any		    =  self.norma(snake_case_       )
    __a			:  Optional[int]		    =  nn.swish(snake_case_       )
    __a			:  str		    =  self.conva(snake_case_       )

    __a			:  Optional[Any]		    =  self.time_emb_proj(nn.swish(snake_case_       )       )
    __a			:  Optional[Any]		    =  jnp.expand_dims(jnp.expand_dims(snake_case_ ,    1       ) ,    1       )
    __a			:  Any		    =  hidden_states + temb

    __a			:  Optional[Any]		    =  self.norma(snake_case_       )
    __a			:  Any		    =  nn.swish(snake_case_       )
    __a			:  Dict		    =  self.dropout(snake_case_ ,    snake_case_       )
    __a			:  Any		    =  self.conva(snake_case_       )

    if self.conv_shortcut is not None:
     __a			:  int		    =  self.conv_shortcut(snake_case_       )

    return hidden_states + residual


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


lowercase__          ={
    'configuration_layoutlmv2': ['LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'LayoutLMv2Config'],
    'processing_layoutlmv2': ['LayoutLMv2Processor'],
    'tokenization_layoutlmv2': ['LayoutLMv2Tokenizer'],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase__          =['LayoutLMv2TokenizerFast']

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase__          =['LayoutLMv2FeatureExtractor']
      lowercase__          =['LayoutLMv2ImageProcessor']

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase__          =[
          'LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST',
          'LayoutLMv2ForQuestionAnswering',
          'LayoutLMv2ForSequenceClassification',
          'LayoutLMv2ForTokenClassification',
          'LayoutLMv2Layer',
          'LayoutLMv2Model',
          'LayoutLMv2PreTrainedModel',
      ]

if TYPE_CHECKING:
      from .configuration_layoutlmva import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMvaConfig
      from .processing_layoutlmva import LayoutLMvaProcessor
      from .tokenization_layoutlmva import LayoutLMvaTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_layoutlmva_fast import LayoutLMvaTokenizerFast

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .feature_extraction_layoutlmva import LayoutLMvaFeatureExtractor, LayoutLMvaImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_layoutlmva import (
                LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
                LayoutLMvaForQuestionAnswering,
                LayoutLMvaForSequenceClassification,
                LayoutLMvaForTokenClassification,
                LayoutLMvaLayer,
                LayoutLMvaModel,
                LayoutLMvaPreTrainedModel,
            )
else:
      import sys

      lowercase__          =_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
