






'''simple docstring'''






import operator




def        _SCREAMING_SNAKE_CASE  (				A  :       list  ,		A  :       bool = False  ,		A  :       list | None = None  )    -> List[Any]:







   """simple docstring"""
   __snake_case				:      List[str]     							= operator.lt if reverse else operator.gt
   __snake_case				:      str     							= solution or []

   if not arr:
      return solution

   __snake_case				:      Union[str, Any]     							= [arr.pop(0  )]
   for i, item in enumerate(A  ):
      if _operator(A  ,		sublist[-1]  ):
         sublist.append(A  )
         arr.pop(A  )

    #  merging sublist into solution list
   if not solution:
      solution.extend(A  )
   else:
      while sublist:
         __snake_case				:      Any     							= sublist.pop(0  )
         for i, xx in enumerate(A  ):
            if not _operator(A  ,		A  ):
               solution.insert(A  ,		A  )
               break
         else:
            solution.append(A  )

   strand_sort(A  ,		A  ,		A  )
   return solution


if __name__ == "__main__":
      assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
      assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]







'''simple docstring'''






from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
      import accelerate




def        _SCREAMING_SNAKE_CASE  (				A  :       Optional[Any]  )    -> int:







   """simple docstring"""
   if not is_accelerate_available():
      return method
   __snake_case				:      Optional[Any]     							= version.parse(accelerate.__version__  ).base_version
   if version.parse(A  ) < version.parse('0.17.0'  ):
      return method

   def wrapper(self  :       Optional[Any]  ,		*A  :       Optional[Any]  ,		**A  :       Optional[int]  ):
      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