






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)

_UpperCamelCase			:	Dict								=logging.getLogger()



def  a__ (__lowercase							:Union[str, Any]   )		-> List[str]:
				_A	:				List[Any]   =      {}
				_A	:				Optional[Any]   =      os.path.join(__lowercase					,  '''all_results.json'''   )
				if os.path.exists(__lowercase   ):
								with open(__lowercase					,  '''r'''   ) as f:
												_A	:				Dict   =      json.load(__lowercase   )
				else:
								raise ValueError(f"""can't find {path}"""   )
				return results


_UpperCamelCase			:	List[str]								=logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)






@require_torch_tpu
class 						UpperCAmelCase__ (							__snake_case							):







		def  A__      (					self		):
						import xla_spawn

						_A	:				int   =      self.get_auto_remove_tmp_dir()
						_A	:				Optional[Any]   =      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(A__       ,'''argv'''       ,A__		):
										_A	:				Optional[int]   =      time()
										xla_spawn.main()
										_A	:				Dict   =      time()

										_A	:				List[str]   =      get_results(A__		)
										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		):
						import xla_spawn

						_A	:				int   =      '''
            ./tests/test_trainer_tpu.py
            --num_cores=8
            ./tests/test_trainer_tpu.py
            '''.split()
						with patch.object(A__       ,'''argv'''       ,A__		):
										xla_spawn.main()











from ...configuration_utils import PretrainedConfig
from ...utils import logging


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

_UpperCamelCase			:	Optional[Any]								={
    'google/pegasus-large': 'https://huggingface.co/google/pegasus-large/resolve/main/config.json',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}






class 						UpperCAmelCase__ (							__snake_case							):
		__snake_case      :       Optional[int]     =   "pegasus"
		__snake_case      :       List[str]     =   ["past_key_values"]
		__snake_case      :       Union[str, Any]     =   {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}







		def __init__(					self       ,A__=50265       ,A__=1024       ,A__=12       ,A__=4096       ,A__=16       ,A__=12       ,A__=4096       ,A__=16       ,A__=0.0       ,A__=0.0       ,A__=True       ,A__=True       ,A__="gelu"       ,A__=1024       ,A__=0.1       ,A__=0.0       ,A__=0.0       ,A__=0.02       ,A__=0       ,A__=False       ,A__=0       ,A__=1       ,A__=1       ,**A__       ,):
						_A	:				List[str]   =      vocab_size
						_A	:				List[Any]   =      max_position_embeddings
						_A	:				Union[str, Any]   =      d_model
						_A	:				Union[str, Any]   =      encoder_ffn_dim
						_A	:				Union[str, Any]   =      encoder_layers
						_A	:				int   =      encoder_attention_heads
						_A	:				List[Any]   =      decoder_ffn_dim
						_A	:				Optional[int]   =      decoder_layers
						_A	:				Tuple   =      decoder_attention_heads
						_A	:				List[str]   =      dropout
						_A	:				Tuple   =      attention_dropout
						_A	:				Union[str, Any]   =      activation_dropout
						_A	:				int   =      activation_function
						_A	:				Union[str, Any]   =      init_std
						_A	:				Any   =      encoder_layerdrop
						_A	:				int   =      decoder_layerdrop
						_A	:				Tuple   =      use_cache
						_A	:				Dict   =      encoder_layers
						_A	:				List[str]   =      scale_embedding  # scale factor will be sqrt(d_model) if True
						super().__init__(
						    pad_token_id=A__       ,eos_token_id=A__       ,is_encoder_decoder=A__       ,decoder_start_token_id=A__       ,forced_eos_token_id=A__       ,**A__       ,)







		@property
		def  A__      (					self		):
						return self.encoder_attention_heads







		@property
		def  A__      (					self		):
						return self.d_model



