



"""simple docstring"""


import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
				import transformer_engine.pytorch as te

def 				_lowerCAmelCase   (     lowercase_	,			lowercase_=True	,			lowercase_=True	,			lowercase_=True		):
						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(lowercase_	,			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
																		UpperCAmelCase    =				module.bias is not None
																		UpperCAmelCase    =				te.Linear(
																		    module.in_features	,			module.out_features	,			bias=lowercase_	,			params_dtype=module.weight.dtype		)
																		UpperCAmelCase    =				module.weight.data.clone()
																		if has_bias:
																								UpperCAmelCase    =				module.bias.data.clone()

																		setattr(lowercase_	,			lowercase_	,			lowercase_		)
												elif isinstance(lowercase_	,			nn.LayerNorm		) and to_transformer_engine and _convert_ln:
																		UpperCAmelCase    =				te.LayerNorm(module.normalized_shape[0]	,			eps=module.eps	,			params_dtype=module.weight.dtype		)
																		UpperCAmelCase    =				module.weight.data.clone()
																		UpperCAmelCase    =				module.bias.data.clone()

																		setattr(lowercase_	,			lowercase_	,			lowercase_		)
												elif isinstance(lowercase_	,			te.Linear		) and not to_transformer_engine and _convert_linear:
																		UpperCAmelCase    =				module.bias is not None
																		UpperCAmelCase    =				nn.Linear(
																		    module.in_features	,			module.out_features	,			bias=lowercase_	,			params_dtype=module.weight.dtype		)
																		UpperCAmelCase    =				module.weight.data.clone()
																		if has_bias:
																								UpperCAmelCase    =				module.bias.data.clone()

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

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






def 				_lowerCAmelCase   (     lowercase_		):
						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(lowercase_	,			(te.LayerNorm, te.Linear)		):
																		return True
						return False










"""simple docstring"""


from math import exp

def 				_lowerCAmelCase   (     lowercase_		):
						return 8 * x - 2 * exp(-x		)

def 				_lowerCAmelCase   (     lowercase_	,			lowercase_	,			lowercase_		):
						UpperCAmelCase    =				lower_bound
						UpperCAmelCase    =				upper_bound
						for _ in range(0	,			lowercase_		):
												UpperCAmelCase   ,					UpperCAmelCase    =				xa, xa - (f(lowercase_		) * (xa - xa)) / (f(lowercase_		) - f(lowercase_		))
						return xa


if __name__ == "__main__":
				print(f'''Example: {secant_method(1, 3, 2)}''')





