
"""simple docstring"""





import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
    import transformer_engine.pytorch as te







def       __a	(						__lowerCamelCase,						__lowerCamelCase=True,						__lowerCamelCase=True,						__lowerCamelCase=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(__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
         UpperCAmelCase_   :   List[str]     	=       module.bias is not None
         UpperCAmelCase_   :   int     	=       te.Linear(
             module.in_features,						module.out_features,						bias=__lowerCamelCase,						params_dtype=module.weight.dtype    )
         UpperCAmelCase_   :   Dict     	=       module.weight.data.clone()
         if has_bias:
            UpperCAmelCase_   :   Dict     	=       module.bias.data.clone()

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

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

         setattr(__lowerCamelCase,						__lowerCamelCase,						__lowerCamelCase    )
      elif isinstance(__lowerCamelCase,						te.LayerNorm    ) and not to_transformer_engine and _convert_ln:
         UpperCAmelCase_   :   Tuple     	=       nn.LayerNorm(module.normalized_shape[0],						eps=module.eps,						params_dtype=module.weight.dtype    )
         UpperCAmelCase_   :   Optional[Any]     	=       module.weight.data.clone()
         UpperCAmelCase_   :   Dict     	=       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       __a	(						__lowerCamelCase    ):
   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




"""simple docstring"""





from math import exp







def       __a	(						__lowerCamelCase    ):
   return 8 * x - 2 * exp(-x    )







def       __a	(						__lowerCamelCase,						__lowerCamelCase,						__lowerCamelCase    ):
   UpperCAmelCase_   :   Any     	=       lower_bound
   UpperCAmelCase_   :   int     	=       upper_bound
   for _ in range(0,						__lowerCamelCase    ):
      UpperCAmelCase_	,  UpperCAmelCase_   :   Optional[Any]     	=       xa, xa - (f(__lowerCamelCase    ) * (xa - xa)) / (f(__lowerCamelCase    ) - f(__lowerCamelCase    ))
   return xa


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


