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







				@property
				def 						UpperCAmelCase_    (       self     )->		str:







											'''simple docstring'''






											return self.get_dummy_input()







				@property
				def 						UpperCAmelCase_    (       self     )->		Tuple:







											'''simple docstring'''






											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						,				A_=True						,				A_=False						,				A_=False						,				A_=False						,				)->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     4
											UpperCamelCase   			=     32
											UpperCamelCase   			=     (32, 32)

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

											if include_temb:
																		UpperCamelCase   			=     128
																		UpperCamelCase   			=     randn_tensor((batch_size, temb_channels)						,				generator=A_						,				device=A_     )

											if include_res_hidden_states_tuple:
																		UpperCamelCase   			=     torch.manual_seed(1     )
																		UpperCamelCase   			=     (randn_tensor(A_						,				generator=A_						,				device=A_     ),)

											if include_encoder_hidden_states:
																		UpperCamelCase   			=     floats_tensor((batch_size, 32, 32)     ).to(A_     )

											if include_skip_sample:
																		UpperCamelCase   			=     randn_tensor(((batch_size, 3) + sizes)						,				generator=A_						,				device=A_     )

											return dummy_input







				def 						UpperCAmelCase_    (       self     )->		Any:







											'''simple docstring'''






											UpperCamelCase   			=     {
											    'in_channels': 32,
											    'out_channels': 32,
											    'temb_channels': 128,
											}
											if self.block_type == "up":
																		UpperCamelCase   			=     32

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

											UpperCamelCase   			=     self.dummy_input
											return init_dict, inputs_dict







				def 						UpperCAmelCase_    (       self						,				A_     )->		Tuple:







											'''simple docstring'''






											UpperCamelCase			,	UpperCamelCase   			=     self.prepare_init_args_and_inputs_for_common()
											UpperCamelCase   			=     self.block_class(**A_     )
											unet_block.to(A_     )
											unet_block.eval()

											with torch.no_grad():
																		UpperCamelCase   			=     unet_block(**A_     )

											if isinstance(A_						,				A_     ):
																		UpperCamelCase   			=     output[0]

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

											UpperCamelCase   			=     output[0, -1, -3:, -3:]
											UpperCamelCase   			=     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 						UpperCAmelCase_    (       self     )->		Dict:







											'''simple docstring'''






											UpperCamelCase			,	UpperCamelCase   			=     self.prepare_init_args_and_inputs_for_common()
											UpperCamelCase   			=     self.block_class(**A_     )
											model.to(A_     )
											model.train()
											UpperCamelCase   			=     model(**A_     )

											if isinstance(A_						,				A_     ):
																		UpperCamelCase   			=     output[0]

											UpperCamelCase   			=     torch.device(A_     )
											UpperCamelCase   			=     randn_tensor(output.shape						,				device=A_     )
											UpperCamelCase   			=     torch.nn.functional.mse_loss(A_						,				A_     )
											loss.backward()





'''simple docstring'''




# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__UpperCAmelCase					={
    "configuration_efficientnet": [
        "EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "EfficientNetConfig",
        "EfficientNetOnnxConfig",
    ]
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase					=["EfficientNetImageProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase					=[
      "EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST",
      "EfficientNetForImageClassification",
      "EfficientNetModel",
      "EfficientNetPreTrainedModel",
  ]

if TYPE_CHECKING:
  from .configuration_efficientnet import (
      EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP,
      EfficientNetConfig,
      EfficientNetOnnxConfig,
  )

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_efficientnet import EfficientNetImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_efficientnet import (
        EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST,
        EfficientNetForImageClassification,
        EfficientNetModel,
        EfficientNetPreTrainedModel,
    )

else:
  import sys

  __UpperCAmelCase					=_LazyModule(__name__, globals()["__file__"], _import_structure)
