





'''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       __SCREAMING_SNAKE_CASE	:



     '''simple docstring'''






     @property
     def 	UpperCamelCase(					self	):
       return self.get_dummy_input()

     @property
     def 	UpperCamelCase(					self	):







       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						,   lowerCamelCase=True						,   lowerCamelCase=False						,   lowerCamelCase=False						,   lowerCamelCase=False						,   ):
       _snake_case     		=				4
       _snake_case     		=				32
       _snake_case     		=				(32, 32)

       _snake_case     		=				torch.manual_seed(0	)
       _snake_case     		=				torch.device(lowerCAmelCase_	)
       _snake_case     		=				(batch_size, num_channels) + sizes
       _snake_case     		=				randn_tensor(lowerCAmelCase_						,   generator=lowerCAmelCase_						,   device=lowerCAmelCase_	)
       _snake_case     		=				{"hidden_states": hidden_states}

       if include_temb:
         _snake_case     		=				128
         _snake_case     		=				randn_tensor((batch_size, temb_channels)						,   generator=lowerCAmelCase_						,   device=lowerCAmelCase_	)

       if include_res_hidden_states_tuple:
         _snake_case     		=				torch.manual_seed(1	)
         _snake_case     		=				(randn_tensor(lowerCAmelCase_						,   generator=lowerCAmelCase_						,   device=lowerCAmelCase_	),)

       if include_encoder_hidden_states:
         _snake_case     		=				floats_tensor((batch_size, 32, 32)	).to(lowerCAmelCase_	)

       if include_skip_sample:
         _snake_case     		=				randn_tensor(((batch_size, 3) + sizes)						,   generator=lowerCAmelCase_						,   device=lowerCAmelCase_	)

       return dummy_input

     def 	UpperCamelCase(					self	):
       _snake_case     		=				{
           "in_channels": 32,
           "out_channels": 32,
           "temb_channels": 128,
       }
       if self.block_type == "up":
         _snake_case     		=				32

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

       _snake_case     		=				self.dummy_input
       return init_dict, inputs_dict

     def 	UpperCamelCase(					self						,   lowerCamelCase	):
       _snake_case		,		_snake_case     		=				self.prepare_init_args_and_inputs_for_common()
       _snake_case     		=				self.block_class(**lowerCAmelCase_	)
       unet_block.to(lowerCAmelCase_	)
       unet_block.eval()

       with torch.no_grad():
         _snake_case     		=				unet_block(**lowerCAmelCase_	)

       if isinstance(lowerCAmelCase_						,   lowerCAmelCase_	):
         _snake_case     		=				output[0]

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

       _snake_case     		=				output[0, -1, -3:, -3:]
       _snake_case     		=				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	):
       _snake_case		,		_snake_case     		=				self.prepare_init_args_and_inputs_for_common()
       _snake_case     		=				self.block_class(**lowerCAmelCase_	)
       model.to(lowerCAmelCase_	)
       model.train()
       _snake_case     		=				model(**lowerCAmelCase_	)

       if isinstance(lowerCAmelCase_						,   lowerCAmelCase_	):
         _snake_case     		=				output[0]

       _snake_case     		=				torch.device(lowerCAmelCase_	)
       _snake_case     		=				randn_tensor(output.shape						,   device=lowerCAmelCase_	)
       _snake_case     		=				torch.nn.functional.mse_loss(lowerCAmelCase_						,   lowerCAmelCase_	)
       loss.backward()









'''simple docstring'''



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__magic_name__   :						Dict    =			logging.get_logger(__name__)

__magic_name__   :						Dict    =			{
    """google/mobilenet_v1_1.0_224""": """https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json""",
    """google/mobilenet_v1_0.75_192""": """https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}


class       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						List[Any]      =   '''mobilenet_v1'''

     def __init__(					self						,   lowerCamelCase=3						,   lowerCamelCase=224						,   lowerCamelCase=1.0						,   lowerCamelCase=8						,   lowerCamelCase="relu6"						,   lowerCamelCase=True						,   lowerCamelCase=0.999						,   lowerCamelCase=0.02						,   lowerCamelCase=0.001						,   **lowerCamelCase						,   ):
       super().__init__(**lowerCamelCase	)

       if depth_multiplier <= 0:
         raise ValueError("depth_multiplier must be greater than zero."	)

       _snake_case     		=				num_channels
       _snake_case     		=				image_size
       _snake_case     		=				depth_multiplier
       _snake_case     		=				min_depth
       _snake_case     		=				hidden_act
       _snake_case     		=				tf_padding
       _snake_case     		=				classifier_dropout_prob
       _snake_case     		=				initializer_range
       _snake_case     		=				layer_norm_eps







class       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						int      =   version.parse('''1.11'''			)

     @property
     def 	UpperCamelCase(					self	):
       return OrderedDict([("pixel_values", {0: "batch"})]	)

     @property
     def 	UpperCamelCase(					self	):
       if self.task == "image-classification":
         return OrderedDict([("logits", {0: "batch"})]	)
       else:
         return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]	)






     @property
     def 	UpperCamelCase(					self	):
       return 1e-4


