



"""simple docstring"""





import ast
import os
import re
import shutil
import tempfile
import unittest
from unittest import mock

import torch

from accelerate.test_utils.examples import compare_against_test
from accelerate.test_utils.testing import TempDirTestCase, require_trackers, run_command, slow
from accelerate.utils import write_basic_config


# DataLoaders built from `test_samples/MRPC` for quick testing
# Should mock `{script_name}.get_dataloaders` via:
# @mock.patch("{script_name}.get_dataloaders", mocked_dataloaders)

lowerCamelCase      =		[
    """cross_validation.py""",
    """gradient_accumulation.py""",
    """local_sgd.py""",
    """multi_process_metrics.py""",
    """memory.py""",
    """automatic_gradient_accumulation.py""",
    """fsdp_with_peak_mem_tracking.py""",
    """deepspeed_with_config_support.py""",
    """megatron_lm_gpt_pretraining.py""",
]
class    lowercase__     (					unittest.TestCase   ):







       '''simple docstring'''


       def   lowercase__       (							self    :						str	,       _UpperCAmelCase    :						str	,       _UpperCAmelCase    :						bool	,       _UpperCAmelCase    :						str = None	,       _UpperCAmelCase    :						list = None					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							None
             UpperCAmelCase_    				=							os.path.abspath(os.path.join("examples"	,       "by_feature"					)					)
             UpperCAmelCase_    				=							os.path.abspath("examples"					)
             for item in os.listdir(_UpperCAmelCase					):
                   if item not in EXCLUDE_EXAMPLES:
                         UpperCAmelCase_    				=							os.path.join(_UpperCAmelCase	,       _UpperCAmelCase					)
                         if os.path.isfile(_UpperCAmelCase					) and ".py" in item_path:
                               with self.subTest(
                                   tested_script=_UpperCAmelCase	,       feature_script=_UpperCAmelCase	,       tested_section="main()" if parser_only else "training_function()"	,       ):
                                     UpperCAmelCase_    				=							compare_against_test(
                                         os.path.join(_UpperCAmelCase	,       _UpperCAmelCase					)	,       _UpperCAmelCase	,       _UpperCAmelCase	,       _UpperCAmelCase					)
                                     UpperCAmelCase_    				=							"\n".join(_UpperCAmelCase					)
                                     if special_strings is not None:
                                           for string in special_strings:
                                                 UpperCAmelCase_    				=							diff.replace(_UpperCAmelCase	,       ""					)
                                     self.assertEqual(_UpperCAmelCase	,       ""					)



       def   lowercase__       (							self    :						Union[str, Any]					)				->		Any:


             '''simple docstring'''




             self.one_complete_example("complete_nlp_example.py"	,       _UpperCAmelCase					)
             self.one_complete_example("complete_nlp_example.py"	,       _UpperCAmelCase					)







       def   lowercase__       (							self    :						Optional[Any]					)				->		Dict:


             '''simple docstring'''




             UpperCAmelCase_    				=							os.path.abspath(os.path.join("examples"	,       "cv_example.py"					)					)
             UpperCAmelCase_    				=							[
                 " " * 16 + "{\n\n",
                 " " * 20 + "\"accuracy\": eval_metric[\"accuracy\"],\n\n",
                 " " * 20 + "\"f1\": eval_metric[\"f1\"],\n\n",
                 " " * 20 + "\"train_loss\": total_loss.item() / len(train_dataloader),\n\n",
                 " " * 20 + "\"epoch\": epoch,\n\n",
                 " " * 16 + "},\n\n",
                 " " * 16 + "step=epoch,\n",
                 " " * 12,
                 " " * 8 + "for step, batch in enumerate(active_dataloader):\n",
             ]
             self.one_complete_example("complete_cv_example.py"	,       _UpperCAmelCase	,       _UpperCAmelCase	,       _UpperCAmelCase					)
             self.one_complete_example("complete_cv_example.py"	,       _UpperCAmelCase	,       _UpperCAmelCase	,       _UpperCAmelCase					)



@mock.patch.dict(os.environ       ,      {'''TESTING_MOCKED_DATALOADERS''': '''1'''}   )
class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  False



       @classmethod
       def   lowercase__       (							cls    :						Tuple					)				->		str:


             '''simple docstring'''




             super().setUpClass()
             UpperCAmelCase_    				=							tempfile.mkdtemp()
             UpperCAmelCase_    				=							os.path.join(cls._tmpdir	,       "default_config.yml"					)

             write_basic_config(save_location=cls.configPath					)
             UpperCAmelCase_    				=							["accelerate", "launch", "--config_file", cls.configPath]



       @classmethod
       def   lowercase__       (							cls    :						List[Any]					)				->		Union[str, Any]:


             '''simple docstring'''




             super().tearDownClass()
             shutil.rmtree(cls._tmpdir					)



       def   lowercase__       (							self    :						Tuple					)				->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							F"""
        examples/by_feature/checkpointing.py
        --checkpointing_steps epoch
        --output_dir {self.tmpdir}
        """.split()
             run_command(self._launch_args + testargs					)
             self.assertTrue(os.path.exists(os.path.join(self.tmpdir	,       "epoch_0"					)					)					)



       def   lowercase__       (							self    :						Tuple					)				->		List[str]:


             '''simple docstring'''




             UpperCAmelCase_    				=							F"""
        examples/by_feature/checkpointing.py
        --checkpointing_steps 1
        --output_dir {self.tmpdir}
        """.split()
             UpperCAmelCase_    				=							run_command(self._launch_args + testargs					)
             self.assertTrue(os.path.exists(os.path.join(self.tmpdir	,       "step_2"					)					)					)



       def   lowercase__       (							self    :						Optional[Any]					)				->		Tuple:


             '''simple docstring'''




             UpperCAmelCase_    				=							F"""
        examples/by_feature/checkpointing.py
        --resume_from_checkpoint {os.path.join(self.tmpdir	,       'epoch_0'					)}
        """.split()
             UpperCAmelCase_    				=							run_command(self._launch_args + testargs	,       return_stdout=_UpperCAmelCase					)
             self.assertNotIn("epoch 0:"	,       _UpperCAmelCase					)
             self.assertIn("epoch 1:"	,       _UpperCAmelCase					)



       def   lowercase__       (							self    :						List[Any]					)				->		Optional[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							F"""
        examples/by_feature/checkpointing.py
        --resume_from_checkpoint {os.path.join(self.tmpdir	,       'step_2'					)}
        """.split()
             UpperCAmelCase_    				=							run_command(self._launch_args + testargs	,       return_stdout=_UpperCAmelCase					)
             if torch.cuda.is_available():
                   UpperCAmelCase_    				=							torch.cuda.device_count()
             else:
                   UpperCAmelCase_    				=							1
             if num_processes > 1:
                   self.assertNotIn("epoch 0:"	,       _UpperCAmelCase					)
                   self.assertIn("epoch 1:"	,       _UpperCAmelCase					)
             else:
                   self.assertIn("epoch 0:"	,       _UpperCAmelCase					)
                   self.assertIn("epoch 1:"	,       _UpperCAmelCase					)



       @slow
       def   lowercase__       (							self    :						List[Any]					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							"\n        examples/by_feature/cross_validation.py\n        --num_folds 2\n        ".split()
             with mock.patch.dict(os.environ	,       {"TESTING_MOCKED_DATALOADERS": "0"}					):
                   UpperCAmelCase_    				=							run_command(self._launch_args + testargs	,       return_stdout=_UpperCAmelCase					)
                   UpperCAmelCase_    				=							re.findall("({.+})"	,       _UpperCAmelCase					)
                   UpperCAmelCase_    				=							[r for r in results if "accuracy" in r][-1]
                   UpperCAmelCase_    				=							ast.literal_eval(_UpperCAmelCase					)
                   self.assertGreaterEqual(results["accuracy"]	,       0.75					)



       def   lowercase__       (							self    :						Optional[int]					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							["examples/by_feature/multi_process_metrics.py"]
             run_command(self._launch_args + testargs					)



       @require_trackers
       @mock.patch.dict(os.environ	,       {"WANDB_MODE": "offline"}					)
       def   lowercase__       (							self    :						Optional[Any]					)				->		str:


             '''simple docstring'''




             with tempfile.TemporaryDirectory() as tmpdir:
                   UpperCAmelCase_    				=							F"""
            examples/by_feature/tracking.py
            --with_tracking
            --project_dir {tmpdir}
            """.split()
                   run_command(self._launch_args + testargs					)
                   self.assertTrue(os.path.exists(os.path.join(_UpperCAmelCase	,       "tracking"					)					)					)



       def   lowercase__       (							self    :						Optional[Any]					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							["examples/by_feature/gradient_accumulation.py"]
             run_command(self._launch_args + testargs					)







       def   lowercase__       (							self    :						Optional[Any]					)				->		str:


             '''simple docstring'''




             UpperCAmelCase_    				=							["examples/by_feature/local_sgd.py"]
             run_command(self._launch_args + testargs					)









"""simple docstring"""





import string
def      a__			(   lowerCAmelCase__   ):
      for key in range(len(string.ascii_uppercase   )   ):
            UpperCAmelCase_    				=							""
            for symbol in message:
                  if symbol in string.ascii_uppercase:
                        UpperCAmelCase_    				=							string.ascii_uppercase.find(lowerCAmelCase__   )
                        UpperCAmelCase_    				=							num - key
                        if num < 0:
                              UpperCAmelCase_    				=							num + len(string.ascii_uppercase   )
                        UpperCAmelCase_    				=							translated + string.ascii_uppercase[num]
                  else:
                        UpperCAmelCase_    				=							translated + symbol
            print(f"""Decryption using Key #{key}: {translated}"""   )
def      a__			(   ):
      UpperCAmelCase_    				=							input("Encrypted message: "   )
      UpperCAmelCase_    				=							message.upper()
      decrypt(lowerCAmelCase__   )


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()




