


'''simple docstring'''
import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_flax_cross_test,
    require_flax,
    require_torch,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import is_flax_available, is_torch_available, is_vision_available

from ...test_modeling_flax_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_flax_bert import FlaxBertModelTester
from ..clip.test_modeling_flax_clip import FlaxCLIPVisionModelTester
from ..vit.test_modeling_flax_vit import FlaxViTModelTester


if is_flax_available():
  from transformers import (
      FlaxBertModel,
      FlaxCLIPVisionModel,
      FlaxVisionTextDualEncoderModel,
      FlaxViTModel,
      VisionTextDualEncoderConfig,
      VisionTextDualEncoderProcessor,
  )
  from transformers.modeling_flax_pytorch_utils import (
      convert_pytorch_state_dict_to_flax,
      load_flax_weights_in_pytorch_model,
  )


if is_torch_available():
  import torch

  from transformers import VisionTextDualEncoderModel

if is_vision_available():
  from PIL import Image





def    a__			(   lowerCAmelCase__		)       ->      Any:
    if isinstance(lowerCAmelCase__    ,   collections.abc.Iterable		):
        return x
    return (x, x)




@require_flax
class      lowerCamelCase_  :






      def lowercase_				(   self							:       str		,		_A							:       Union[str, Any]		,		_A							:       List[Any]					):


          '''simple docstring'''


          pass






      def lowercase_				(   self							:       Optional[int]					):


          '''simple docstring'''


          pass






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          pass






      def lowercase_				(   self							:       List[Any]		,		_A							:       np.ndarray		,		_A							:       np.ndarray		,		_A							:       float					):


          '''simple docstring'''


          UpperCAmelCase__     :						int						=							np.abs((a - b)					).max()
          self.assertLessEqual(_A		,		_A		,		f"""Difference between torch and flax is {diff} (>= {tol})."""					)






      def lowercase_				(   self							:       Tuple		,		_A							:       Union[str, Any]		,		_A							:       Union[str, Any]		,		_A							:       Union[str, Any]		,		_A							:       Any		,		_A							:       Any=None		,		**_A							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[Any]						=							VisionTextDualEncoderConfig.from_vision_text_configs(_A		,		_A					)

          UpperCAmelCase__     :						Optional[int]						=							FlaxVisionTextDualEncoderModel(_A					)

          UpperCAmelCase__     :						Union[str, Any]						=							model(input_ids=_A		,		pixel_values=_A		,		attention_mask=_A					)

          self.assertEqual(output['''text_embeds'''].shape		,		(input_ids.shape[0], config.projection_dim)					)
          self.assertEqual(output['''image_embeds'''].shape		,		(pixel_values.shape[0], config.projection_dim)					)






      def lowercase_				(   self							:       Optional[int]		,		_A							:       List[Any]		,		_A							:       Tuple		,		_A							:       str		,		_A							:       str		,		_A							:       int=None		,		**_A							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__		,		UpperCAmelCase__     :						List[Any]						=							self.get_vision_text_model(_A		,		_A					)
          UpperCAmelCase__     :						int						=							{'''vision_model''': vision_model, '''text_model''': text_model}
          UpperCAmelCase__     :						List[Any]						=							FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_A					)

          UpperCAmelCase__     :						Any						=							model(input_ids=_A		,		pixel_values=_A		,		attention_mask=_A					)

          self.assertEqual(output['''text_embeds'''].shape		,		(input_ids.shape[0], model.config.projection_dim)					)
          self.assertEqual(output['''image_embeds'''].shape		,		(pixel_values.shape[0], model.config.projection_dim)					)






      def lowercase_				(   self							:       Dict		,		_A							:       Optional[int]		,		_A							:       Union[str, Any]		,		_A							:       List[str]		,		_A							:       str		,		_A							:       Optional[int]=None		,		**_A							:       Any					):


          '''simple docstring'''


          UpperCAmelCase__		,		UpperCAmelCase__     :						List[str]						=							self.get_vision_text_model(_A		,		_A					)
          UpperCAmelCase__     :						Optional[Any]						=							{'''vision_model''': vision_model, '''text_model''': text_model}
          UpperCAmelCase__     :						Tuple						=							FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_A					)

          UpperCAmelCase__     :						Any						=							model(input_ids=_A		,		pixel_values=_A		,		attention_mask=_A					)
          UpperCAmelCase__     :						Dict						=							output[0]

          with tempfile.TemporaryDirectory() as tmpdirname:
              model.save_pretrained(_A					)
              UpperCAmelCase__     :						Optional[Any]						=							FlaxVisionTextDualEncoderModel.from_pretrained(_A					)

              UpperCAmelCase__     :						Optional[Any]						=							model(input_ids=_A		,		pixel_values=_A		,		attention_mask=_A					)
              UpperCAmelCase__     :						Any						=							after_output[0]
              UpperCAmelCase__     :						str						=							np.amax(np.abs(out_a - out_a					)					)
              self.assertLessEqual(_A		,		1e-3					)






      def lowercase_				(   self							:       Tuple		,		_A							:       Dict		,		_A							:       Optional[Any]		,		_A							:       List[Any]		,		_A							:       List[Any]		,		_A							:       Dict=None		,		**_A							:       Optional[Any]					):


          '''simple docstring'''


          UpperCAmelCase__		,		UpperCAmelCase__     :						str						=							self.get_vision_text_model(_A		,		_A					)
          UpperCAmelCase__     :						List[str]						=							{'''vision_model''': vision_model, '''text_model''': text_model}
          UpperCAmelCase__     :						Dict						=							FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(**_A					)

          UpperCAmelCase__     :						Optional[Any]						=							model(
              input_ids=_A		,		pixel_values=_A		,		attention_mask=_A		,		output_attentions=_A					)

          UpperCAmelCase__     :						List[Any]						=							output.vision_model_output.attentions
          self.assertEqual(len(_A					)		,		vision_config.num_hidden_layers					)

          # in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
          UpperCAmelCase__     :						Dict						=							to_atuple(vision_model.config.image_size					)
          UpperCAmelCase__     :						List[Any]						=							to_atuple(vision_model.config.patch_size					)
          UpperCAmelCase__     :						Any						=							(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
          UpperCAmelCase__     :						Tuple						=							num_patches + 1
          self.assertEqual(vision_attentions[0].shape[-3:]		,		(vision_config.num_attention_heads, seq_len, seq_len)					)

          UpperCAmelCase__     :						List[Any]						=							output.text_model_output.attentions
          self.assertEqual(len(_A					)		,		text_config.num_hidden_layers					)

          self.assertEqual(
              text_attentions[0].shape[-3:]		,		(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])		,		)






      def lowercase_				(   self							:       List[str]		,		_A							:       Dict		,		_A							:       Any		,		_A							:       Tuple					):


          '''simple docstring'''


          pt_model.to(_A					)
          pt_model.eval()

          # prepare inputs
          UpperCAmelCase__     :						Any						=							inputs_dict
          UpperCAmelCase__     :						Optional[Any]						=							{k: torch.tensor(v.tolist()					) for k, v in flax_inputs.items()}

          with torch.no_grad():
              UpperCAmelCase__     :						int						=							pt_model(**_A					).to_tuple()

          UpperCAmelCase__     :						List[Any]						=							fx_model(**_A					).to_tuple()
          self.assertEqual(len(_A					)		,		len(_A					)		,		'''Output lengths differ between Flax and PyTorch'''					)
          for fx_output, pt_output in zip(fx_outputs[:4]		,		pt_outputs[:4]					):
              self.assert_almost_equals(_A		,		pt_output.numpy()		,		4e-2					)

          # PT -> Flax
          with tempfile.TemporaryDirectory() as tmpdirname:
              pt_model.save_pretrained(_A					)
              UpperCAmelCase__     :						int						=							FlaxVisionTextDualEncoderModel.from_pretrained(_A		,		from_pt=_A					)

          UpperCAmelCase__     :						Tuple						=							fx_model_loaded(**_A					).to_tuple()
          self.assertEqual(len(_A					)		,		len(_A					)		,		'''Output lengths differ between Flax and PyTorch'''					)
          for fx_output_loaded, pt_output in zip(fx_outputs_loaded[:4]		,		pt_outputs[:4]					):
              self.assert_almost_equals(_A		,		pt_output.numpy()		,		4e-2					)

          # Flax -> PT
          with tempfile.TemporaryDirectory() as tmpdirname:
              fx_model.save_pretrained(_A					)
              UpperCAmelCase__     :						Optional[int]						=							VisionTextDualEncoderModel.from_pretrained(_A		,		from_flax=_A					)

          pt_model_loaded.to(_A					)
          pt_model_loaded.eval()

          with torch.no_grad():
              UpperCAmelCase__     :						Any						=							pt_model_loaded(**_A					).to_tuple()

          self.assertEqual(len(_A					)		,		len(_A					)		,		'''Output lengths differ between Flax and PyTorch'''					)
          for fx_output, pt_output_loaded in zip(fx_outputs[:4]		,		pt_outputs_loaded[:4]					):
              self.assert_almost_equals(_A		,		pt_output_loaded.numpy()		,		4e-2					)






      def lowercase_				(   self							:       Union[str, Any]		,		_A							:       Optional[Any]		,		_A							:       List[str]		,		_A							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[str]						=							VisionTextDualEncoderConfig.from_vision_text_configs(_A		,		_A					)

          UpperCAmelCase__     :						Optional[int]						=							VisionTextDualEncoderModel(_A					)
          UpperCAmelCase__     :						Tuple						=							FlaxVisionTextDualEncoderModel(_A					)

          UpperCAmelCase__     :						Union[str, Any]						=							convert_pytorch_state_dict_to_flax(pt_model.state_dict()		,		_A					)
          UpperCAmelCase__     :						Union[str, Any]						=							fx_state

          self.check_pt_flax_equivalence(_A		,		_A		,		_A					)






      def lowercase_				(   self							:       List[Any]		,		_A							:       Optional[Any]		,		_A							:       int		,		_A							:       Dict					):


          '''simple docstring'''


          UpperCAmelCase__     :						str						=							VisionTextDualEncoderConfig.from_vision_text_configs(_A		,		_A					)

          UpperCAmelCase__     :						Optional[Any]						=							VisionTextDualEncoderModel(_A					)
          UpperCAmelCase__     :						int						=							FlaxVisionTextDualEncoderModel(_A					)

          UpperCAmelCase__     :						Optional[Any]						=							load_flax_weights_in_pytorch_model(_A		,		fx_model.params					)

          self.check_pt_flax_equivalence(_A		,		_A		,		_A					)






      def lowercase_				(   self							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[int]						=							self.prepare_config_and_inputs()
          self.check_model_from_pretrained_configs(**_A					)






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          UpperCAmelCase__     :						Any						=							self.prepare_config_and_inputs()
          self.check_vision_text_dual_encoder_from_pretrained(**_A					)






      def lowercase_				(   self							:       str					):


          '''simple docstring'''


          UpperCAmelCase__     :						Dict						=							self.prepare_config_and_inputs()
          self.check_save_load(**_A					)






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          UpperCAmelCase__     :						str						=							self.prepare_config_and_inputs()
          self.check_vision_text_output_attention(**_A					)






      @is_pt_flax_cross_test
      def lowercase_				(   self							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[str]						=							self.prepare_config_and_inputs()
          UpperCAmelCase__     :						Optional[int]						=							config_inputs_dict.pop('''vision_config'''					)
          UpperCAmelCase__     :						List[str]						=							config_inputs_dict.pop('''text_config'''					)

          UpperCAmelCase__     :						List[str]						=							config_inputs_dict

          self.check_equivalence_pt_to_flax(_A		,		_A		,		_A					)
          self.check_equivalence_flax_to_pt(_A		,		_A		,		_A					)






      @slow
      def lowercase_				(   self							:       List[str]					):


          '''simple docstring'''


          UpperCAmelCase__		,		UpperCAmelCase__     :						Union[str, Any]						=							self.get_pretrained_model_and_inputs()

          UpperCAmelCase__     :						Union[str, Any]						=							model_a(**_A					)
          UpperCAmelCase__     :						Tuple						=							outputs[0]

          with tempfile.TemporaryDirectory() as tmp_dirname:
              model_a.save_pretrained(_A					)
              UpperCAmelCase__     :						Tuple						=							FlaxVisionTextDualEncoderModel.from_pretrained(_A					)

              UpperCAmelCase__     :						str						=							model_a(**_A					)
              UpperCAmelCase__     :						Optional[Any]						=							after_outputs[0]
              UpperCAmelCase__     :						Dict						=							np.amax(np.abs(out_a - out_a					)					)
              self.assertLessEqual(_A		,		1e-5					)




@require_flax
class      lowerCamelCase_  (      __a	,			unittest.TestCase ):






      def lowercase_				(   self							:       int					):


          '''simple docstring'''


          UpperCAmelCase__     :						Dict						=							FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(
              '''hf-internal-testing/tiny-random-vit'''		,		'''hf-internal-testing/tiny-bert'''		,		vision_from_pt=_A		,		text_from_pt=_A		,		)
          UpperCAmelCase__     :						List[str]						=							13
          UpperCAmelCase__     :						int						=							floats_tensor(
              [
                  batch_size,
                  model.config.vision_config.num_channels,
                  model.config.vision_config.image_size,
                  model.config.vision_config.image_size,
              ]					)
          UpperCAmelCase__     :						Any						=							ids_tensor([batch_size, 4]		,		model.config.text_config.vocab_size					)
          UpperCAmelCase__     :						List[str]						=							random_attention_mask([batch_size, 4]					)
          UpperCAmelCase__     :						Tuple						=							{'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

          return model, inputs






      def lowercase_				(   self							:       int		,		_A							:       Union[str, Any]		,		_A							:       List[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[int]						=							FlaxViTModel(_A					)
          UpperCAmelCase__     :						List[Any]						=							FlaxBertModel(_A					)
          return vision_model, text_model






      def lowercase_				(   self							:       Optional[int]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[str]						=							FlaxViTModelTester(self					)
          UpperCAmelCase__     :						List[str]						=							FlaxBertModelTester(self					)
          UpperCAmelCase__     :						str						=							vit_model_tester.prepare_config_and_inputs()
          UpperCAmelCase__     :						Dict						=							bert_model_tester.prepare_config_and_inputs()

          UpperCAmelCase__		,		UpperCAmelCase__     :						List[str]						=							vision_config_and_inputs

          UpperCAmelCase__		,		UpperCAmelCase__		,		UpperCAmelCase__		,		UpperCAmelCase__     :						Dict						=							text_config_and_inputs

          # make sure that cross attention layers are added
          return {
              "text_config": text_config,
              "vision_config": vision_config,
              "pixel_values": pixel_values,
              "attention_mask": attention_mask,
              "input_ids": input_ids,
              "token_type_ids": token_type_ids,
          }




@require_torch
class      lowerCamelCase_  (      __a	,			unittest.TestCase ):






      def lowercase_				(   self							:       Union[str, Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						List[Any]						=							FlaxVisionTextDualEncoderModel.from_vision_text_pretrained(
              '''hf-internal-testing/tiny-random-clip'''		,		'''hf-internal-testing/tiny-bert'''		,		vision_from_pt=_A		,		text_from_pt=_A		,		)
          UpperCAmelCase__     :						List[Any]						=							13
          UpperCAmelCase__     :						Dict						=							floats_tensor(
              [
                  batch_size,
                  model.config.vision_config.num_channels,
                  model.config.vision_config.image_size,
                  model.config.vision_config.image_size,
              ]					)
          UpperCAmelCase__     :						Optional[int]						=							ids_tensor([batch_size, 4]		,		model.config.text_config.vocab_size					)
          UpperCAmelCase__     :						Tuple						=							random_attention_mask([batch_size, 4]					)
          UpperCAmelCase__     :						Any						=							{'''pixel_values''': pixel_values, '''input_ids''': input_ids, '''attention_mask''': attention_mask}

          return model, inputs






      def lowercase_				(   self							:       int		,		_A							:       Any		,		_A							:       Optional[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						Dict						=							FlaxCLIPVisionModel(_A					)
          UpperCAmelCase__     :						int						=							FlaxBertModel(_A					)
          return vision_model, text_model






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          UpperCAmelCase__     :						Union[str, Any]						=							FlaxCLIPVisionModelTester(self					)
          UpperCAmelCase__     :						List[str]						=							FlaxBertModelTester(self					)
          UpperCAmelCase__     :						Tuple						=							clip_model_tester.prepare_config_and_inputs()
          UpperCAmelCase__     :						Optional[Any]						=							bert_model_tester.prepare_config_and_inputs()

          UpperCAmelCase__		,		UpperCAmelCase__     :						Union[str, Any]						=							vision_config_and_inputs

          UpperCAmelCase__		,		UpperCAmelCase__		,		UpperCAmelCase__		,		UpperCAmelCase__     :						Optional[Any]						=							text_config_and_inputs

          # make sure that cross attention layers are added
          return {
              "text_config": text_config,
              "vision_config": vision_config,
              "pixel_values": pixel_values,
              "attention_mask": attention_mask,
              "input_ids": input_ids,
              "token_type_ids": token_type_ids,
          }




@require_flax
@require_vision
class      lowerCamelCase_  (      unittest.TestCase ):






      @slow
      def lowercase_				(   self							:       Dict					):


          '''simple docstring'''


          UpperCAmelCase__     :						str						=							FlaxVisionTextDualEncoderModel.from_pretrained('''clip-italian/clip-italian'''		,		logit_scale_init_value=1.0					)
          UpperCAmelCase__     :						int						=							VisionTextDualEncoderProcessor.from_pretrained('''clip-italian/clip-italian'''					)

          UpperCAmelCase__     :						Optional[Any]						=							Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''					)
          UpperCAmelCase__     :						Optional[int]						=							processor(
              text=['''una foto di un gatto''', '''una foto di un cane''']		,		images=_A		,		padding=_A		,		return_tensors='''np'''					)

          UpperCAmelCase__     :						List[str]						=							model(**_A					)

          # verify the logits
          self.assertEqual(outputs.logits_per_image.shape		,		(inputs.pixel_values.shape[0], inputs.input_ids.shape[0])					)
          self.assertEqual(
              outputs.logits_per_text.shape		,		(inputs.input_ids.shape[0], inputs.pixel_values.shape[0])		,		)

          UpperCAmelCase__     :						Tuple						=							np.array([[1.2_2_8_4_7_2_7, 0.3_1_0_4_1_2_2]]					)

          self.assertTrue(np.allclose(outputs.logits_per_image		,		_A		,		atol=1e-3					)					)



'''simple docstring'''





from dataclasses import asdict, dataclass
from typing import Optional

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase_    						=       logging.get_logger(__name__)

# TODO Update this
UpperCamelCase_    						=       {
    """facebook/esm-1b""": """https://huggingface.co/facebook/esm-1b/resolve/main/config.json""",
    # See all ESM models at https://huggingface.co/models?filter=esm
}





class 		__SCREAMING_SNAKE_CASE							(			lowercase__      ):
				lowerCamelCase_		       =    'esm'







				def __init__(       self     :		Optional[Any]		,					UpperCAmelCase__     :		str=None		,					UpperCAmelCase__     :		Dict=None		,					UpperCAmelCase__     :		Any=None		,					UpperCAmelCase__     :		int=768		,					UpperCAmelCase__     :		Union[str, Any]=12		,					UpperCAmelCase__     :		List[Any]=12		,					UpperCAmelCase__     :		Optional[Any]=3072		,					UpperCAmelCase__     :		Dict=0.1		,					UpperCAmelCase__     :		int=0.1		,					UpperCAmelCase__     :		int=1026		,					UpperCAmelCase__     :		Tuple=0.02		,					UpperCAmelCase__     :		Optional[int]=1E-12		,					UpperCAmelCase__     :		List[Any]="absolute"		,					UpperCAmelCase__     :		int=True		,					UpperCAmelCase__     :		Dict=None		,					UpperCAmelCase__     :		str=False		,					UpperCAmelCase__     :		int=False		,					UpperCAmelCase__     :		Optional[Any]=None		,					UpperCAmelCase__     :		List[str]=None		,					**UpperCAmelCase__     :		int		,					):
										'''simple docstring'''
										super().__init__(pad_token_id=UpperCAmelCase__		,					mask_token_id=UpperCAmelCase__		,					**UpperCAmelCase__   )

										lowercase :							Any    		=vocab_size
										lowercase :							List[Any]    		=hidden_size
										lowercase :							Any    		=num_hidden_layers
										lowercase :							Optional[Any]    		=num_attention_heads
										lowercase :							Tuple    		=intermediate_size
										lowercase :							int    		=hidden_dropout_prob
										lowercase :							Dict    		=attention_probs_dropout_prob
										lowercase :							Optional[int]    		=max_position_embeddings
										lowercase :							Union[str, Any]    		=initializer_range
										lowercase :							Tuple    		=layer_norm_eps
										lowercase :							Union[str, Any]    		=position_embedding_type
										lowercase :							List[Any]    		=use_cache
										lowercase :							Dict    		=emb_layer_norm_before
										lowercase :							Optional[Any]    		=token_dropout
										lowercase :							Union[str, Any]    		=is_folding_model
										if is_folding_model:
																if esmfold_config is None:
																						logger.info('''No esmfold_config supplied for folding model, using default values.'''   )
																						lowercase :							Any    		=EsmFoldConfig()
																elif isinstance(UpperCAmelCase__		,					UpperCAmelCase__   ):
																						lowercase :							Optional[int]    		=EsmFoldConfig(**UpperCAmelCase__   )
																lowercase :							Union[str, Any]    		=esmfold_config
																if vocab_list is None:
																						logger.warning('''No vocab_list supplied for folding model, assuming the ESM-2 vocabulary!'''   )
																						lowercase :							int    		=get_default_vocab_list()
																else:
																						lowercase :							Tuple    		=vocab_list
										else:
																lowercase :							Union[str, Any]    		=None
																lowercase :							Dict    		=None
										if self.esmfold_config is not None and getattr(self.esmfold_config		,					'''use_esm_attn_map'''		,					UpperCAmelCase__   ):
																raise ValueError('''The HuggingFace port of ESMFold does not support use_esm_attn_map at this time!'''   )







				def  lowerCamelCase_	(       self     :		Union[str, Any]   ):
										'''simple docstring'''
										lowercase :							Union[str, Any]    		=super().to_dict()
										if isinstance(self.esmfold_config		,					UpperCAmelCase__   ):
																lowercase :							Optional[Any]    		=self.esmfold_config.to_dict()
										return output





@dataclass
class 		__SCREAMING_SNAKE_CASE							:
				lowerCamelCase_		       =    None
				lowerCamelCase_		       =    True
				lowerCamelCase_		       =    False
				lowerCamelCase_		       =    False
				lowerCamelCase_		       =    False
				lowerCamelCase_		       =    0

				lowerCamelCase_		       =    True
				lowerCamelCase_		       =    False

				lowerCamelCase_		       =    1_28
				lowerCamelCase_		       =    None







				def  lowerCamelCase_	(       self     :		Tuple   ):
										'''simple docstring'''
										if self.trunk is None:
																lowercase :							str    		=TrunkConfig()
										elif isinstance(self.trunk		,					UpperCAmelCase__   ):
																lowercase :							int    		=TrunkConfig(**self.trunk   )







				def  lowerCamelCase_	(       self     :		List[Any]   ):
										'''simple docstring'''
										lowercase :							str    		=asdict(self   )
										lowercase :							Union[str, Any]    		=self.trunk.to_dict()
										return output





@dataclass
class 		__SCREAMING_SNAKE_CASE							:
				lowerCamelCase_		       =    48
				lowerCamelCase_		       =    10_24
				lowerCamelCase_		       =    1_28
				lowerCamelCase_		       =    32
				lowerCamelCase_		       =    32
				lowerCamelCase_		       =    32
				lowerCamelCase_		       =    0
				lowerCamelCase_		       =    0
				lowerCamelCase_		       =    False
				lowerCamelCase_		       =    4
				lowerCamelCase_		       =    1_28
				lowerCamelCase_		       =    None







				def  lowerCamelCase_	(       self     :		List[str]   ):
										'''simple docstring'''
										if self.structure_module is None:
																lowercase :							Any    		=StructureModuleConfig()
										elif isinstance(self.structure_module		,					UpperCAmelCase__   ):
																lowercase :							Union[str, Any]    		=StructureModuleConfig(**self.structure_module   )

										if self.max_recycles <= 0:
																raise ValueError(F'''`max_recycles` should be positive, got {self.max_recycles}.'''   )
										if self.sequence_state_dim % self.sequence_state_dim != 0:
																raise ValueError(
																    '''`sequence_state_dim` should be a round multiple of `sequence_state_dim`, got'''
																    F''' {self.sequence_state_dim} and {self.sequence_state_dim}.'''   )
										if self.pairwise_state_dim % self.pairwise_state_dim != 0:
																raise ValueError(
																    '''`pairwise_state_dim` should be a round multiple of `pairwise_state_dim`, got'''
																    F''' {self.pairwise_state_dim} and {self.pairwise_state_dim}.'''   )

										lowercase :							str    		=self.sequence_state_dim // self.sequence_head_width
										lowercase :							int    		=self.pairwise_state_dim // self.pairwise_head_width

										if self.sequence_state_dim != sequence_num_heads * self.sequence_head_width:
																raise ValueError(
																    '''`sequence_state_dim` should be equal to `sequence_num_heads * sequence_head_width, got'''
																    F''' {self.sequence_state_dim} != {sequence_num_heads} * {self.sequence_head_width}.'''   )
										if self.pairwise_state_dim != pairwise_num_heads * self.pairwise_head_width:
																raise ValueError(
																    '''`pairwise_state_dim` should be equal to `pairwise_num_heads * pairwise_head_width, got'''
																    F''' {self.pairwise_state_dim} != {pairwise_num_heads} * {self.pairwise_head_width}.'''   )
										if self.pairwise_state_dim % 2 != 0:
																raise ValueError(F'''`pairwise_state_dim` should be even, got {self.pairwise_state_dim}.'''   )

										if self.dropout >= 0.4:
																raise ValueError(F'''`dropout` should not be greater than 0.4, got {self.dropout}.'''   )







				def  lowerCamelCase_	(       self     :		Any   ):
										'''simple docstring'''
										lowercase :							List[Any]    		=asdict(self   )
										lowercase :							Any    		=self.structure_module.to_dict()
										return output





@dataclass
class 		__SCREAMING_SNAKE_CASE							:
				lowerCamelCase_		       =    3_84
				lowerCamelCase_		       =    1_28
				lowerCamelCase_		       =    16
				lowerCamelCase_		       =    1_28
				lowerCamelCase_		       =    12
				lowerCamelCase_		       =    4
				lowerCamelCase_		       =    8
				lowerCamelCase_		       =    0.1
				lowerCamelCase_		       =    8
				lowerCamelCase_		       =    1
				lowerCamelCase_		       =    2
				lowerCamelCase_		       =    7
				lowerCamelCase_		       =    10
				lowerCamelCase_		       =    1E-8
				lowerCamelCase_		       =    1E5







				def  lowerCamelCase_	(       self     :		Dict   ):
										'''simple docstring'''
										return asdict(self   )






def 				_lowerCAmelCase			(   )				->  Optional[int]:
						return (
						    "<cls>",
						    "<pad>",
						    "<eos>",
						    "<unk>",
						    "L",
						    "A",
						    "G",
						    "V",
						    "S",
						    "E",
						    "R",
						    "T",
						    "I",
						    "D",
						    "P",
						    "K",
						    "Q",
						    "N",
						    "F",
						    "Y",
						    "M",
						    "H",
						    "W",
						    "C",
						    "X",
						    "B",
						    "U",
						    "Z",
						    "O",
						    ".",
						    "-",
						    "<null_1>",
						    "<mask>",
						)





