



"""simple docstring"""





import time
from contextlib import contextmanager
from pathlib import Path

import pytest
import requests
from huggingface_hub.hf_api import HfApi, HfFolder


__lowerCAmelCase							:       List[str]          =       '''__DUMMY_TRANSFORMERS_USER__'''
__lowerCAmelCase							:       Dict          =       '''Dummy User'''
__lowerCAmelCase							:       Dict          =       '''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'''

__lowerCAmelCase							:       Dict          =       '''https://hub-ci.huggingface.co'''
__lowerCAmelCase							:       List[str]          =       CI_HUB_ENDPOINT + '''/datasets/{repo_id}/resolve/{revision}/{path}'''
__lowerCAmelCase							:       int          =       CI_HUB_ENDPOINT + '''/{repo_id}/resolve/{revision}/{filename}'''
__lowerCAmelCase							:       Optional[Any]          =       Path('''~/.huggingface/hub_ci_token''').expanduser()
@pytest.fixture
def 						__lowerCAmelCase    (		__UpperCamelCase   :      Optional[int]     ):


						'''simple docstring'''






						monkeypatch.setattr(
						    """huggingface_hub.file_download.HUGGINGFACE_CO_URL_TEMPLATE"""       ,			__UpperCamelCase     )
@pytest.fixture
def 						__lowerCAmelCase    (		__UpperCamelCase   :      Tuple     ):


						'''simple docstring'''






						monkeypatch.setattr("""datasets.config.HF_ENDPOINT"""       ,			__UpperCamelCase     )
						monkeypatch.setattr("""datasets.config.HUB_DATASETS_URL"""       ,			__UpperCamelCase     )
@pytest.fixture
def 						__lowerCAmelCase    (		__UpperCamelCase   :      Tuple     ):


						'''simple docstring'''






						monkeypatch.setattr("""huggingface_hub.hf_api.HfFolder.path_token"""       ,			__UpperCamelCase     )
@pytest.fixture
def 						__lowerCAmelCase    (		__UpperCamelCase   :      List[str]       ,			__UpperCamelCase   :      Union[str, Any]     ):


						'''simple docstring'''






						HfFolder.save_token(__UpperCamelCase     )
						yield
						HfFolder.delete_token()
@pytest.fixture(scope="""session"""     )
def 						__lowerCAmelCase    (		):


						'''simple docstring'''






						return HfApi(endpoint=__UpperCamelCase     )
@pytest.fixture(scope="""session"""     )
def 						__lowerCAmelCase    (		__UpperCamelCase   :      HfApi     ):


						'''simple docstring'''






						snake_case_ :			List[Any]            =      HfFolder.get_token()
						HfFolder.save_token(__UpperCamelCase     )
						yield CI_HUB_USER_TOKEN
						if previous_token is not None:
												HfFolder.save_token(__UpperCamelCase     )
@pytest.fixture
def 						__lowerCAmelCase    (		__UpperCamelCase   :      str     ):


						'''simple docstring'''






						def _cleanup_repo(__UpperCamelCase   :      int     ):
												hf_api.delete_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""     )

						return _cleanup_repo
@pytest.fixture
def 						__lowerCAmelCase    (		__UpperCamelCase   :      str     ):


						'''simple docstring'''






						@contextmanager
						def _temporary_repo(__UpperCamelCase   :      int     ):
												try:
																		yield repo_id
												finally:
																		cleanup_repo(__UpperCamelCase     )

						return _temporary_repo
@pytest.fixture(scope="""session"""     )
def 						__lowerCAmelCase    (		__UpperCamelCase   :      HfApi       ,			__UpperCamelCase   :      int       ,			__UpperCamelCase   :      Optional[Any]     ):


						'''simple docstring'''






						snake_case_ :			List[str]            =      F'repo_txt_data-{int(time.time() * 1_0E3     )}'
						snake_case_ :			Optional[int]            =      F'{CI_HUB_USER}/{repo_name}'
						hf_api.create_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""       ,			private=__UpperCamelCase     )
						hf_api.upload_file(
						    token=__UpperCamelCase       ,			path_or_fileobj=str(__UpperCamelCase     )       ,			path_in_repo="""data/text_data.txt"""       ,			repo_id=__UpperCamelCase       ,			repo_type="""dataset"""       ,			)
						yield repo_id
						try:
												hf_api.delete_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""     )
						except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
												pass
@pytest.fixture()
def 						__lowerCAmelCase    (		__UpperCamelCase   :      List[Any]       ,			__UpperCamelCase   :      Optional[Any]       ,			__UpperCamelCase   :      Optional[int]     ):


						'''simple docstring'''






						return hf_private_dataset_repo_txt_data_
@pytest.fixture(scope="""session"""     )
def 						__lowerCAmelCase    (		__UpperCamelCase   :      HfApi       ,			__UpperCamelCase   :      str       ,			__UpperCamelCase   :      str     ):


						'''simple docstring'''






						snake_case_ :			Optional[Any]            =      F'repo_zipped_txt_data-{int(time.time() * 1_0E3     )}'
						snake_case_ :			Tuple            =      F'{CI_HUB_USER}/{repo_name}'
						hf_api.create_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""       ,			private=__UpperCamelCase     )
						hf_api.upload_file(
						    token=__UpperCamelCase       ,			path_or_fileobj=str(__UpperCamelCase     )       ,			path_in_repo="""data.zip"""       ,			repo_id=__UpperCamelCase       ,			repo_type="""dataset"""       ,			)
						yield repo_id
						try:
												hf_api.delete_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""     )
						except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
												pass
@pytest.fixture()
def 						__lowerCAmelCase    (		__UpperCamelCase   :      Dict       ,			__UpperCamelCase   :      Dict       ,			__UpperCamelCase   :      Optional[int]     ):


						'''simple docstring'''






						return hf_private_dataset_repo_zipped_txt_data_
@pytest.fixture(scope="""session"""     )
def 						__lowerCAmelCase    (		__UpperCamelCase   :      HfApi       ,			__UpperCamelCase   :      int       ,			__UpperCamelCase   :      Tuple     ):


						'''simple docstring'''






						snake_case_ :			Any            =      F'repo_zipped_img_data-{int(time.time() * 1_0E3     )}'
						snake_case_ :			str            =      F'{CI_HUB_USER}/{repo_name}'
						hf_api.create_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""       ,			private=__UpperCamelCase     )
						hf_api.upload_file(
						    token=__UpperCamelCase       ,			path_or_fileobj=str(__UpperCamelCase     )       ,			path_in_repo="""data.zip"""       ,			repo_id=__UpperCamelCase       ,			repo_type="""dataset"""       ,			)
						yield repo_id
						try:
												hf_api.delete_repo(__UpperCamelCase       ,			token=__UpperCamelCase       ,			repo_type="""dataset"""     )
						except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
												pass






@pytest.fixture()
def 						__lowerCAmelCase    (		__UpperCamelCase   :      Optional[Any]       ,			__UpperCamelCase   :      int       ,			__UpperCamelCase   :      Any     ):


						'''simple docstring'''






						return hf_private_dataset_repo_zipped_img_data_






'''simple docstring'''





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


A__    :   Union[str, Any]           =					logging.get_logger(__name__)



class  snake_case__						(    SCREAMING_SNAKE_CASE_				):
 A__				= '''upernet'''
 def __init__(   self						:							Optional[int]      ,     __a						:							Dict=None      ,     __a						:							List[str]=512      ,     __a						:							int=0.0_2      ,     __a						:							Optional[Any]=[1, 2, 3, 6]      ,     __a						:							Union[str, Any]=True      ,     __a						:							Any=0.4      ,     __a						:							int=384      ,     __a						:							int=256      ,     __a						:							str=1      ,     __a						:							List[Any]=False      ,     __a						:							Dict=255      ,     **__a						:							Dict      ,     )      ->   Optional[int]:







       '''simple docstring'''
       super().__init__(**__a  )

       if backbone_config is None:
             logger.info('`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.'  )
             __snake_case :   Optional[int]													=    CONFIG_MAPPING['resnet'](out_features=['stage1', 'stage2', 'stage3', 'stage4']  )
       elif isinstance(__a      ,     __a  ):
             __snake_case :   List[Any]													=    backbone_config.get('model_type'  )
             __snake_case :   List[str]													=    CONFIG_MAPPING[backbone_model_type]
             __snake_case :   int													=    config_class.from_dict(__a  )

       __snake_case :   Any													=    backbone_config
       __snake_case :   Tuple													=    hidden_size
       __snake_case :   str													=    initializer_range
       __snake_case :   Dict													=    pool_scales
       __snake_case :   Optional[Any]													=    use_auxiliary_head
       __snake_case :   Optional[Any]													=    auxiliary_loss_weight
       __snake_case :   Optional[int]													=    auxiliary_in_channels
       __snake_case :   Dict													=    auxiliary_channels
       __snake_case :   Any													=    auxiliary_num_convs
       __snake_case :   Optional[Any]													=    auxiliary_concat_input
       __snake_case :   List[str]													=    loss_ignore_index





 def A_   (   self						:							List[Any]  )      ->   Union[str, Any]:







       '''simple docstring'''
       __snake_case :   Union[str, Any]													=    copy.deepcopy(self.__dict__  )
       __snake_case :   str													=    self.backbone_config.to_dict()
       __snake_case :   Optional[int]													=    self.__class__.model_type
       return output



