






"""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      a						:






    @property
    def    UpperCamelCase       (       self     :							Tuple					)     ->		Dict:
      return self.get_dummy_input()






    @property
    def    UpperCamelCase       (       self     :							int					)     ->		str:
      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    UpperCamelCase       (       self     :							Any       ,						__SCREAMING_SNAKE_CASE     :							List[str]=True       ,						__SCREAMING_SNAKE_CASE     :							int=False       ,						__SCREAMING_SNAKE_CASE     :							List[Any]=False       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]=False       ,						)     ->		Dict:
      lowerCamelCase_         =						4
      lowerCamelCase_         =						32
      lowerCamelCase_         =						(32, 32)

      lowerCamelCase_         =						torch.manual_seed(0					)
      lowerCamelCase_         =						torch.device(_lowerCamelCase					)
      lowerCamelCase_         =						(batch_size, num_channels) + sizes
      lowerCamelCase_         =						randn_tensor(_lowerCamelCase       ,						generator=_lowerCamelCase       ,						device=_lowerCamelCase					)
      lowerCamelCase_         =						{'hidden_states': hidden_states}

      if include_temb:
        lowerCamelCase_         =						128
        lowerCamelCase_         =						randn_tensor((batch_size, temb_channels)       ,						generator=_lowerCamelCase       ,						device=_lowerCamelCase					)

      if include_res_hidden_states_tuple:
        lowerCamelCase_         =						torch.manual_seed(1					)
        lowerCamelCase_         =						(randn_tensor(_lowerCamelCase       ,						generator=_lowerCamelCase       ,						device=_lowerCamelCase					),)

      if include_encoder_hidden_states:
        lowerCamelCase_         =						floats_tensor((batch_size, 32, 32)					).to(_lowerCamelCase					)

      if include_skip_sample:
        lowerCamelCase_         =						randn_tensor(((batch_size, 3) + sizes)       ,						generator=_lowerCamelCase       ,						device=_lowerCamelCase					)

      return dummy_input






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

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

      lowerCamelCase_         =						self.dummy_input
      return init_dict, inputs_dict






    def    UpperCamelCase       (       self     :							int       ,						__SCREAMING_SNAKE_CASE     :							Optional[int]					)     ->		Optional[int]:
      lowerCamelCase_     ,	lowerCamelCase_         =						self.prepare_init_args_and_inputs_for_common()
      lowerCamelCase_         =						self.block_class(**_lowerCamelCase					)
      unet_block.to(_lowerCamelCase					)
      unet_block.eval()

      with torch.no_grad():
        lowerCamelCase_         =						unet_block(**_lowerCamelCase					)

      if isinstance(_lowerCamelCase       ,						_lowerCamelCase					):
        lowerCamelCase_         =						output[0]

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

      lowerCamelCase_         =						output[0, -1, -3:, -3:]
      lowerCamelCase_         =						torch.tensor(_lowerCamelCase					).to(_lowerCamelCase					)
      assert torch_all_close(output_slice.flatten()       ,						_lowerCamelCase       ,						atol=5e-3					)






    @unittest.skipIf(torch_device == 'mps'       ,						'Training is not supported in mps'					)
    def    UpperCamelCase       (       self     :							int					)     ->		Dict:
      lowerCamelCase_     ,	lowerCamelCase_         =						self.prepare_init_args_and_inputs_for_common()
      lowerCamelCase_         =						self.block_class(**_lowerCamelCase					)
      model.to(_lowerCamelCase					)
      model.train()
      lowerCamelCase_         =						model(**_lowerCamelCase					)

      if isinstance(_lowerCamelCase       ,						_lowerCamelCase					):
        lowerCamelCase_         =						output[0]

      lowerCamelCase_         =						torch.device(_lowerCamelCase					)
      lowerCamelCase_         =						randn_tensor(output.shape       ,						device=_lowerCamelCase					)
      lowerCamelCase_         =						torch.nn.functional.mse_loss(_lowerCamelCase       ,						_lowerCamelCase					)
      loss.backward()












"""simple docstring"""



_UpperCamelCase		:  List[str]						=		{
    'meter': 'm',
    'kilometer': 'km',
    'megametre': 'Mm',
    'gigametre': 'Gm',
    'terametre': 'Tm',
    'petametre': 'Pm',
    'exametre': 'Em',
    'zettametre': 'Zm',
    'yottametre': 'Ym',
}
# Exponent of the factor(meter)
_UpperCamelCase		:  str						=		{
    'm': 0,
    'km': 3,
    'Mm': 6,
    'Gm': 9,
    'Tm': 1_2,
    'Pm': 1_5,
    'Em': 1_8,
    'Zm': 2_1,
    'Ym': 2_4,
}
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  float		,					__snake_case			:  str		,					__snake_case			:  str    ):





  '''simple docstring'''





  lowercase							    =       from_type.lower().strip('s'    )
  lowercase							    =       to_type.lower().strip('s'    )

  lowercase							    =       UNIT_SYMBOL.get(__snake_case		,					__snake_case    )
  lowercase							    =       UNIT_SYMBOL.get(__snake_case		,					__snake_case    )

  if from_sanitized not in METRIC_CONVERSION:
    lowercase							    =       (
        f'Invalid \'from_type\' value: {from_type!r}.\n'
        f'Conversion abbreviations are: {", ".join(__snake_case    )}'
    )
    raise ValueError(__snake_case    )
  if to_sanitized not in METRIC_CONVERSION:
    lowercase							    =       (
        f'Invalid \'to_type\' value: {to_type!r}.\n'
        f'Conversion abbreviations are: {", ".join(__snake_case    )}'
    )
    raise ValueError(__snake_case    )
  lowercase							    =       METRIC_CONVERSION[from_sanitized]
  lowercase							    =       METRIC_CONVERSION[to_sanitized]
  lowercase							    =       1

  if from_exponent > to_exponent:
    lowercase							    =       from_exponent - to_exponent
  else:
    lowercase							    =       -(to_exponent - from_exponent)

  return value * pow(10		,					__snake_case    )


if __name__ == "__main__":
    from doctest import testmod

    testmod()


