



"""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		=						logging.getLogger()

def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							Optional[Any] ):
						"""simple docstring"""






						snake_case   :			List[Any]						    = {}
						snake_case   :			Optional[Any]						    = os.path.join(lowerCamelCase_     ,		"all_results.json" )
						if os.path.exists(lowerCamelCase_ ):
												with open(lowerCamelCase_     ,		"r" ) as f:
																		snake_case   :			Optional[int]						    = json.load(lowerCamelCase_ )
						else:
												raise ValueError(f'''can\'t find {path}''' )
						return results


A		=						logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)

@require_torch_tpu
class       _a  ( SCREAMING_SNAKE_CASE__):



			def 				__lowercase					(			self							:				Tuple		)							->					Optional[int]:
									import xla_spawn

									snake_case   :			Tuple						    = self.get_auto_remove_tmp_dir()
									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(_lowercase   ,	"argv"   ,	_lowercase		):
															snake_case   :			Any						    = time()
															xla_spawn.main()
															snake_case   :			Optional[int]						    = time()

															snake_case   :			str						    = get_results(_lowercase		)
															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 				__lowercase					(			self							:				List[Any]		)							->					str:
									import xla_spawn

									snake_case   :			List[Any]						    = "\n            ./tests/test_trainer_tpu.py\n            --num_cores=8\n            ./tests/test_trainer_tpu.py\n            ".split()
									with patch.object(_lowercase   ,	"argv"   ,	_lowercase		):
															xla_spawn.main()








"""simple docstring"""







# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re

from ..utils import cached_file


# docstyle-ignore
A		=						'\nHuman: <<task>>\n\nAssistant: '


A		=						'huggingface-tools/default-prompts'
A		=						{'chat': 'chat_prompt_template.txt', 'run': 'run_prompt_template.txt'}

def  __SCREAMING_SNAKE_CASE		(			lowerCamelCase_:							Optional[int]     ,		lowerCamelCase_:							str     ,		lowerCamelCase_:							Tuple="run" ):
						"""simple docstring"""






						if prompt_or_repo_id is None:
												snake_case   :			Any						    = DEFAULT_PROMPTS_REPO

						# prompt is considered a repo ID when it does not contain any kind of space
						if re.search("\\s"     ,		lowerCamelCase_ ) is not None:
												return prompt_or_repo_id

						snake_case   :			Optional[int]						    = cached_file(
						    lowerCamelCase_     ,		PROMPT_FILES[mode]     ,		repo_type="dataset"     ,		user_agent={"agent": agent_name} )
						with open(lowerCamelCase_     ,		"r"     ,		encoding="utf-8" ) as f:
												return f.read()



