






'''simple docstring'''




import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  ''''''
	_lowerCamelCase              =  (
	    None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
	)
	_lowerCamelCase              =  None  # compression type in fsspec. ex: "gzip"
	_lowerCamelCase              =  None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz

	def __init__(      self   :						Optional[Any]  ,					UpperCAmelCase_   :						str = ""  ,					UpperCAmelCase_   :						Optional[str] = None  ,					UpperCAmelCase_   :						Optional[dict] = None  ,					**UpperCAmelCase_   :						Dict):
			super().__init__(self  ,					**UpperCAmelCase_)
			# always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
			UpperCamelCase__				:					int					=					fsspec.open(
			    UpperCAmelCase_  ,					mode='rb'  ,					protocol=UpperCAmelCase_  ,					compression=self.compression  ,					client_kwargs={
			        'requote_redirect_url': False,  # see https://github.com/huggingface/datasets/pull/5459
			        'trust_env': True,  # Enable reading proxy env variables.
			        **(target_options or {}).pop('client_kwargs'  ,					{}),  # To avoid issues if it was already passed.
			    }  ,					**(target_options or {})  ,					)
			UpperCamelCase__				:					Tuple					=					os.path.basename(self.file.path.split('::')[0])
			UpperCamelCase__				:					Union[str, Any]					=					(
			    self.compressed_name[: self.compressed_name.rindex('.')]
			    if '.' in self.compressed_name
			    else self.compressed_name
			)
			UpperCamelCase__				:					str					=					None

	@classmethod
	def      __UpperCamelCase							(      cls   :						Optional[int]  ,					UpperCAmelCase_   :						Dict):
			# compressed file paths are always relative to the archive root
			return super()._strip_protocol(UpperCAmelCase_).lstrip('/')

	def      __UpperCamelCase							(      self   :						Any):
			if self.dir_cache is None:
					UpperCamelCase__				:					Tuple					=					{**self.file.fs.info(self.file.path), 'name': self.uncompressed_name}
					UpperCamelCase__				:					Dict					=					{f['name']: f}

	def      __UpperCamelCase							(      self   :						str  ,					UpperCAmelCase_   :						str):
			return self.file.open().read()





	def      __UpperCamelCase							(      self   :						Dict  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						str = "rb"  ,					UpperCAmelCase_   :						Any=None  ,					UpperCAmelCase_   :						Optional[int]=True  ,					UpperCAmelCase_   :						Any=None  ,					**UpperCAmelCase_   :						str  ,					):
			UpperCamelCase__				:					str					=					self._strip_protocol(UpperCAmelCase_)
			if mode != "rb":
					raise ValueError(F'Tried to read with mode {mode} on file {self.file.path} opened with mode \'rb\'')
			return self.file.open()







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''bz2'''
	_lowerCamelCase              =  '''bz2'''
	_lowerCamelCase              =  '''.bz2'''







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''gzip'''
	_lowerCamelCase              =  '''gzip'''
	_lowerCamelCase              =  '''.gz'''







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''lz4'''
	_lowerCamelCase              =  '''lz4'''
	_lowerCamelCase              =  '''.lz4'''







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''xz'''
	_lowerCamelCase              =  '''xz'''
	_lowerCamelCase              =  '''.xz'''







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''zstd'''
	_lowerCamelCase              =  '''zstd'''
	_lowerCamelCase              =  '''.zst'''

	def __init__(      self   :						Optional[int]  ,					UpperCAmelCase_   :						str  ,					UpperCAmelCase_   :						str = "rb"  ,					UpperCAmelCase_   :						Optional[str] = None  ,					UpperCAmelCase_   :						Optional[dict] = None  ,					UpperCAmelCase_   :						int = DEFAULT_BLOCK_SIZE  ,					**UpperCAmelCase_   :						Dict  ,					):
			super().__init__(
			    fo=UpperCAmelCase_  ,					mode=UpperCAmelCase_  ,					target_protocol=UpperCAmelCase_  ,					target_options=UpperCAmelCase_  ,					block_size=UpperCAmelCase_  ,					**UpperCAmelCase_  ,					)
			# We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
			#
			# File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
			#     out.close = close
			# AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
			#
			# see https://github.com/intake/filesystem_spec/issues/725
			UpperCamelCase__				:					str					=					self.file.__enter__







			class       __lowercase					:

				def __init__(      self   :						Optional[int]  ,					UpperCAmelCase_   :						Dict):
						UpperCamelCase__				:					str					=					file_

				def __enter__(      self   :						str):
						self._file.__enter__()
						return self

				def __exit__(      self   :						Optional[int]  ,					*UpperCAmelCase_   :						Dict  ,					**UpperCAmelCase_   :						Any):
						self._file.__exit__(*UpperCAmelCase_  ,					**UpperCAmelCase_)

				def __iter__(      self   :						Tuple):
						return iter(self._file)

				def      __UpperCamelCase							(      self   :						Any):
						return next(self._file)





				def __getattr__(      self   :						str  ,					UpperCAmelCase_   :						Tuple):
						return getattr(self._file  ,					UpperCAmelCase_)

			def fixed_enter(*UpperCAmelCase_   :						List[str]  ,					**UpperCAmelCase_   :						Dict):
					return WrappedFile(_enter(*UpperCAmelCase_  ,					**UpperCAmelCase_))

			UpperCamelCase__				:					str					=					fixed_enter












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


lowerCAmelCase__          =						logging.get_logger(__name__)

lowerCAmelCase__          =						{
    '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       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  '''segformer'''

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

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

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







class       __lowercase					(__lowerCamelCase    ):
	_lowerCamelCase              =  version.parse('''1.11'''    )

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

	@property
	def      __UpperCamelCase							(      self   :						Optional[Any]):
			return 1e-4





	@property
	def      __UpperCamelCase							(      self   :						Any):
			return 12




