




import warnings
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


__A						:							str							=  logging.get_logger(__name__)

__A						:							Tuple							=  {
    """nvidia/segformer-b0-finetuned-ade-512-512""": (
        """https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json"""
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}




class 			UpperCAmelCase_      (   A       ):




							'''simple docstring'''



							a__						  =     '''segformer'''





							def __init__(					self       :	Optional[Any]       ,     a       :	Optional[int]=3       ,     a       :	int=4       ,     a       :	Tuple=[2, 2, 2, 2]       ,     a       :	str=[8, 4, 2, 1]       ,     a       :	Union[str, Any]=[32, 64, 160, 256]       ,     a       :	Dict=[7, 3, 3, 3]       ,     a       :	Optional[Any]=[4, 2, 2, 2]       ,     a       :	List[str]=[1, 2, 5, 8]       ,     a       :	int=[4, 4, 4, 4]       ,     a       :	Any="gelu"       ,     a       :	Optional[Any]=0.0       ,     a       :	Any=0.0       ,     a       :	Any=0.1       ,     a       :	Union[str, Any]=0.02       ,     a       :	int=0.1       ,     a       :	Tuple=1E-6       ,     a       :	Optional[int]=256       ,     a       :	Dict=255       ,     **a       :	Union[str, Any]       ,     )			->					Optional[int]:
										super().__init__(**a			)

										if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
													warnings.warn(
													    """Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be"""
													    """ removed, as the behaviour will default to that of reshape_last_stage = True."""       ,     a       ,     )

										SCREAMING_SNAKE_CASE           =					num_channels
										SCREAMING_SNAKE_CASE           =					num_encoder_blocks
										SCREAMING_SNAKE_CASE           =					depths
										SCREAMING_SNAKE_CASE           =					sr_ratios
										SCREAMING_SNAKE_CASE           =					hidden_sizes
										SCREAMING_SNAKE_CASE           =					patch_sizes
										SCREAMING_SNAKE_CASE           =					strides
										SCREAMING_SNAKE_CASE           =					mlp_ratios
										SCREAMING_SNAKE_CASE           =					num_attention_heads
										SCREAMING_SNAKE_CASE           =					hidden_act
										SCREAMING_SNAKE_CASE           =					hidden_dropout_prob
										SCREAMING_SNAKE_CASE           =					attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE           =					classifier_dropout_prob
										SCREAMING_SNAKE_CASE           =					initializer_range
										SCREAMING_SNAKE_CASE           =					drop_path_rate
										SCREAMING_SNAKE_CASE           =					layer_norm_eps
										SCREAMING_SNAKE_CASE           =					decoder_hidden_size
										SCREAMING_SNAKE_CASE           =					kwargs.get("""reshape_last_stage"""       ,     a			)
										SCREAMING_SNAKE_CASE           =					semantic_loss_ignore_index





class 			UpperCAmelCase_      (   A       ):




							'''simple docstring'''



							a__						  =     version.parse('''1.11'''       )





							@property
							def    _UpperCAmelCase     (					self       :	Dict			)			->					Mapping[str, Mapping[int, str]]:
										return OrderedDict(
										    [
										        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
										    ]			)





							@property
							def    _UpperCAmelCase     (					self       :	str			)			->					float:
										return 1E-4







							@property
							def    _UpperCAmelCase     (					self       :	Union[str, Any]			)			->					int:
										return 12












import os
import sys
import unittest


__A						:							Any							=  os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
__A						:							List[Any]							=  os.path.join(git_repo_path, """src""", """diffusers""")




class 			UpperCAmelCase_      (   unittest.TestCase       ):




							'''simple docstring'''



							def    _UpperCAmelCase     (					self       :	Any			)			->					Optional[Any]:
										SCREAMING_SNAKE_CASE           =					find_backend("""    if not is_torch_available():"""			)
										self.assertEqual(a       ,     """torch"""			)

										# backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
										# self.assertEqual(backend_with_underscore, "tensorflow_text")

										SCREAMING_SNAKE_CASE           =					find_backend("""    if not (is_torch_available() and is_transformers_available()):"""			)
										self.assertEqual(a       ,     """torch_and_transformers"""			)

										# double_backend_with_underscore = find_backend(
										#    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
										# )
										# self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

										SCREAMING_SNAKE_CASE           =					find_backend(
										    """    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):"""			)
										self.assertEqual(a       ,     """torch_and_transformers_and_onnx"""			)





							def    _UpperCAmelCase     (					self       :	List[str]			)			->					int:
										SCREAMING_SNAKE_CASE           =					read_init()
										# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
										self.assertIn("""torch"""       ,     a			)
										self.assertIn("""torch_and_transformers"""       ,     a			)
										self.assertIn("""flax_and_transformers"""       ,     a			)
										self.assertIn("""torch_and_transformers_and_onnx"""       ,     a			)

										# Likewise, we can't assert on the exact content of a key
										self.assertIn("""UNet2DModel"""       ,     objects["""torch"""]			)
										self.assertIn("""FlaxUNet2DConditionModel"""       ,     objects["""flax"""]			)
										self.assertIn("""StableDiffusionPipeline"""       ,     objects["""torch_and_transformers"""]			)
										self.assertIn("""FlaxStableDiffusionPipeline"""       ,     objects["""flax_and_transformers"""]			)
										self.assertIn("""LMSDiscreteScheduler"""       ,     objects["""torch_and_scipy"""]			)
										self.assertIn("""OnnxStableDiffusionPipeline"""       ,     objects["""torch_and_transformers_and_onnx"""]			)





							def    _UpperCAmelCase     (					self       :	Any			)			->					int:
										SCREAMING_SNAKE_CASE           =					create_dummy_object("""CONSTANT"""       ,     """'torch'"""			)
										self.assertEqual(a       ,     """\nCONSTANT = None\n"""			)

										SCREAMING_SNAKE_CASE           =					create_dummy_object("""function"""       ,     """'torch'"""			)
										self.assertEqual(
										    a       ,     """\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""			)

										SCREAMING_SNAKE_CASE           =					"""
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, 'torch')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, 'torch')
"""
										SCREAMING_SNAKE_CASE           =					create_dummy_object("""FakeClass"""       ,     """'torch'"""			)
										self.assertEqual(a       ,     a			)







							def    _UpperCAmelCase     (					self       :	Union[str, Any]			)			->					Union[str, Any]:
										SCREAMING_SNAKE_CASE           =					"""# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, [\"torch\"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, [\"torch\"])
"""
										SCREAMING_SNAKE_CASE           =					create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}			)
										self.assertEqual(dummy_files["""torch"""]       ,     a			)






