





"""simple docstring"""





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


_UpperCamelCase					      =   logging.get_logger(__name__)

_UpperCamelCase					      =   {
    '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 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							Optional[int]									=		"""segformer"""




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

											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.'''    ,     __lowercase    ,     )

											__lowerCamelCase   :   Union[str, Any]       =num_channels
											__lowerCamelCase   :   Tuple       =num_encoder_blocks
											__lowerCamelCase   :   Dict       =depths
											__lowerCamelCase   :   List[str]       =sr_ratios
											__lowerCamelCase   :   List[Any]       =hidden_sizes
											__lowerCamelCase   :   int       =patch_sizes
											__lowerCamelCase   :   List[Any]       =strides
											__lowerCamelCase   :   Union[str, Any]       =mlp_ratios
											__lowerCamelCase   :   int       =num_attention_heads
											__lowerCamelCase   :   Any       =hidden_act
											__lowerCamelCase   :   List[str]       =hidden_dropout_prob
											__lowerCamelCase   :   Optional[int]       =attention_probs_dropout_prob
											__lowerCamelCase   :   Optional[Any]       =classifier_dropout_prob
											__lowerCamelCase   :   List[str]       =initializer_range
											__lowerCamelCase   :   str       =drop_path_rate
											__lowerCamelCase   :   Optional[int]       =layer_norm_eps
											__lowerCamelCase   :   Dict       =decoder_hidden_size
											__lowerCamelCase   :   int       =kwargs.get('''reshape_last_stage'''    ,     __lowercase      )
											__lowerCamelCase   :   Optional[int]       =semantic_loss_ignore_index

class 		SCREAMING_SNAKE_CASE_				(     snake_case__ ):
				"""simple docstring"""
				__snake_case :							List[str]									=		version.parse("""1.11""" )




				@property
				def        __lowercase	(  self	:Dict      ):
											return OrderedDict(
											    [
											        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
											    ]      )




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




				@property
				def        __lowercase	(  self	:List[Any]      ):
											return 12











"""simple docstring"""





import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment
@require_huggingface_suite
class 		SCREAMING_SNAKE_CASE_				(     unittest.TestCase ):
				"""simple docstring"""




				def        __lowercase	(  self	:Dict      ):
											__lowerCamelCase   :   Union[str, Any]       =inspect.getfile(accelerate.test_utils      )
											__lowerCamelCase   :   Union[str, Any]       =os.path.sep.join(
											    mod_file.split(os.path.sep      )[:-1] + ['''scripts''', '''external_deps''', '''test_metrics.py''']      )

											from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

											__lowerCamelCase   :   List[str]       =test_metrics




				@require_cpu
				def        __lowercase	(  self	:Optional[Any]      ):
											debug_launcher(self.test_metrics.main    ,     num_processes=1      )




				@require_cpu
				def        __lowercase	(  self	:int      ):
											debug_launcher(self.test_metrics.main      )




				@require_single_gpu
				def        __lowercase	(  self	:int      ):
											self.test_metrics.main()




				@require_multi_gpu
				def        __lowercase	(  self	:Dict      ):
											print(f'Found {torch.cuda.device_count()} devices.'      )
											__lowerCamelCase   :   Union[str, Any]       =['''torchrun''', f'--nproc_per_node={torch.cuda.device_count()}', self.test_file_path]
											with patch_environment(omp_num_threads=1      ):
																		execute_subprocess_async(__lowercase    ,     env=os.environ.copy()      )




