'''simple docstring'''







import copy
import tempfile
import unittest

from huggingface_hub import HfFolder, delete_repo
from parameterized import parameterized
from requests.exceptions import HTTPError

from transformers import AutoConfig, GenerationConfig
from transformers.testing_utils import TOKEN, USER, is_staging_test




class _SCREAMING_SNAKE_CASE(							unittest.TestCase					):




						@parameterized.expand([(None,), ('foo.json',)]      )
						def      __lowerCamelCase       (    self :       List[str]							,							UpperCamelCase_ :       List[Any]      )     ->				Any:
													SCREAMING_SNAKE_CASE__     :int						    = GenerationConfig(
													    do_sample=UpperCamelCase_							,							temperature=0.7							,							length_penalty=1.0							,							bad_words_ids=[[1, 2, 3], [4, 5]]							,							)
													with tempfile.TemporaryDirectory() as tmp_dir:
																				config.save_pretrained(UpperCamelCase_							,							config_name=UpperCamelCase_      )
																				SCREAMING_SNAKE_CASE__     :Optional[int]						    = GenerationConfig.from_pretrained(UpperCamelCase_							,							config_name=UpperCamelCase_      )

													# Checks parameters that were specified
													self.assertEqual(loaded_config.do_sample							,							UpperCamelCase_      )
													self.assertEqual(loaded_config.temperature							,							0.7      )
													self.assertEqual(loaded_config.length_penalty							,							1.0      )
													self.assertEqual(loaded_config.bad_words_ids							,							[[1, 2, 3], [4, 5]]      )

													# Checks parameters that were not specified (defaults)
													self.assertEqual(loaded_config.top_k							,							50      )
													self.assertEqual(loaded_config.max_length							,							20      )
													self.assertEqual(loaded_config.max_time							,							UpperCamelCase_      )




						def      __lowerCamelCase       (    self :       Optional[int]      )     ->				List[str]:
													SCREAMING_SNAKE_CASE__     :str						    = AutoConfig.from_pretrained('gpt2'      )
													SCREAMING_SNAKE_CASE__     :Any						    = GenerationConfig.from_model_config(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Tuple						    = GenerationConfig()

													# The generation config has loaded a few non-default parameters from the model config
													self.assertNotEqual(UpperCamelCase_							,							UpperCamelCase_      )

													# One of those parameters is eos_token_id -- check if it matches
													self.assertNotEqual(generation_config_from_model.eos_token_id							,							default_generation_config.eos_token_id      )
													self.assertEqual(generation_config_from_model.eos_token_id							,							model_config.eos_token_id      )




						def      __lowerCamelCase       (    self :       Dict      )     ->				List[str]:
													SCREAMING_SNAKE_CASE__     :Tuple						    = GenerationConfig()
													SCREAMING_SNAKE_CASE__     :Optional[int]						    = {
													    'max_new_tokens': 10_24,
													    'foo': 'bar',
													}
													SCREAMING_SNAKE_CASE__     :Dict						    = copy.deepcopy(UpperCamelCase_      )
													SCREAMING_SNAKE_CASE__     :Dict						    = generation_config.update(**UpperCamelCase_      )

													# update_kwargs was not modified (no side effects)
													self.assertEqual(UpperCamelCase_							,							UpperCamelCase_      )

													# update_kwargs was used to update the config on valid attributes
													self.assertEqual(generation_config.max_new_tokens							,							10_24      )

													# `.update()` returns a dictionary of unused kwargs
													self.assertEqual(UpperCamelCase_							,							{'foo': 'bar'}      )




						def      __lowerCamelCase       (    self :       Any      )     ->				Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :List[Any]						    = GenerationConfig()
													SCREAMING_SNAKE_CASE__     :Dict						    = 'bar'

													with tempfile.TemporaryDirectory('test-generation-config'      ) as tmp_dir:
																				generation_config.save_pretrained(UpperCamelCase_      )

																				SCREAMING_SNAKE_CASE__     :Any						    = GenerationConfig.from_pretrained(UpperCamelCase_      )
													# update_kwargs was used to update the config on valid attributes
													self.assertEqual(new_config.foo							,							'bar'      )

													SCREAMING_SNAKE_CASE__     :List[str]						    = GenerationConfig.from_model_config(UpperCamelCase_      )
													assert not hasattr(UpperCamelCase_							,							'foo'      )  # no new kwargs should be initialized if from config




						def      __lowerCamelCase       (    self :       Optional[int]      )     ->				Any:
													SCREAMING_SNAKE_CASE__     :List[str]						    = GenerationConfig()
													self.assertEqual(default_config.temperature							,							1.0      )
													self.assertEqual(default_config.do_sample							,							UpperCamelCase_      )
													self.assertEqual(default_config.num_beams							,							1      )

													SCREAMING_SNAKE_CASE__     :str						    = GenerationConfig(
													    do_sample=UpperCamelCase_							,							temperature=0.7							,							length_penalty=1.0							,							bad_words_ids=[[1, 2, 3], [4, 5]]							,							)
													self.assertEqual(config.temperature							,							0.7      )
													self.assertEqual(config.do_sample							,							UpperCamelCase_      )
													self.assertEqual(config.num_beams							,							1      )

													with tempfile.TemporaryDirectory() as tmp_dir:
																				config.save_pretrained(UpperCamelCase_      )
																				SCREAMING_SNAKE_CASE__     :Optional[Any]						    = GenerationConfig.from_pretrained(UpperCamelCase_							,							temperature=1.0      )

													self.assertEqual(loaded_config.temperature							,							1.0      )
													self.assertEqual(loaded_config.do_sample							,							UpperCamelCase_      )
													self.assertEqual(loaded_config.num_beams							,							1      )  # default value




@is_staging_test
class _SCREAMING_SNAKE_CASE(							unittest.TestCase					):




						@classmethod
						def      __lowerCamelCase       (    cls :       Optional[Any]      )     ->				List[Any]:
													SCREAMING_SNAKE_CASE__     :Union[str, Any]						    = TOKEN
													HfFolder.save_token(UpperCamelCase_      )




						@classmethod
						def      __lowerCamelCase       (    cls :       List[str]      )     ->				Any:
													try:
																				delete_repo(token=cls._token							,							repo_id='test-generation-config'      )
													except HTTPError:
																				pass

													try:
																				delete_repo(token=cls._token							,							repo_id='valid_org/test-generation-config-org'      )
													except HTTPError:
																				pass




						def      __lowerCamelCase       (    self :       List[str]      )     ->				Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = GenerationConfig(
													    do_sample=UpperCamelCase_							,							temperature=0.7							,							length_penalty=1.0							,							)
													config.push_to_hub('test-generation-config'							,							use_auth_token=self._token      )

													SCREAMING_SNAKE_CASE__     :Tuple						    = GenerationConfig.from_pretrained(f'''{USER}/test-generation-config'''      )
													for k, v in config.to_dict().items():
																				if k != "transformers_version":
																											self.assertEqual(UpperCamelCase_							,							getattr(UpperCamelCase_							,							UpperCamelCase_      )      )

        # Reset repo
													delete_repo(token=self._token							,							repo_id='test-generation-config'      )

													# Push to hub via save_pretrained
													with tempfile.TemporaryDirectory() as tmp_dir:
																				config.save_pretrained(
																				    UpperCamelCase_							,							repo_id='test-generation-config'							,							push_to_hub=UpperCamelCase_							,							use_auth_token=self._token      )

													SCREAMING_SNAKE_CASE__     :List[str]						    = GenerationConfig.from_pretrained(f'''{USER}/test-generation-config'''      )
													for k, v in config.to_dict().items():
																				if k != "transformers_version":
																											self.assertEqual(UpperCamelCase_							,							getattr(UpperCamelCase_							,							UpperCamelCase_      )      )




						def      __lowerCamelCase       (    self :       str      )     ->				Dict:
													SCREAMING_SNAKE_CASE__     :Optional[Any]						    = GenerationConfig(
													    do_sample=UpperCamelCase_							,							temperature=0.7							,							length_penalty=1.0							,							)
													config.push_to_hub('valid_org/test-generation-config-org'							,							use_auth_token=self._token      )

													SCREAMING_SNAKE_CASE__     :str						    = GenerationConfig.from_pretrained('valid_org/test-generation-config-org'      )
													for k, v in config.to_dict().items():
																				if k != "transformers_version":
																											self.assertEqual(UpperCamelCase_							,							getattr(UpperCamelCase_							,							UpperCamelCase_      )      )

        # Reset repo
													delete_repo(token=self._token							,							repo_id='valid_org/test-generation-config-org'      )

													# Push to hub via save_pretrained
													with tempfile.TemporaryDirectory() as tmp_dir:
																				config.save_pretrained(
																				    UpperCamelCase_							,							repo_id='valid_org/test-generation-config-org'							,							push_to_hub=UpperCamelCase_							,							use_auth_token=self._token      )

													SCREAMING_SNAKE_CASE__     :Optional[int]						    = GenerationConfig.from_pretrained('valid_org/test-generation-config-org'      )
													for k, v in config.to_dict().items():
																				if k != "transformers_version":
																											self.assertEqual(UpperCamelCase_							,							getattr(UpperCamelCase_							,							UpperCamelCase_      )      )







'''simple docstring'''







import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
UpperCamelCase_      	=	'''.'''


if __name__ == "__main__":
		UpperCamelCase_      	=	os.path.join(REPO_PATH, '''utils/documentation_tests.txt''')
		UpperCamelCase_      	=	[]
		UpperCamelCase_      	=	[]
		with open(doctest_file_path) as fp:
				for line in fp:
						UpperCamelCase_      	=	line.strip()
						UpperCamelCase_      	=	os.path.join(REPO_PATH, line)
						if not (os.path.isfile(path) or os.path.isdir(path)):
								non_existent_paths.append(line)
						all_paths.append(path)
		if len(non_existent_paths) > 0:
				UpperCamelCase_      	=	'''\n'''.join(non_existent_paths)
				raise ValueError(f"`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}")
		if all_paths != sorted(all_paths):
				raise ValueError('''Files in `utils/documentation_tests.txt` are not in alphabetical order.''')






