


'''simple docstring'''


import os
import socket
from contextlib import contextmanager

import torch

from ..commands.config.default import write_basic_config  # noqa: F401
from ..state import PartialState
from .dataclasses import DistributedType
from .imports import is_deepspeed_available, is_tpu_available
from .transformer_engine import convert_model
from .versions import is_torch_version


if is_deepspeed_available():
						from deepspeed import DeepSpeedEngine

if is_tpu_available(check_device=False):
						import torch_xla.core.xla_model as xm






def  __lowerCAmelCase (__lowerCAmelCase   ):
		if is_torch_version("<"      , "2.0.0"   ) or not hasattr(__lowerCAmelCase      , "_dynamo"   ):
				return False
		return isinstance(__lowerCAmelCase      , torch._dynamo.eval_frame.OptimizedModule   )






def  __lowerCAmelCase (__lowerCAmelCase      , __lowerCAmelCase = True   ):
		_UpperCAmelCase		:       Any								=      (torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

		_UpperCAmelCase		:       Optional[Any]								=      is_compiled_module(__lowerCAmelCase   )
		if is_compiled:
				_UpperCAmelCase		:       Optional[Any]								=      model
				_UpperCAmelCase		:       Tuple								=      model._orig_mod

		if is_deepspeed_available():
				options += (DeepSpeedEngine,)

		while isinstance(__lowerCAmelCase      , __lowerCAmelCase   ):
				_UpperCAmelCase		:       List[Any]								=      model.module

		if not keep_fpaa_wrapper:
				_UpperCAmelCase		:       Tuple								=      getattr(__lowerCAmelCase      , "forward"   )
				_UpperCAmelCase		:       Tuple								=      model.__dict__.pop("_original_forward"      , __lowerCAmelCase   )
				if original_forward is not None:
						while hasattr(__lowerCAmelCase      , "__wrapped__"   ):
								_UpperCAmelCase		:       List[Any]								=      forward.__wrapped__
								if forward == original_forward:
										break
						_UpperCAmelCase		:       Optional[Any]								=      forward
				if getattr(__lowerCAmelCase      , "_converted_to_transformer_engine"      , __lowerCAmelCase   ):
						convert_model(__lowerCAmelCase      , to_transformer_engine=__lowerCAmelCase   )

		if is_compiled:
				_UpperCAmelCase		:       str								=      model
				_UpperCAmelCase		:       Optional[Any]								=      compiled_model

		return model






def  __lowerCAmelCase ():
		PartialState().wait_for_everyone()






def  __lowerCAmelCase (__lowerCAmelCase      , __lowerCAmelCase   ):
		if PartialState().distributed_type == DistributedType.TPU:
				xm.save(__lowerCAmelCase      , __lowerCAmelCase   )
		elif PartialState().local_process_index == 0:
				torch.save(__lowerCAmelCase      , __lowerCAmelCase   )






@contextmanager
def  __lowerCAmelCase (**__lowerCAmelCase   ):
		for key, value in kwargs.items():
				_UpperCAmelCase		:       int								=      str(__lowerCAmelCase   )

		yield

		for key in kwargs:
				if key.upper() in os.environ:
						del os.environ[key.upper()]






def  __lowerCAmelCase (__lowerCAmelCase   ):
		if not hasattr(__lowerCAmelCase      , "__qualname__"   ) and not hasattr(__lowerCAmelCase      , "__name__"   ):
				_UpperCAmelCase		:       Dict								=      getattr(__lowerCAmelCase      , "__class__"      , __lowerCAmelCase   )
		if hasattr(__lowerCAmelCase      , "__qualname__"   ):
				return obj.__qualname__
		if hasattr(__lowerCAmelCase      , "__name__"   ):
				return obj.__name__
		return str(__lowerCAmelCase   )






def  __lowerCAmelCase (__lowerCAmelCase      , __lowerCAmelCase   ):
		for key, value in source.items():
				if isinstance(__lowerCAmelCase      , __lowerCAmelCase   ):
						_UpperCAmelCase		:       Union[str, Any]								=      destination.setdefault(__lowerCAmelCase      , {}   )
						merge_dicts(__lowerCAmelCase      , __lowerCAmelCase   )
				else:
						_UpperCAmelCase		:       str								=      value

		return destination






def  __lowerCAmelCase (__lowerCAmelCase = None   ):
		if port is None:
				_UpperCAmelCase		:       Union[str, Any]								=      29_500
		with socket.socket(socket.AF_INET      , socket.SOCK_STREAM   ) as s:
				return s.connect_ex(("localhost", port)   ) == 0







'''simple docstring'''


def  __lowerCAmelCase ():
		_UpperCAmelCase		:       str								=      0
		for i in range(1      , 1_001   ):
				total += i**i
		return str(__lowerCAmelCase   )[-10:]


if __name__ == "__main__":
						print(solution())



