


import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_torch_available
from transformers.testing_utils import require_torch, torch_device


if is_torch_available():
    from transformers import PyTorchBenchmark, PyTorchBenchmarkArguments







@require_torch
class     _lowercase				(							unittest.TestCase):


       """simple docstring"""




       def 		lowerCAmelCase  (     self							:    int      ,   __lowerCamelCase							:    Any ):


             '''simple docstring'''



             for model_result in results.values():
                   for batch_size, sequence_length in zip(model_result["bs"]      ,   model_result["ss"] ):
                         lowerCamelCase__	:       List[Any]					=						model_result["result"][batch_size][sequence_length]
                         self.assertIsNotNone(__lowerCamelCase )





       def 		lowerCAmelCase  (     self							:    Tuple ):


             '''simple docstring'''



             lowerCamelCase__	:       Any					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       Optional[Any]					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       List[Any]					=						PyTorchBenchmark(__lowerCamelCase )
             lowerCamelCase__	:       Dict					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result )
             self.check_results_dict_not_empty(results.memory_inference_result )





       def 		lowerCAmelCase  (     self							:    List[str] ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						"sgugger/tiny-distilbert-classification"
             lowerCamelCase__	:       List[Any]					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   only_pretrain_model=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Optional[Any]					=						PyTorchBenchmark(__lowerCamelCase )
             lowerCamelCase__	:       Any					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result )
             self.check_results_dict_not_empty(results.memory_inference_result )





       def 		lowerCAmelCase  (     self							:    List[str] ):


             '''simple docstring'''



             lowerCamelCase__	:       List[str]					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       Union[str, Any]					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   torchscript=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       str					=						PyTorchBenchmark(__lowerCamelCase )
             lowerCamelCase__	:       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(torch_device == "cpu"      ,   "Cant do half precision" )
       def 		lowerCAmelCase  (     self							:    str ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       int					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   fpaa=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Optional[int]					=						PyTorchBenchmark(__lowerCamelCase )
             lowerCamelCase__	:       Dict					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result )
             self.check_results_dict_not_empty(results.memory_inference_result )





       def 		lowerCAmelCase  (     self							:    List[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       int					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       Any					=						AutoConfig.from_pretrained(__lowerCamelCase )
             # set architectures equal to `None`
             lowerCamelCase__	:       Any					=						None
             lowerCamelCase__	:       Dict					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Optional[int]					=						PyTorchBenchmark(__lowerCamelCase      ,   configs=[config] )
             lowerCamelCase__	:       Any					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result )
             self.check_results_dict_not_empty(results.memory_inference_result )





       def 		lowerCAmelCase  (     self							:    int ):


             '''simple docstring'''



             lowerCamelCase__	:       str					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       Union[str, Any]					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Optional[Any]					=						PyTorchBenchmark(__lowerCamelCase )
             lowerCamelCase__	:       Optional[Any]					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result )
             self.check_results_dict_not_empty(results.memory_train_result )





       @unittest.skipIf(torch_device == "cpu"      ,   "Can't do half precision" )
       def 		lowerCAmelCase  (     self							:    Tuple ):


             '''simple docstring'''



             lowerCamelCase__	:       Tuple					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       Optional[int]					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   fpaa=__lowerCamelCase      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Any					=						PyTorchBenchmark(__lowerCamelCase )
             lowerCamelCase__	:       Dict					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result )
             self.check_results_dict_not_empty(results.memory_train_result )





       def 		lowerCAmelCase  (     self							:    Dict ):


             '''simple docstring'''



             lowerCamelCase__	:       Optional[int]					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       List[Any]					=						AutoConfig.from_pretrained(__lowerCamelCase )
             lowerCamelCase__	:       int					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       List[Any]					=						PyTorchBenchmark(__lowerCamelCase      ,   configs=[config] )
             lowerCamelCase__	:       str					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result )
             self.check_results_dict_not_empty(results.memory_inference_result )





       def 		lowerCAmelCase  (     self							:    Any ):


             '''simple docstring'''



             lowerCamelCase__	:       Optional[Any]					=						"sshleifer/tinier_bart"
             lowerCamelCase__	:       Dict					=						AutoConfig.from_pretrained(__lowerCamelCase )
             lowerCamelCase__	:       int					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       str					=						PyTorchBenchmark(__lowerCamelCase      ,   configs=[config] )
             lowerCamelCase__	:       List[str]					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_inference_result )
             self.check_results_dict_not_empty(results.memory_inference_result )





       def 		lowerCAmelCase  (     self							:    List[Any] ):


             '''simple docstring'''



             lowerCamelCase__	:       List[str]					=						"sshleifer/tiny-gpt2"
             lowerCamelCase__	:       Optional[int]					=						AutoConfig.from_pretrained(__lowerCamelCase )
             lowerCamelCase__	:       Dict					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Any					=						PyTorchBenchmark(__lowerCamelCase      ,   configs=[config] )
             lowerCamelCase__	:       int					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result )
             self.check_results_dict_not_empty(results.memory_train_result )





       def 		lowerCAmelCase  (     self							:    Any ):


             '''simple docstring'''



             lowerCamelCase__	:       Union[str, Any]					=						"sshleifer/tinier_bart"
             lowerCamelCase__	:       Union[str, Any]					=						AutoConfig.from_pretrained(__lowerCamelCase )
             lowerCamelCase__	:       List[str]					=						PyTorchBenchmarkArguments(
                 models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   multi_process=__lowerCamelCase      ,   )
             lowerCamelCase__	:       Dict					=						PyTorchBenchmark(__lowerCamelCase      ,   configs=[config] )
             lowerCamelCase__	:       int					=						benchmark.run()
             self.check_results_dict_not_empty(results.time_train_result )
             self.check_results_dict_not_empty(results.memory_train_result )





       def 		lowerCAmelCase  (     self							:    Any ):


             '''simple docstring'''



             lowerCamelCase__	:       Optional[Any]					=						"sshleifer/tiny-gpt2"
             with tempfile.TemporaryDirectory() as tmp_dir:
                   lowerCamelCase__	:       List[str]					=						PyTorchBenchmarkArguments(
                       models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   save_to_csv=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   inference_time_csv_file=os.path.join(__lowerCamelCase      ,   "inf_time.csv" )      ,   train_memory_csv_file=os.path.join(__lowerCamelCase      ,   "train_mem.csv" )      ,   inference_memory_csv_file=os.path.join(__lowerCamelCase      ,   "inf_mem.csv" )      ,   train_time_csv_file=os.path.join(__lowerCamelCase      ,   "train_time.csv" )      ,   env_info_csv_file=os.path.join(__lowerCamelCase      ,   "env.csv" )      ,   multi_process=__lowerCamelCase      ,   )
                   lowerCamelCase__	:       Union[str, Any]					=						PyTorchBenchmark(__lowerCamelCase )
                   benchmark.run()
                   self.assertTrue(Path(os.path.join(__lowerCamelCase      ,   "inf_time.csv" ) ).exists() )
                   self.assertTrue(Path(os.path.join(__lowerCamelCase      ,   "train_time.csv" ) ).exists() )
                   self.assertTrue(Path(os.path.join(__lowerCamelCase      ,   "inf_mem.csv" ) ).exists() )
                   self.assertTrue(Path(os.path.join(__lowerCamelCase      ,   "train_mem.csv" ) ).exists() )
                   self.assertTrue(Path(os.path.join(__lowerCamelCase      ,   "env.csv" ) ).exists() )





       def 		lowerCAmelCase  (     self							:    Dict ):


             '''simple docstring'''



             lowerCamelCase__	:       Union[str, Any]					=						"sshleifer/tiny-gpt2"

             def _check_summary_is_not_empty(__lowerCamelCase							:    str ):
                   self.assertTrue(hasattr(__lowerCamelCase      ,   "sequential" ) )
                   self.assertTrue(hasattr(__lowerCamelCase      ,   "cumulative" ) )
                   self.assertTrue(hasattr(__lowerCamelCase      ,   "current" ) )
                   self.assertTrue(hasattr(__lowerCamelCase      ,   "total" ) )

             with tempfile.TemporaryDirectory() as tmp_dir:
                   lowerCamelCase__	:       Tuple					=						PyTorchBenchmarkArguments(
                       models=[MODEL_ID]      ,   training=__lowerCamelCase      ,   inference=__lowerCamelCase      ,   sequence_lengths=[8]      ,   batch_sizes=[1]      ,   log_filename=os.path.join(__lowerCamelCase      ,   "log.txt" )      ,   log_print=__lowerCamelCase      ,   trace_memory_line_by_line=__lowerCamelCase      ,   multi_process=__lowerCamelCase      ,   )
                   lowerCamelCase__	:       str					=						PyTorchBenchmark(__lowerCamelCase )
                   lowerCamelCase__	:       Union[str, Any]					=						benchmark.run()
                   _check_summary_is_not_empty(result.inference_summary )
                   _check_summary_is_not_empty(result.train_summary )
                   self.assertTrue(Path(os.path.join(__lowerCamelCase      ,   "log.txt" ) ).exists() )






import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
    print("Googling.....")
    A   :					str	=      "https://www.google.com/search?q=" + " ".join(sys.argv[1:])
    A   :					Optional[int]	=      requests.get(url, headers={"UserAgent": UserAgent().random})
    # res.raise_for_status()
    with open("project1a.html", "wb") as out_file:  # only for knowing the class
        for data in res.iter_content(10000):
            out_file.write(data)
    A   :					int	=      BeautifulSoup(res.text, "html.parser")
    A   :					Any	=      list(soup.select(".eZt8xd"))[:5]

    print(len(links))
    for link in links:
        if link.text == "Maps":
            webbrowser.open(link.get("href"))
        else:
            webbrowser.open(f'https://google.com{link.get("href")}')


