

'''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  UpperCAmelCase (							unittest.TestCase    ):

		'''simple docstring'''






		@parameterized.expand([(None,), ('foo.json',)]		)
		def 			UpperCamelCase(					self   ,			SCREAMING_SNAKE_CASE_		)  ->     Union[str, Any]:






							'''simple docstring'''



							lowerCamelCase_  				=      GenerationConfig(
							    do_sample=SCREAMING_SNAKE_CASE_   ,			temperature=0.7   ,			length_penalty=1.0   ,			bad_words_ids=[[1, 2, 3], [4, 5]]   ,			)
							with tempfile.TemporaryDirectory() as tmp_dir:
												config.save_pretrained(SCREAMING_SNAKE_CASE_   ,			config_name=SCREAMING_SNAKE_CASE_		)
												lowerCamelCase_  				=      GenerationConfig.from_pretrained(SCREAMING_SNAKE_CASE_   ,			config_name=SCREAMING_SNAKE_CASE_		)

							# Checks parameters that were specified
							self.assertEqual(loaded_config.do_sample   ,			SCREAMING_SNAKE_CASE_		)
							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   ,			SCREAMING_SNAKE_CASE_		)
		def 			UpperCamelCase(					self		)  ->     Tuple:






							'''simple docstring'''



							lowerCamelCase_  				=      AutoConfig.from_pretrained('gpt2'		)
							lowerCamelCase_  				=      GenerationConfig.from_model_config(SCREAMING_SNAKE_CASE_		)
							lowerCamelCase_  				=      GenerationConfig()

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

							# 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 			UpperCamelCase(					self		)  ->     List[Any]:






							'''simple docstring'''



							lowerCamelCase_  				=      GenerationConfig()
							lowerCamelCase_  				=      {
							    'max_new_tokens': 1024,
							    'foo': 'bar',
							}
							lowerCamelCase_  				=      copy.deepcopy(SCREAMING_SNAKE_CASE_		)
							lowerCamelCase_  				=      generation_config.update(**SCREAMING_SNAKE_CASE_		)

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

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

							# `.update()` returns a dictionary of unused kwargs
							self.assertEqual(SCREAMING_SNAKE_CASE_   ,			{'foo': 'bar'}		)
		def 			UpperCamelCase(					self		)  ->     Optional[int]:






							'''simple docstring'''



							lowerCamelCase_  				=      GenerationConfig()
							lowerCamelCase_  				=      'bar'

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

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

							lowerCamelCase_  				=      GenerationConfig.from_model_config(SCREAMING_SNAKE_CASE_		)
							assert not hasattr(SCREAMING_SNAKE_CASE_   ,			'foo'		)  # no new kwargs should be initialized if from config






		def 			UpperCamelCase(					self		)  ->     Optional[int]:






							'''simple docstring'''



							lowerCamelCase_  				=      GenerationConfig()
							self.assertEqual(default_config.temperature   ,			1.0		)
							self.assertEqual(default_config.do_sample   ,			SCREAMING_SNAKE_CASE_		)
							self.assertEqual(default_config.num_beams   ,			1		)

							lowerCamelCase_  				=      GenerationConfig(
							    do_sample=SCREAMING_SNAKE_CASE_   ,			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   ,			SCREAMING_SNAKE_CASE_		)
							self.assertEqual(config.num_beams   ,			1		)

							with tempfile.TemporaryDirectory() as tmp_dir:
												config.save_pretrained(SCREAMING_SNAKE_CASE_		)
												lowerCamelCase_  				=      GenerationConfig.from_pretrained(SCREAMING_SNAKE_CASE_   ,			temperature=1.0		)

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


@is_staging_test
class  UpperCAmelCase (							unittest.TestCase    ):

		'''simple docstring'''






		@classmethod
		def 			UpperCamelCase(					cls		)  ->     Optional[int]:






							'''simple docstring'''



							lowerCamelCase_  				=      TOKEN
							HfFolder.save_token(SCREAMING_SNAKE_CASE_		)
		@classmethod
		def 			UpperCamelCase(					cls		)  ->     Tuple:






							'''simple docstring'''



							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 			UpperCamelCase(					self		)  ->     Dict:






							'''simple docstring'''



							lowerCamelCase_  				=      GenerationConfig(
							    do_sample=SCREAMING_SNAKE_CASE_   ,			temperature=0.7   ,			length_penalty=1.0   ,			)
							config.push_to_hub('test-generation-config'   ,			use_auth_token=self._token		)

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

        # 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(
												    SCREAMING_SNAKE_CASE_   ,			repo_id='test-generation-config'   ,			push_to_hub=SCREAMING_SNAKE_CASE_   ,			use_auth_token=self._token		)

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






		def 			UpperCamelCase(					self		)  ->     Tuple:






							'''simple docstring'''



							lowerCamelCase_  				=      GenerationConfig(
							    do_sample=SCREAMING_SNAKE_CASE_   ,			temperature=0.7   ,			length_penalty=1.0   ,			)
							config.push_to_hub('valid_org/test-generation-config-org'   ,			use_auth_token=self._token		)

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

        # 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(
												    SCREAMING_SNAKE_CASE_   ,			repo_id='valid_org/test-generation-config-org'   ,			push_to_hub=SCREAMING_SNAKE_CASE_   ,			use_auth_token=self._token		)

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








import numpy as np
from sklearn.datasets import fetch_california_housing
from sklearn.metrics import mean_absolute_error, mean_squared_error
from sklearn.model_selection import train_test_split
from xgboost import XGBRegressor

def        __a			(   __lowerCAmelCase   )     ->     tuple:
					return (data["data"], data["target"])

def        __a			(   __lowerCAmelCase      ,	__lowerCAmelCase      ,	__lowerCAmelCase   )     ->     np.ndarray:
					SCREAMING_SNAKE_CASE							:     int						=				XGBRegressor(verbosity=0      ,	random_state=42   )
					xgb.fit(__lowerCAmelCase      ,	__lowerCAmelCase   )
					# Predict target for test data
					SCREAMING_SNAKE_CASE							:     List[Any]						=				xgb.predict(__lowerCAmelCase   )
					SCREAMING_SNAKE_CASE							:     str						=				predictions.reshape(len(__lowerCAmelCase   )      ,	1   )
					return predictions

def        __a			(   )     ->     None:
					SCREAMING_SNAKE_CASE							:     Dict						=				fetch_california_housing()
					SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     Any						=				data_handling(__lowerCAmelCase   )
					SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     str						=				train_test_split(
					    __lowerCAmelCase      ,	__lowerCAmelCase      ,	test_size=0.25      ,	random_state=1   )
					SCREAMING_SNAKE_CASE							:     int						=				xgboost(__lowerCAmelCase      ,	__lowerCAmelCase      ,	__lowerCAmelCase   )
					# Error printing
					print(F'''Mean Absolute Error : {mean_absolute_error(__lowerCAmelCase      ,	__lowerCAmelCase   )}'''   )
					print(F'''Mean Square Error  : {mean_squared_error(__lowerCAmelCase      ,	__lowerCAmelCase   )}'''   )


if __name__ == "__main__":
			import doctest

			doctest.testmod(verbose=True)
			main()