




'''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 					_a (a__,		a__,		unittest.TestCase	):





     '''simple docstring'''



     lowerCAmelCase_  :     Optional[Any]          =					VQModel
     lowerCAmelCase_  :     Tuple          =					"""sample"""







     @property
     def 			snake_case_      (				self							,__a=(32, 32)							)      ->				Dict:
          snake_case			:      Tuple        =			4
          snake_case			:      Optional[int]        =			3

          snake_case			:      Tuple        =			floats_tensor((batch_size, num_channels) + sizes							).to(__a							)

          return {"sample": image}







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







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







     def 			snake_case_      (				self							)      ->				str:
          snake_case			:      Tuple        =			{
              """block_out_channels""": [32, 64],
              """in_channels""": 3,
              """out_channels""": 3,
              """down_block_types""": ["""DownEncoderBlock2D""", """DownEncoderBlock2D"""],
              """up_block_types""": ["""UpDecoderBlock2D""", """UpDecoderBlock2D"""],
              """latent_channels""": 3,
          }
          snake_case			:      Any        =			self.dummy_input
          return init_dict, inputs_dict







     def 			snake_case_      (				self							)      ->				Dict:
          pass







     def 			snake_case_      (				self							)      ->				Any:
          pass







     def 			snake_case_      (				self							)      ->				int:
          snake_case ,		snake_case			:      List[str]        =			VQModel.from_pretrained("""fusing/vqgan-dummy"""							,output_loading_info=__a							)
          self.assertIsNotNone(__a							)
          self.assertEqual(len(loading_info["""missing_keys"""]							)							,0							)

          model.to(__a							)
          snake_case			:      int        =			model(**self.dummy_input							)

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







     def 			snake_case_      (				self							)      ->				List[str]:
          snake_case			:      str        =			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							)

          snake_case			:      Optional[Any]        =			torch.randn(1							,model.config.in_channels							,model.config.sample_size							,model.config.sample_size							)
          snake_case			:      Optional[Any]        =			image.to(__a							)
          with torch.no_grad():
               snake_case			:      Optional[Any]        =			model(__a							).sample

          snake_case			:      Optional[Any]        =			output[0, -1, -3:, -3:].flatten().cpu()
          # fmt: off
          snake_case			:      str        =			torch.tensor([-0.0_153, -0.4_044, -0.1_880, -0.5_161, -0.2_418, -0.4_072, -0.1_612, -0.0_633, -0.0_143]							)
          # fmt: on
          self.assertTrue(torch.allclose(__a							,__a							,atol=1E-3							)							)









'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase      :   Union[str, Any]      =       {
    """configuration_instructblip""": [
        """INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """InstructBlipConfig""",
        """InstructBlipQFormerConfig""",
        """InstructBlipVisionConfig""",
    ],
    """processing_instructblip""": ["""InstructBlipProcessor"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase      :   Union[str, Any]      =       [
          """INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """InstructBlipQFormerModel""",
          """InstructBlipPreTrainedModel""",
          """InstructBlipForConditionalGeneration""",
          """InstructBlipVisionModel""",
      ]

if TYPE_CHECKING:
      from .configuration_instructblip import (
          INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
          InstructBlipConfig,
          InstructBlipQFormerConfig,
          InstructBlipVisionConfig,
      )
      from .processing_instructblip import InstructBlipProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_instructblip import (
                INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                InstructBlipForConditionalGeneration,
                InstructBlipPreTrainedModel,
                InstructBlipQFormerModel,
                InstructBlipVisionModel,
            )

else:
      import sys

      lowercase      :   List[Any]      =       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



