


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     UpperCAmelCase__       (					A_   ,  A_   ,  unittest.TestCase		):



    """simple docstring"""






    UpperCAmelCase__						:		Dict      =  VQModel
    UpperCAmelCase__						:		str      =  "sample"






    @property
    def _a					(			self					,   A_=(32, 32)    )  ->       str:
         __UpperCamelCase    							=4
         __UpperCamelCase    							=3

         __UpperCamelCase    							=floats_tensor((batch_size, num_channels) + sizes    ).to(A_    )

         return {"sample": image}






    @property
    def _a					(			self    )  ->       str:
         return (3, 32, 32)






    @property
    def _a					(			self    )  ->       Optional[int]:
         return (3, 32, 32)






    def _a					(			self    )  ->       Optional[Any]:
         __UpperCamelCase    							={
             'block_out_channels': [32, 64],
             '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 _a					(			self    )  ->       str:
         pass






    def _a					(			self    )  ->       List[str]:
         pass






    def _a					(			self    )  ->       int:
         __UpperCamelCase							,      __UpperCamelCase    							=VQModel.from_pretrained('fusing/vqgan-dummy'					,   output_loading_info=A_    )
         self.assertIsNotNone(A_    )
         self.assertEqual(len(loading_info['missing_keys']    )					,   0    )

         model.to(A_    )
         __UpperCamelCase    							=model(**self.dummy_input    )

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






    def _a					(			self    )  ->       Tuple:
         __UpperCamelCase    							=VQModel.from_pretrained('fusing/vqgan-dummy'    )
         model.to(A_    ).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(A_    )
         with torch.no_grad():
              __UpperCamelCase    							=model(A_    ).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(A_					,   A_					,   atol=1E-3    )    )









from typing import TYPE_CHECKING

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


_A		       =						{
    'configuration_convbert': ['CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ConvBertConfig', 'ConvBertOnnxConfig'],
    'tokenization_convbert': ['ConvBertTokenizer'],
}

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

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A		       =						[
       'CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'ConvBertForMaskedLM',
       'ConvBertForMultipleChoice',
       'ConvBertForQuestionAnswering',
       'ConvBertForSequenceClassification',
       'ConvBertForTokenClassification',
       'ConvBertLayer',
       'ConvBertModel',
       'ConvBertPreTrainedModel',
       'load_tf_weights_in_convbert',
   ]


try:
   if not is_tf_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _A		       =						[
       'TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TFConvBertForMaskedLM',
       'TFConvBertForMultipleChoice',
       'TFConvBertForQuestionAnswering',
       'TFConvBertForSequenceClassification',
       'TFConvBertForTokenClassification',
       'TFConvBertLayer',
       'TFConvBertModel',
       'TFConvBertPreTrainedModel',
   ]


if TYPE_CHECKING:
   from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
   from .tokenization_convbert import ConvBertTokenizer

   try:
      if not is_tokenizers_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .tokenization_convbert_fast import ConvBertTokenizerFast

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_convbert import (
          CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          ConvBertForMaskedLM,
          ConvBertForMultipleChoice,
          ConvBertForQuestionAnswering,
          ConvBertForSequenceClassification,
          ConvBertForTokenClassification,
          ConvBertLayer,
          ConvBertModel,
          ConvBertPreTrainedModel,
          load_tf_weights_in_convbert,
      )

   try:
      if not is_tf_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_tf_convbert import (
          TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
          TFConvBertForMaskedLM,
          TFConvBertForMultipleChoice,
          TFConvBertForQuestionAnswering,
          TFConvBertForSequenceClassification,
          TFConvBertForTokenClassification,
          TFConvBertLayer,
          TFConvBertModel,
          TFConvBertPreTrainedModel,
      )


else:
   import sys

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





