


from __future__ import annotations

import sys
def     UpperCAmelCase__		(UpperCamelCase_							,UpperCamelCase_       ):



     """simple docstring"""






     if abs(UpperCamelCase_       ) == 1:
          return a, 0
     elif abs(UpperCamelCase_       ) == 1:
          return 0, b

     snake_case				,						snake_case					=       a, b
     snake_case				,						snake_case					=       1, 0
     snake_case				,						snake_case					=       0, 1

     while remainder != 0:
          snake_case					=       old_remainder // remainder
          snake_case				,						snake_case					=       remainder, old_remainder - quotient * remainder
          snake_case				,						snake_case					=       coeff_a, old_coeff_a - quotient * coeff_a
          snake_case				,						snake_case					=       coeff_b, old_coeff_b - quotient * coeff_b

     # sign correction for negative numbers
     if a < 0:
          snake_case					=       -old_coeff_a
     if b < 0:
          snake_case					=       -old_coeff_b

     return old_coeff_a, old_coeff_b
def     UpperCAmelCase__		():



     """simple docstring"""






     if len(sys.argv       ) < 3:
          print('''2 integer arguments required'''       )
          return 1
     snake_case					=       int(sys.argv[1]       )
     snake_case					=       int(sys.argv[2]       )
     print(extended_euclidean_algorithm(UpperCamelCase_							,UpperCamelCase_       )       )
     return 0


if __name__ == "__main__":
 raise SystemExit(main())







import torch

from accelerate import Accelerator, DistributedType

class 						A__      :







    """simple docstring"""

    def __enter__( self					):
         if self.enabled:
              snake_case					=       self.model.no_sync()
              self.model_sync_obj.__enter__()

         return self
    def __exit__( self    ,      __snake_case    ,      __snake_case    ,      __snake_case					):
         if self.enabled:
              # Average all models on exit
              self._sync_and_avg_model_params()
              self.model_sync_obj.__exit__(__snake_case    ,      __snake_case    ,      __snake_case					)
    def __init__( self    ,      __snake_case    ,      __snake_case    ,      __snake_case    ,      __snake_case = True					):
         if accelerator.distributed_type not in [
             DistributedType.NO,
             DistributedType.MULTI_CPU,
             DistributedType.MULTI_GPU,
         ]:
              raise NotImplementedError('''LocalSGD is supported only for CPUs and GPUs (no DeepSpeed or MegatronLM)'''					)
         snake_case					=       enabled and accelerator.distributed_type != DistributedType.NO
         snake_case					=       0
         if self.enabled:
              snake_case					=       accelerator
              snake_case					=       model
              snake_case					=       local_sgd_steps
    def 	a_    ( self					):
         self.num_steps += 1
         if not self.enabled:
              return

         if self.num_steps % self.local_sgd_steps == 0:
              self._sync_and_avg_model_params()




    def 	a_    ( self					):
         self.accelerator.wait_for_everyone()
         with self.accelerator.autocast():
              for param in self.model.parameters():
                   snake_case					=       self.accelerator.reduce(param.data    ,      reduction='''mean'''					)




