


'''simple docstring'''

import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch
@require_torch
class _lowerCamelCase	:



  '''simple docstring'''







  @property
  def        __lowerCAmelCase		( self		:						Tuple      )  ->			Optional[int]:
   return self.get_dummy_input()







  @property
  def        __lowerCAmelCase		( self		:						Optional[int]      )  ->			int:
   if self.block_type == "down":
    return (4, 32, 16, 16)
   elif self.block_type == "mid":
    return (4, 32, 32, 32)
   elif self.block_type == "up":
    return (4, 32, 64, 64)

   raise ValueError(F'\'{self.block_type}\' is not a supported block_type. Set it to \'up\', \'mid\', or \'down\'.'      )







  def        __lowerCAmelCase		( self		:						Optional[int]  ,					_A		:						List[str]=True  ,					_A		:						Tuple=False  ,					_A		:						List[str]=False  ,					_A		:						Union[str, Any]=False  ,					)  ->			Dict:
   __magic_name__	:   List[Any]					     =					4
   __magic_name__	:   Union[str, Any]					     =					32
   __magic_name__	:   Tuple					     =					(32, 32)

   __magic_name__	:   List[Any]					     =					torch.manual_seed(0      )
   __magic_name__	:   int					     =					torch.device(_A      )
   __magic_name__	:   int					     =					(batch_size, num_channels) + sizes
   __magic_name__	:   Optional[int]					     =					randn_tensor(_A  ,					generator=_A  ,					device=_A      )
   __magic_name__	:   Dict					     =					{'hidden_states': hidden_states}

   if include_temb:
    __magic_name__	:   int					     =					128
    __magic_name__	:   Optional[Any]					     =					randn_tensor((batch_size, temb_channels)  ,					generator=_A  ,					device=_A      )

   if include_res_hidden_states_tuple:
    __magic_name__	:   Union[str, Any]					     =					torch.manual_seed(1      )
    __magic_name__	:   Tuple					     =					(randn_tensor(_A  ,					generator=_A  ,					device=_A      ),)

   if include_encoder_hidden_states:
    __magic_name__	:   Optional[int]					     =					floats_tensor((batch_size, 32, 32)      ).to(_A      )

   if include_skip_sample:
    __magic_name__	:   Tuple					     =					randn_tensor(((batch_size, 3) + sizes)  ,					generator=_A  ,					device=_A      )

   return dummy_input







  def        __lowerCAmelCase		( self		:						Tuple      )  ->			Any:
   __magic_name__	:   Optional[Any]					     =					{
       'in_channels': 32,
       'out_channels': 32,
       'temb_channels': 128,
   }
   if self.block_type == "up":
    __magic_name__	:   str					     =					32

   if self.block_type == "mid":
    init_dict.pop('out_channels'      )

   __magic_name__	:   List[Any]					     =					self.dummy_input
   return init_dict, inputs_dict







  def        __lowerCAmelCase		( self		:						List[str]  ,					_A		:						Optional[Any]      )  ->			List[str]:
   __magic_name__	:   Union[str, Any]					     =					self.prepare_init_args_and_inputs_for_common()
   __magic_name__	:   Optional[Any]					     =					self.block_class(**_A      )
   unet_block.to(_A      )
   unet_block.eval()

   with torch.no_grad():
    __magic_name__	:   Tuple					     =					unet_block(**_A      )

   if isinstance(_A  ,					_A      ):
    __magic_name__	:   int					     =					output[0]

   self.assertEqual(output.shape  ,					self.output_shape      )

   __magic_name__	:   List[Any]					     =					output[0, -1, -3:, -3:]
   __magic_name__	:   int					     =					torch.tensor(_A      ).to(_A      )
   assert torch_all_close(output_slice.flatten()  ,					_A  ,					atol=5E-3      )







  @unittest.skipIf(torch_device == 'mps'  ,					'Training is not supported in mps'      )
  def        __lowerCAmelCase		( self		:						Any      )  ->			Dict:
   __magic_name__	:   List[Any]					     =					self.prepare_init_args_and_inputs_for_common()
   __magic_name__	:   List[Any]					     =					self.block_class(**_A      )
   model.to(_A      )
   model.train()
   __magic_name__	:   Optional[Any]					     =					model(**_A      )

   if isinstance(_A  ,					_A      ):
    __magic_name__	:   Optional[Any]					     =					output[0]

   __magic_name__	:   int					     =					torch.device(_A      )
   __magic_name__	:   Tuple					     =					randn_tensor(output.shape  ,					device=_A      )
   __magic_name__	:   Any					     =					torch.nn.functional.mse_loss(_A  ,					_A      )
   loss.backward()



'''simple docstring'''

# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
lowerCAmelCase				:Optional[int]        =      abspath(join(dirname(__file__), '''src'''))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='''ignore''', category=FutureWarning)





def lowerCamelCase      (      lowerCAmelCase    :     Tuple		):





	"""simple docstring"""







	config.addinivalue_line(
	    'markers'		,		'is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested'		)
	config.addinivalue_line(
	    'markers'		,		'is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested'		)
	config.addinivalue_line('markers'		,		'is_pipeline_test: mark test to run only when pipelines are tested'		)
	config.addinivalue_line('markers'		,		'is_staging_test: mark test to run only in the staging environment'		)
	config.addinivalue_line('markers'		,		'accelerate_tests: mark test that require accelerate'		)
	config.addinivalue_line('markers'		,		'tool_tests: mark the tool tests that are run on their specific schedule'		)





def lowerCamelCase      (      lowerCAmelCase    :     Any		):





	"""simple docstring"""







	from transformers.testing_utils import pytest_addoption_shared

	pytest_addoption_shared(lowerCAmelCase		)





def lowerCamelCase      (      lowerCAmelCase    :     Dict		):





	"""simple docstring"""







	from transformers.testing_utils import pytest_terminal_summary_main

	__magic_name__	:   Tuple					     =					terminalreporter.config.getoption('--make-reports'		)
	if make_reports:
		pytest_terminal_summary_main(lowerCAmelCase		,		id=lowerCAmelCase		)





def lowerCamelCase      (      lowerCAmelCase    :     List[Any]		,		lowerCAmelCase    :     Tuple		):





	"""simple docstring"""







	if exitstatus == 5:
		__magic_name__	:   Any					     =					0


# Doctest custom flag to ignore output.
lowerCAmelCase				:List[str]        =      doctest.register_optionflag('''IGNORE_RESULT''')

lowerCAmelCase				:Union[str, Any]        =      doctest.OutputChecker
class _lowerCamelCase	(						lowercase__							):



		'''simple docstring'''







		def        __lowerCAmelCase		( self		:						List[str]  ,					_A		:						Tuple  ,					_A		:						Tuple  ,					_A		:						str      )  ->			int:
			if IGNORE_RESULT & optionflags:
				return True
			return OutputChecker.check_output(self  ,					_A  ,					_A  ,					_A      )







lowerCAmelCase				:Optional[Any]        =      CustomOutputChecker
lowerCAmelCase				:int        =      HfDoctestModule





lowerCAmelCase				:Any        =      HfDocTestParser