


'''simple docstring'''

import functools
import gc
import inspect

import torch

from .imports import is_npu_available, is_xpu_available






def __UpperCamelCase   (			*__lowerCamelCase		: int				)      ->     Optional[Any]:







     '''simple docstring'''






     if not isinstance(__lowerCamelCase      ,  __lowerCamelCase				):
          _a						=		list(__lowerCamelCase				)
     for i in range(len(__lowerCamelCase				)				):
          _a						=		None
     gc.collect()
     if is_xpu_available():
          torch.xpu.empty_cache()
     elif is_npu_available():
          torch.npu.empty_cache()
     else:
          torch.cuda.empty_cache()
     return objects






def __UpperCamelCase   (			__lowerCamelCase		: Exception				)      ->     bool:







     '''simple docstring'''






     _a						=		[
         "CUDA out of memory.",  # CUDA OOM
         "cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.",  # CUDNN SNAFU
         "DefaultCPUAllocator: can't allocate memory",  # CPU OOM
     ]
     if isinstance(__lowerCamelCase      ,  __lowerCamelCase				) and len(exception.args				) == 1:
          return any(err in exception.args[0] for err in _statements				)
     return False






def __UpperCamelCase   (			__lowerCamelCase		: callable = None      ,  __lowerCamelCase		: int = 128				)      ->     Dict:







     '''simple docstring'''






     if function is None:
          return functools.partial(__lowerCamelCase      ,  starting_batch_size=__lowerCamelCase				)

     _a						=		starting_batch_size

     def decorator(*__lowerCamelCase		: Union[str, Any]      ,  **__lowerCamelCase		: Optional[int]				):
          nonlocal batch_size
          gc.collect()
          if is_xpu_available():
               torch.xpu.empty_cache()
          elif is_npu_available():
               torch.npu.empty_cache()
          else:
               torch.cuda.empty_cache()
          _a						=		list(inspect.signature(__lowerCamelCase				).parameters.keys()				)
          # Guard against user error
          if len(__lowerCamelCase				) < (len(__lowerCamelCase				) + 1):
               _a						=		", ".join([F"{arg}={value}" for arg, value in zip(params[1:]      ,  args[1:]				)]				)
               raise TypeError(
                   F"Batch size was passed into `{function.__name__}` as the first argument when called."
                   F"Remove this as the decorator already does so: `{function.__name__}({arg_str})`"				)
          while True:
               if batch_size == 0:
                    raise RuntimeError("No executable batch size found, reached zero."				)
               try:
                    return function(__lowerCamelCase      ,  *__lowerCamelCase      ,  **__lowerCamelCase				)
               except Exception as e:
                    if should_reduce_batch_size(__lowerCamelCase				):
                         gc.collect()
                         if is_xpu_available():
                              torch.xpu.empty_cache()
                         elif is_npu_available():
                              torch.npu.empty_cache()
                         else:
                              torch.cuda.empty_cache()
                         batch_size //= 2
                    else:
                         raise

     return decorator





'''simple docstring'''

def __UpperCamelCase   (			__lowerCamelCase		: int = 400_0000				)      ->     int:







     '''simple docstring'''






     _a						=		[]
     _a			,			_a						=		0, 1
     while b <= n:
          if b % 2 == 0:
               even_fibs.append(__lowerCamelCase				)
          _a			,			_a						=		b, a + b
     return sum(__lowerCamelCase				)


if __name__ == "__main__":
   print(f'''{solution() = }''')

