



'''simple docstring'''






import os
import unittest

import pytest
from parameterized import parameterized

from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device


# skipping in unittest tests

UpperCamelCase__:       Union[str, Any]							     =      [(1,)]


def 			snake_case_					( )				->       Union[str, Any]:
       UpperCAmelCase			:	Any										=		bool(os.getenv('''RUN_SLOW'''       ,				0  )  )
       if run_slow:
              assert True
       else:
              assert False, "should have been skipped"


def 			snake_case_					( )				->       Union[str, Any]:
       UpperCAmelCase			:	Optional[Any]										=		bool(os.getenv('''RUN_SLOW'''       ,				0  )  )
       if run_slow and torch_device == "cuda":
              assert True
       else:
              assert False, "should have been skipped"

@require_torch
class     SCREAMING_SNAKE_CASE(							unittest.TestCase      ):







 """simple docstring"""






 @slow
 @require_torch_gpu
 def 					A     (						self      :					Union[str, Any]		)      ->		Optional[Any]:
        check_slow_torch_cuda()







 @require_torch_gpu
 @slow
 def 					A     (						self      :					Any		)      ->		List[str]:
        check_slow_torch_cuda()







 @parameterized.expand(__snake_case		)
 @slow
 def 					A     (						self      :					Optional[Any]		,      __snake_case      :					Union[str, Any]=None		)      ->		List[Any]:
        check_slow()


@slow
@require_torch_gpu
def 			snake_case_					( )				->       Optional[Any]:
       check_slow_torch_cuda()


@require_torch_gpu
@slow
def 			snake_case_					( )				->       Any:
       check_slow_torch_cuda()


@slow
@pytest.mark.parametrize('''param'''       ,				[1]  )
def 			snake_case_					( _lowerCAmelCase  :						Union[str, Any]  )				->       Any:
       check_slow()




@pytest.mark.parametrize('''param'''       ,				[1]  )
@slow
def 			snake_case_					( _lowerCAmelCase  :						List[str]  )				->       Dict:
       check_slow()










'''simple docstring'''






import importlib.metadata
import subprocess
import sys


def 			snake_case_					( _lowerCAmelCase  :						bool = False  )				->       str:
							UpperCAmelCase			:	List[str]										=		False
							if "IPython" in sys.modules:
														UpperCAmelCase			:	Optional[Any]										=		'''google.colab''' in str(sys.modules['''IPython'''].get_ipython()  )

							if in_colab:
														if upgrade:
																					UpperCAmelCase			:	List[Any]										=		['''pip''', '''install''', '''-U''', '''torch''']
																					subprocess.run(_lowerCAmelCase       ,				check=_lowerCAmelCase  )
														# get the current version of torch
														UpperCAmelCase			:	Dict										=		importlib.metadata.version('''torch'''  )
														UpperCAmelCase			:	int										=		torch_version[: torch_version.rindex('''.'''  )]
														UpperCAmelCase			:	Any										=		f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
														UpperCAmelCase			:	List[str]										=		['''pip''', '''install''', xla_wheel]
														subprocess.run(_lowerCAmelCase       ,				check=_lowerCAmelCase  )
							else:
														raise RuntimeError('''`install_xla` utility works only on google colab.'''  )





