






'''simple docstring'''




import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
		import tensorflow as tf

		from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments







@require_tf
class       __lowercase					(unittest.TestCase    ):

	def      __UpperCamelCase							(      self   :						List[str]  ,					UpperCAmelCase_   :						Union[str, Any]):
			for model_result in results.values():
					for batch_size, sequence_length in zip(model_result['bs']  ,					model_result['ss']):
							UpperCamelCase__				:					str					=					model_result['result'][batch_size][sequence_length]
							self.assertIsNotNone(UpperCAmelCase_)

	def      __UpperCamelCase							(      self   :						Tuple):
			UpperCamelCase__				:					Dict					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					Tuple					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					eager_mode=UpperCAmelCase_  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					Optional[int]					=					TensorFlowBenchmark(UpperCAmelCase_)
			UpperCamelCase__				:					Tuple					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	def      __UpperCamelCase							(      self   :						Optional[Any]):
			UpperCamelCase__				:					List[str]					=					'sgugger/tiny-distilbert-classification'
			UpperCamelCase__				:					Optional[int]					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					multi_process=UpperCAmelCase_  ,					only_pretrain_model=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					Optional[Any]					=					TensorFlowBenchmark(UpperCAmelCase_)
			UpperCamelCase__				:					int					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	def      __UpperCamelCase							(      self   :						Tuple):
			UpperCamelCase__				:					Optional[Any]					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					Optional[int]					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					Optional[Any]					=					TensorFlowBenchmark(UpperCAmelCase_)
			UpperCamelCase__				:					List[Any]					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	def      __UpperCamelCase							(      self   :						Optional[Any]):
			UpperCamelCase__				:					int					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					int					=					AutoConfig.from_pretrained(UpperCAmelCase_)
			UpperCamelCase__				:					int					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					eager_mode=UpperCAmelCase_  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					Optional[Any]					=					TensorFlowBenchmark(UpperCAmelCase_  ,					[config])
			UpperCamelCase__				:					Any					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	def      __UpperCamelCase							(      self   :						Optional[Any]):
			UpperCamelCase__				:					List[str]					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					Union[str, Any]					=					AutoConfig.from_pretrained(UpperCAmelCase_)
			UpperCamelCase__				:					Tuple					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					str					=					TensorFlowBenchmark(UpperCAmelCase_  ,					[config])
			UpperCamelCase__				:					Dict					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	def      __UpperCamelCase							(      self   :						Union[str, Any]):
			UpperCamelCase__				:					int					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					List[str]					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					List[str]					=					TensorFlowBenchmark(UpperCAmelCase_)
			UpperCamelCase__				:					Dict					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_train_result)
			self.check_results_dict_not_empty(results.memory_train_result)

	def      __UpperCamelCase							(      self   :						Any):
			UpperCamelCase__				:					Tuple					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					Optional[int]					=					AutoConfig.from_pretrained(UpperCAmelCase_)
			UpperCamelCase__				:					str					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					Optional[int]					=					TensorFlowBenchmark(UpperCAmelCase_  ,					[config])
			UpperCamelCase__				:					Dict					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_train_result)
			self.check_results_dict_not_empty(results.memory_train_result)

	def      __UpperCamelCase							(      self   :						Dict):
			UpperCamelCase__				:					Tuple					=					'patrickvonplaten/t5-tiny-random'
			UpperCamelCase__				:					List[str]					=					AutoConfig.from_pretrained(UpperCAmelCase_)
			UpperCamelCase__				:					str					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					str					=					TensorFlowBenchmark(UpperCAmelCase_  ,					configs=[config])
			UpperCamelCase__				:					Union[str, Any]					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	@unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices('GPU')) == 0  ,					'Cannot do xla on CPU.')
	def      __UpperCamelCase							(      self   :						int):
			UpperCamelCase__				:					str					=					'sshleifer/tiny-gpt2'
			UpperCamelCase__				:					List[Any]					=					TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]  ,					training=UpperCAmelCase_  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					use_xla=UpperCAmelCase_  ,					multi_process=UpperCAmelCase_  ,					)
			UpperCamelCase__				:					List[Any]					=					TensorFlowBenchmark(UpperCAmelCase_)
			UpperCamelCase__				:					Any					=					benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result)
			self.check_results_dict_not_empty(results.memory_inference_result)

	def      __UpperCamelCase							(      self   :						List[str]):
			UpperCamelCase__				:					Any					=					'sshleifer/tiny-gpt2'
			with tempfile.TemporaryDirectory() as tmp_dir:
					UpperCamelCase__				:					str					=					TensorFlowBenchmarkArguments(
					    models=[MODEL_ID]  ,					inference=UpperCAmelCase_  ,					save_to_csv=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					inference_time_csv_file=os.path.join(UpperCAmelCase_  ,					'inf_time.csv')  ,					inference_memory_csv_file=os.path.join(UpperCAmelCase_  ,					'inf_mem.csv')  ,					env_info_csv_file=os.path.join(UpperCAmelCase_  ,					'env.csv')  ,					multi_process=UpperCAmelCase_  ,					)
					UpperCamelCase__				:					Optional[Any]					=					TensorFlowBenchmark(UpperCAmelCase_)
					benchmark.run()
					self.assertTrue(Path(os.path.join(UpperCAmelCase_  ,					'inf_time.csv')).exists())
					self.assertTrue(Path(os.path.join(UpperCAmelCase_  ,					'inf_mem.csv')).exists())
					self.assertTrue(Path(os.path.join(UpperCAmelCase_  ,					'env.csv')).exists())





	def      __UpperCamelCase							(      self   :						str):
			UpperCamelCase__				:					List[Any]					=					'sshleifer/tiny-gpt2'

			def _check_summary_is_not_empty(UpperCAmelCase_   :						Union[str, Any]):
					self.assertTrue(hasattr(UpperCAmelCase_  ,					'sequential'))
					self.assertTrue(hasattr(UpperCAmelCase_  ,					'cumulative'))
					self.assertTrue(hasattr(UpperCAmelCase_  ,					'current'))
					self.assertTrue(hasattr(UpperCAmelCase_  ,					'total'))

			with tempfile.TemporaryDirectory() as tmp_dir:
					UpperCamelCase__				:					Tuple					=					TensorFlowBenchmarkArguments(
					    models=[MODEL_ID]  ,					inference=UpperCAmelCase_  ,					sequence_lengths=[8]  ,					batch_sizes=[1]  ,					log_filename=os.path.join(UpperCAmelCase_  ,					'log.txt')  ,					log_print=UpperCAmelCase_  ,					trace_memory_line_by_line=UpperCAmelCase_  ,					eager_mode=UpperCAmelCase_  ,					multi_process=UpperCAmelCase_  ,					)
					UpperCamelCase__				:					Any					=					TensorFlowBenchmark(UpperCAmelCase_)
					UpperCamelCase__				:					Union[str, Any]					=					benchmark.run()
					_check_summary_is_not_empty(result.inference_summary)
					self.assertTrue(Path(os.path.join(UpperCAmelCase_  ,					'log.txt')).exists())












'''simple docstring'''




import requests
from bsa import BeautifulSoup







def       __UpperCAmelCase						(  lowerCamelCase_ = "AAPL")							->     str:
		UpperCamelCase__				:					str					=					f'https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'
		UpperCamelCase__				:					Optional[Any]					=					BeautifulSoup(requests.get(lowerCamelCase_).text     ,      'html.parser')
		UpperCamelCase__				:					Union[str, Any]					=					'My(6px) Pos(r) smartphone_Mt(6px)'
		return soup.find('div'     ,      class_=class_).find('span').text


if __name__ == "__main__":
		for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
				print(f'''Current {symbol:<4} stock price is {stock_price(symbol):>8}''')




