



from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
       import accelerate

def   _lowerCAmelCase   (						A__	):
      if not is_accelerate_available():
            return method
      lowercase__     =  version.parse(accelerate.__version__	).base_version
      if version.parse(A__	) < version.parse('0.17.0'	):
            return method

      def wrapper(self						,  *A__						,  **A__	):
            if hasattr(self						,  '_hf_hook'	) and hasattr(self._hf_hook						,  'pre_forward'	):
                  self._hf_hook.pre_forward(self	)
            return method(self						,  *A__						,  **A__	)

      return wrapper





from __future__ import annotations

def   _lowerCAmelCase   (						A__						,  A__	):
      if b == 0:
            return (1, 0)
      ((lowercase__),	(lowercase__))     =  extended_euclid(A__						,  a % b	)
      lowercase__     =  a // b
      return (y, x - k * y)

def   _lowerCAmelCase   (						A__						,  A__						,  A__						,  A__	):
      ((lowercase__),	(lowercase__))     =  extended_euclid(A__						,  A__	)
      lowercase__     =  na * na
      lowercase__     =  ra * x * na + ra * y * na
      return (n % m + m) % m

def   _lowerCAmelCase   (						A__						,  A__	):
      ((lowercase__),	(lowercase__))     =  extended_euclid(A__						,  A__	)
      if b < 0:
            lowercase__     =  (b % n + n) % n
      return b

def   _lowerCAmelCase   (						A__						,  A__						,  A__						,  A__	):
      lowercase__,	lowercase__     =  invert_modulo(A__						,  A__	), invert_modulo(A__						,  A__	)
      lowercase__     =  na * na
      lowercase__     =  ra * x * na + ra * y * na
      return (n % m + m) % m


if __name__ == "__main__":
       from doctest import testmod

       testmod(name="chinese_remainder_theorem", verbose=True)
       testmod(name="chinese_remainder_theorem2", verbose=True)
       testmod(name="invert_modulo", verbose=True)
       testmod(name="extended_euclid", verbose=True)
