


def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:Any					)							->	bool:
						if not isinstance(lowerCAmelCase_   ,    lowerCAmelCase_					):
												raise ValueError('Input series is not valid, valid series - [1, 2/3, 2]'					)
						if len(lowerCAmelCase_					) == 0:
												raise ValueError('Input list must be a non empty list'					)
						if len(lowerCAmelCase_					) == 1 and series[0] != 0:
												return True
						__magic_name__					:				Optional[int]				=   []
						__magic_name__					:				Union[str, Any]				=   len(lowerCAmelCase_					)
						for i in range(0   ,    lowerCAmelCase_					):
												if series[i] == 0:
																		raise ValueError('Input series cannot have 0 as an element'					)
												rec_series.append(1 / series[i]					)
						__magic_name__					:				Optional[int]				=   rec_series[1] - rec_series[0]
						for index in range(2   ,    lowerCAmelCase_					):
												if rec_series[index] - rec_series[index - 1] != common_diff:
																		return False
						return True
def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:Union[str, Any]					)							->	float:
						if not isinstance(lowerCAmelCase_   ,    lowerCAmelCase_					):
												raise ValueError('Input series is not valid, valid series - [2, 4, 6]'					)
						if len(lowerCAmelCase_					) == 0:
												raise ValueError('Input list must be a non empty list'					)
						__magic_name__					:				Tuple				=   0
						for val in series:
												answer += 1 / val
						return len(lowerCAmelCase_					) / answer


if __name__ == "__main__":
			import doctest

			doctest.testmod()






import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
						import transformer_engine.pytorch as te



def       lowerCAmelCase			(		lowerCAmelCase_			, lowerCAmelCase_=True			, lowerCAmelCase_=True			, lowerCAmelCase_=True			)->			Union[str, Any]:
				if not is_fpa_available():
								raise ImportError('''Using `convert_model` requires transformer_engine to be installed.'''			)
				for name, module in model.named_children():
								if isinstance(lowerCAmelCase_			, nn.Linear			) and to_transformer_engine and _convert_linear:
												# Return early if the linear layer weights are not multiples of 16
												if any(p % 16 != 0 for p in module.weight.shape			):
																return
												lowerCAmelCase_			:   Optional[int]     					=					module.bias is not None
												lowerCAmelCase_			:   Any     					=					te.Linear(
												    module.in_features			, module.out_features			, bias=lowerCAmelCase_			, params_dtype=module.weight.dtype			)
												lowerCAmelCase_			:   Dict     					=					module.weight.data.clone()
												if has_bias:
																lowerCAmelCase_			:   Any     					=					module.bias.data.clone()

												setattr(lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)
								elif isinstance(lowerCAmelCase_			, nn.LayerNorm			) and to_transformer_engine and _convert_ln:
												lowerCAmelCase_			:   List[str]     					=					te.LayerNorm(module.normalized_shape[0]			, eps=module.eps			, params_dtype=module.weight.dtype			)
												lowerCAmelCase_			:   Union[str, Any]     					=					module.weight.data.clone()
												lowerCAmelCase_			:   List[Any]     					=					module.bias.data.clone()

												setattr(lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)
								elif isinstance(lowerCAmelCase_			, te.Linear			) and not to_transformer_engine and _convert_linear:
												lowerCAmelCase_			:   Dict     					=					module.bias is not None
												lowerCAmelCase_			:   Union[str, Any]     					=					nn.Linear(
												    module.in_features			, module.out_features			, bias=lowerCAmelCase_			, params_dtype=module.weight.dtype			)
												lowerCAmelCase_			:   Optional[Any]     					=					module.weight.data.clone()
												if has_bias:
																lowerCAmelCase_			:   Union[str, Any]     					=					module.bias.data.clone()

												setattr(lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)
								elif isinstance(lowerCAmelCase_			, te.LayerNorm			) and not to_transformer_engine and _convert_ln:
												lowerCAmelCase_			:   Union[str, Any]     					=					nn.LayerNorm(module.normalized_shape[0]			, eps=module.eps			, params_dtype=module.weight.dtype			)
												lowerCAmelCase_			:   List[str]     					=					module.weight.data.clone()
												lowerCAmelCase_			:   List[Any]     					=					module.bias.data.clone()

												setattr(lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)
								else:
												convert_model(
												    lowerCAmelCase_			, to_transformer_engine=lowerCAmelCase_			, _convert_linear=_convert_linear			, _convert_ln=_convert_ln			, )




def       lowerCAmelCase			(		lowerCAmelCase_			)->			str:
				if not is_fpa_available():
								raise ImportError('''Using `has_transformer_engine_layers` requires transformer_engine to be installed.'''			)
				for m in model.modules():
								if isinstance(lowerCAmelCase_			, (te.LayerNorm, te.Linear)			):
												return True
				return False