
'''simple docstring'''


import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()


class 						lowercase__	(  snake_case_,					snake_case_,					unittest.TestCase   ):






			'''simple docstring'''







			_snake_case		   =							VQModel
			_snake_case		   =							'''sample'''







			@property
			def       UpperCAmelCase				(			self ,   lowerCamelCase__=(3_2, 3_2)   ):

						'''simple docstring'''







						UpperCamelCase       =  4
						UpperCamelCase       =  3

						UpperCamelCase       =  floats_tensor((batch_size, num_channels) + sizes   ).to(lowerCamelCase__   )

						return {"sample": image}







			@property
			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						return (3, 3_2, 3_2)







			@property
			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						return (3, 3_2, 3_2)







			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						UpperCamelCase       =  {
						    '''block_out_channels''': [3_2, 6_4],
						    '''in_channels''': 3,
						    '''out_channels''': 3,
						    '''down_block_types''': ['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],
						    '''up_block_types''': ['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],
						    '''latent_channels''': 3,
						}
						UpperCamelCase       =  self.dummy_input
						return init_dict, inputs_dict







			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						pass







			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						pass







			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						UpperCamelCase     , UpperCamelCase       =  VQModel.from_pretrained('''fusing/vqgan-dummy''' ,   output_loading_info=lowerCamelCase__   )
						self.assertIsNotNone(lowerCamelCase__   )
						self.assertEqual(len(loading_info['''missing_keys''']   ) ,   0   )

						model.to(lowerCamelCase__   )
						UpperCamelCase       =  model(**self.dummy_input   )

						assert image is not None, "Make sure output is not None"







			def       UpperCAmelCase				(			self   ):

						'''simple docstring'''







						UpperCamelCase       =  VQModel.from_pretrained('''fusing/vqgan-dummy'''   )
						model.to(lowerCamelCase__   ).eval()

						torch.manual_seed(0   )
						if torch.cuda.is_available():
									torch.cuda.manual_seed_all(0   )

						UpperCamelCase       =  torch.randn(1 ,   model.config.in_channels ,   model.config.sample_size ,   model.config.sample_size   )
						UpperCamelCase       =  image.to(lowerCamelCase__   )
						with torch.no_grad():
									UpperCamelCase       =  model(lowerCamelCase__   ).sample

						UpperCamelCase       =  output[0, -1, -3:, -3:].flatten().cpu()
						# fmt: off
						UpperCamelCase       =  torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]   )
						# fmt: on
						self.assertTrue(torch.allclose(lowerCamelCase__ ,   lowerCamelCase__ ,   atol=1e-3   )   )







'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


snake_case_ :  Any     =					{
    'configuration_electra': ['ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ElectraConfig', 'ElectraOnnxConfig'],
    'tokenization_electra': ['ElectraTokenizer'],
}

try:
   if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   snake_case_ :  Union[str, Any]     =					['ElectraTokenizerFast']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   snake_case_ :  Tuple     =					[
       'ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST',
       'ElectraForCausalLM',
       'ElectraForMaskedLM',
       'ElectraForMultipleChoice',
       'ElectraForPreTraining',
       'ElectraForQuestionAnswering',
       'ElectraForSequenceClassification',
       'ElectraForTokenClassification',
       'ElectraModel',
       'ElectraPreTrainedModel',
       'load_tf_weights_in_electra',
   ]

try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   snake_case_ :  int     =					[
       'TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TFElectraForMaskedLM',
       'TFElectraForMultipleChoice',
       'TFElectraForPreTraining',
       'TFElectraForQuestionAnswering',
       'TFElectraForSequenceClassification',
       'TFElectraForTokenClassification',
       'TFElectraModel',
       'TFElectraPreTrainedModel',
   ]

try:
   if not is_flax_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   snake_case_ :  Optional[int]     =					[
       'FlaxElectraForCausalLM',
       'FlaxElectraForMaskedLM',
       'FlaxElectraForMultipleChoice',
       'FlaxElectraForPreTraining',
       'FlaxElectraForQuestionAnswering',
       'FlaxElectraForSequenceClassification',
       'FlaxElectraForTokenClassification',
       'FlaxElectraModel',
       'FlaxElectraPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
   from .tokenization_electra import ElectraTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_electra_fast import ElectraTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_electra import (
          ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
          ElectraForCausalLM,
          ElectraForMaskedLM,
          ElectraForMultipleChoice,
          ElectraForPreTraining,
          ElectraForQuestionAnswering,
          ElectraForSequenceClassification,
          ElectraForTokenClassification,
          ElectraModel,
          ElectraPreTrainedModel,
          load_tf_weights_in_electra,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_electra import (
          TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFElectraForMaskedLM,
          TFElectraForMultipleChoice,
          TFElectraForPreTraining,
          TFElectraForQuestionAnswering,
          TFElectraForSequenceClassification,
          TFElectraForTokenClassification,
          TFElectraModel,
          TFElectraPreTrainedModel,
      )

   try:
      if not is_flax_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_flax_electra import (
          FlaxElectraForCausalLM,
          FlaxElectraForMaskedLM,
          FlaxElectraForMultipleChoice,
          FlaxElectraForPreTraining,
          FlaxElectraForQuestionAnswering,
          FlaxElectraForSequenceClassification,
          FlaxElectraForTokenClassification,
          FlaxElectraModel,
          FlaxElectraPreTrainedModel,
      )

else:
   import sys

   snake_case_ :  Union[str, Any]     =					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





