code: 
  
  
  
  
  
  
  import os
  import pickle
  import unittest
  from collections import UserDict, namedtuple
  
  import torch
  
  from accelerate.test_utils.testing import require_cuda, require_torch_min_version
  from accelerate.test_utils.training import RegressionModel
  from accelerate.utils import (
      convert_outputs_to_fpaa,
      extract_model_from_parallel,
      find_device,
      listify,
      patch_environment,
      recursively_apply,
      send_to_device,
  )
  
  
  SCREAMING_SNAKE_CASE__		:       Dict   							=							namedtuple("""ExampleNamedTuple""", """a b c""")
  
  
  
  
  
  
  
  class 							UpperCAmelCase_     (		unittest.TestCase		):
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     List[str]										= torch.randn(5  ,	2		)
  										UpperCAmelCase__			:     Dict										= torch.device("""cuda"""		) if torch.cuda.is_available() else torch.device("""cpu"""		)
  
  										UpperCAmelCase__			:     Optional[int]										= send_to_device(_lowerCAmelCase  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta.cpu()  ,	_lowerCAmelCase		)		)
  
  										UpperCAmelCase__			:     Optional[Any]										= send_to_device((tensor, [tensor, tensor], 1)  ,	_lowerCAmelCase		)
  										self.assertIsInstance(_lowerCAmelCase  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta[0].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertIsInstance(resulta[1]  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta[1][0].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertTrue(torch.equal(resulta[1][1].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertEqual(resulta[2]  ,	1		)
  
  										UpperCAmelCase__			:     Any										= send_to_device({"""a""": tensor, """b""": [tensor, tensor], """c""": 1}  ,	_lowerCAmelCase		)
  										self.assertIsInstance(_lowerCAmelCase  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta["""a"""].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertIsInstance(resulta["""b"""]  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta["""b"""][0].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertTrue(torch.equal(resulta["""b"""][1].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertEqual(resulta["""c"""]  ,	1		)
  
  										UpperCAmelCase__			:     List[str]										= send_to_device(ExampleNamedTuple(a=_lowerCAmelCase  ,	b=[tensor, tensor]  ,	c=1		)  ,	_lowerCAmelCase		)
  										self.assertIsInstance(_lowerCAmelCase  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta.a.cpu()  ,	_lowerCAmelCase		)		)
  										self.assertIsInstance(resulta.b  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta.b[0].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertTrue(torch.equal(resulta.b[1].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertEqual(resulta.c  ,	1		)
  
  										UpperCAmelCase__			:     Tuple										= send_to_device(UserDict({"""a""": tensor, """b""": [tensor, tensor], """c""": 1}		)  ,	_lowerCAmelCase		)
  										self.assertIsInstance(_lowerCAmelCase  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta["""a"""].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertIsInstance(resulta["""b"""]  ,	_lowerCAmelCase		)
  										self.assertTrue(torch.equal(resulta["""b"""][0].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertTrue(torch.equal(resulta["""b"""][1].cpu()  ,	_lowerCAmelCase		)		)
  										self.assertEqual(resulta["""c"""]  ,	1		)
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										with self.assertRaises(_lowerCAmelCase		) as cm:
  															UpperCAmelCase__			:     Optional[int]										= recursively_apply(torch.tensor  ,	(torch.tensor(1		), 1)  ,	error_on_other_type=_lowerCAmelCase		)
  										self.assertEqual(
  										    str(cm.exception		)  ,	"""Unsupported types (<class 'int'>) passed to `tensor`. Only nested list/tuple/dicts of objects that are valid for `is_torch_tensor` should be passed."""  ,	)
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     Tuple										= torch.tensor([1, 2, 3, 4, 5]		)
  										self.assertEqual(listify(_lowerCAmelCase		)  ,	[1, 2, 3, 4, 5]		)
  
  										UpperCAmelCase__			:     Optional[Any]										= torch.tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]		)
  										self.assertEqual(listify(_lowerCAmelCase		)  ,	[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]		)
  
  										UpperCAmelCase__			:     int										= torch.tensor([[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], [[11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]]		)
  										self.assertEqual(
  										    listify(_lowerCAmelCase		)  ,	[[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], [[11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]]		)
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										with patch_environment(aa=1  ,	BB=2		):
  															self.assertEqual(os.environ.get("""AA"""		)  ,	"""1"""		)
  															self.assertEqual(os.environ.get("""BB"""		)  ,	"""2"""		)
  
  										self.assertNotIn("""AA"""  ,	os.environ		)
  										self.assertNotIn("""BB"""  ,	os.environ		)
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     Tuple										= RegressionModel()
  										UpperCAmelCase__			:     Any										= model.forward
  										UpperCAmelCase__			:     Any										= convert_outputs_to_fpaa(model.forward		)
  										UpperCAmelCase__			:     Any										= extract_model_from_parallel(_lowerCAmelCase  ,	keep_fpaa_wrapper=_lowerCAmelCase		)
  										UpperCAmelCase__			:     List[str]										= pickle.dumps(_lowerCAmelCase		)
  
  
  
  
  					@require_cuda
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     Dict										= RegressionModel()
  										UpperCAmelCase__			:     Dict										= model.forward
  										UpperCAmelCase__			:     Optional[Any]										= torch.cuda.amp.autocast(dtype=torch.floataa		)(model.forward		)
  										UpperCAmelCase__			:     int										= convert_outputs_to_fpaa(model.forward		)
  										UpperCAmelCase__			:     int										= extract_model_from_parallel(_lowerCAmelCase  ,	keep_fpaa_wrapper=_lowerCAmelCase		)
  										UpperCAmelCase__			:     Optional[int]										= pickle.dumps(_lowerCAmelCase		)
  
  
  
  
  					@require_cuda
  					@require_torch_min_version(version="""2.0"""		)
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     Optional[int]										= RegressionModel()
  										UpperCAmelCase__			:     int										= model.forward
  										UpperCAmelCase__			:     Any										= torch.cuda.amp.autocast(dtype=torch.floataa		)(model.forward		)
  										UpperCAmelCase__			:     Optional[Any]										= convert_outputs_to_fpaa(model.forward		)
  										UpperCAmelCase__			:     Dict										= torch.compile(model.forward  ,	backend="""inductor"""		)
  										UpperCAmelCase__			:     Optional[Any]										= torch.randn(4  ,	10		).cuda()
  										UpperCAmelCase__			:     Optional[int]										= model(_lowerCAmelCase		)
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     Any										= RegressionModel()
  										# could also do a test with DistributedDataParallel, but difficult to run on CPU or single GPU
  										UpperCAmelCase__			:     Optional[Any]										= torch.nn.parallel.DataParallel(_lowerCAmelCase		)
  										UpperCAmelCase__			:     List[Any]										= extract_model_from_parallel(_lowerCAmelCase		)
  
  										self.assertEqual(_lowerCAmelCase  ,	_lowerCAmelCase		)
  
  
  
  
  					@require_torch_min_version(version="""2.0"""		)
  					def      __UpperCAmelCase     (							self		):
  										UpperCAmelCase__			:     int										= RegressionModel()
  										UpperCAmelCase__			:     Dict										= torch.compile(_lowerCAmelCase		)
  
  										# could also do a test with DistributedDataParallel, but difficult to run on CPU or single GPU
  										UpperCAmelCase__			:     List[Any]										= torch.nn.parallel.DataParallel(_lowerCAmelCase		)
  										UpperCAmelCase__			:     Union[str, Any]										= torch.compile(_lowerCAmelCase		)
  										UpperCAmelCase__			:     List[str]										= extract_model_from_parallel(_lowerCAmelCase		)
  
  										self.assertEqual(compiled_model._orig_mod  ,	compiled_model_unwrapped._orig_mod		)
  
  
  
  
  					def      __UpperCAmelCase     (							self		):
  										self.assertEqual(find_device([1, """a""", torch.tensor([1, 2, 3]		)]		)  ,	torch.device("""cpu"""		)		)
  										self.assertEqual(find_device({"""a""": 1, """b""": torch.tensor([1, 2, 3]		)}		)  ,	torch.device("""cpu"""		)		)
  										self.assertIsNone(find_device([1, """a"""]		)		)
  
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  from .stack import Stack
  
  
  
  
  
  def    _lowerCamelCase	(	__lowerCamelCase					)   -> bool:
  
       '''simple docstring'''
       UpperCAmelCase__			:     Stack[str]										= Stack()
       UpperCAmelCase__			:     str										= {"""(""": """)""", """[""": """]""", """{""": """}"""}
       for bracket in parentheses:
            if bracket in bracket_pairs:
                 stack.push(__lowerCamelCase					)
            elif bracket in (")", "]", "}"):
                 if stack.is_empty() or bracket_pairs[stack.pop()] != bracket:
                      return False
       return stack.is_empty()
  
  
  if __name__ == "__main__":
        from doctest import testmod
  
        testmod()
  
        SCREAMING_SNAKE_CASE__		:       Any   							=							["""((()))""", """((())""", """(()))"""]
        print("""Balanced parentheses demonstration:\n""")
        for example in examples:
              SCREAMING_SNAKE_CASE__		:       List[str]   							=							"""""" if balanced_parentheses(example) else """not """
              print(f'''{example} is {not_str}balanced''')
  
  
  
  
  
  
  