

"""simple docstring"""


import json
import logging
import os
import sys
from time import time
from unittest.mock import patch

from transformers.testing_utils import TestCasePlus, require_torch_tpu


logging.basicConfig(level=logging.DEBUG)

a					:Union[str, Any]    = logging.getLogger()




def  _lowercase					(    __lowerCAmelCase							)       ->				Optional[int]:
      SCREAMING_SNAKE_CASE__   :      Dict      		=	{}
      SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	os.path.join(_lowercase  ,					"""all_results.json"""							)
      if os.path.exists(_lowercase							):
            with open(_lowercase  ,					"""r"""							) as f:
                  SCREAMING_SNAKE_CASE__   :      int      		=	json.load(_lowercase							)
      else:
            raise ValueError(F'''can\'t find {path}'''							)
      return results


a					:Optional[int]    = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)



@require_torch_tpu
class      __a							(UpperCamelCase_):






     '''simple docstring'''

     def 					_a			(						self  )  ->      Tuple:


           """simple docstring"""


           import xla_spawn

           SCREAMING_SNAKE_CASE__   :      List[Any]      		=	self.get_auto_remove_tmp_dir()
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	f'''
            ./examples/pytorch/text-classification/run_glue.py
            --num_cores=8
            ./examples/pytorch/text-classification/run_glue.py
            --model_name_or_path distilbert-base-uncased
            --output_dir {tmp_dir}
            --overwrite_output_dir
            --train_file ./tests/fixtures/tests_samples/MRPC/train.csv
            --validation_file ./tests/fixtures/tests_samples/MRPC/dev.csv
            --do_train
            --do_eval
            --debug tpu_metrics_debug
            --per_device_train_batch_size=2
            --per_device_eval_batch_size=1
            --learning_rate=1e-4
            --max_steps=10
            --warmup_steps=2
            --seed=42
            --max_seq_length=128
            '''.split()

           with patch.object(UpperCamelCase_	,    """argv"""	,    UpperCamelCase_  ):
                 SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	time()
                 xla_spawn.main()
                 SCREAMING_SNAKE_CASE__   :      Tuple      		=	time()

                 SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	get_results(UpperCamelCase_  )
                 self.assertGreaterEqual(result["""eval_accuracy"""]	,    0.75  )

                 # Assert that the script takes less than 500 seconds to make sure it doesn't hang.
                 self.assertLess(end - start	,    500  )





     def 					_a			(						self  )  ->      List[str]:


           """simple docstring"""


           import xla_spawn

           SCREAMING_SNAKE_CASE__   :      List[str]      		=	'\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            '.split()
           with patch.object(UpperCamelCase_	,    """argv"""	,    UpperCamelCase_  ):
                 xla_spawn.main()







"""simple docstring"""


from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


a					:List[Any]    = logging.get_logger(__name__)

a					:Optional[int]    = {
    "microsoft/focalnet-tiny": "https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json",
}

class      __a							(UpperCamelCase_   ,	UpperCamelCase_):






     '''simple docstring'''
     _SCREAMING_SNAKE_CASE						:Any       = """focalnet"""

     def __init__(						self	,    _a=224	,    _a=4	,    _a=3	,    _a=96	,    _a=False	,    _a=[192, 384, 768, 768]	,    _a=[2, 2, 6, 2]	,    _a=[2, 2, 2, 2]	,    _a=[3, 3, 3, 3]	,    _a="gelu"	,    _a=4.0	,    _a=0.0	,    _a=0.1	,    _a=False	,    _a=1E-4	,    _a=False	,    _a=False	,    _a=False	,    _a=0.02	,    _a=1E-5	,    _a=32	,    _a=None	,    _a=None	,    **_a	,    )  ->      Optional[Any]:


           """simple docstring"""


           super().__init__(**_a  )

           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	image_size
           SCREAMING_SNAKE_CASE__   :      str      		=	patch_size
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	num_channels
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	embed_dim
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	use_conv_embed
           SCREAMING_SNAKE_CASE__   :      List[str]      		=	hidden_sizes
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	depths
           SCREAMING_SNAKE_CASE__   :      Any      		=	focal_levels
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	focal_windows
           SCREAMING_SNAKE_CASE__   :      Any      		=	hidden_act
           SCREAMING_SNAKE_CASE__   :      Tuple      		=	mlp_ratio
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	hidden_dropout_prob
           SCREAMING_SNAKE_CASE__   :      Optional[Any]      		=	drop_path_rate
           SCREAMING_SNAKE_CASE__   :      str      		=	use_layerscale
           SCREAMING_SNAKE_CASE__   :      int      		=	layerscale_value
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	use_post_layernorm
           SCREAMING_SNAKE_CASE__   :      Any      		=	use_post_layernorm_in_modulation
           SCREAMING_SNAKE_CASE__   :      Union[str, Any]      		=	normalize_modulator
           SCREAMING_SNAKE_CASE__   :      str      		=	initializer_range
           SCREAMING_SNAKE_CASE__   :      Any      		=	layer_norm_eps
           SCREAMING_SNAKE_CASE__   :      Any      		=	encoder_stride
           SCREAMING_SNAKE_CASE__   :      Optional[int]      		=	["""stem"""] + [f'''stage{idx}''' for idx in range(1	,    len(self.depths  ) + 1  )]
           SCREAMING_SNAKE_CASE__		,		SCREAMING_SNAKE_CASE__   :      Dict      		=	get_aligned_output_features_output_indices(
               out_features=_a	,    out_indices=_a	,    stage_names=self.stage_names  )




