





'''simple docstring'''
import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
    import transformer_engine.pytorch as te
def     lowercase__       (       __lowercase						:  str    ,  __lowercase						:  str=True    ,  __lowercase						:  Tuple=True    ,  __lowercase						:  Union[str, Any]=True					)			->				List[str]:



       """simple docstring"""






       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     lowercase__       (       __lowercase						:  int					)			->				int:



       """simple docstring"""






       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'''
def     lowercase__       (       __lowercase						:  int = 20					)			->				int:



       """simple docstring"""






       try:
              __UpperCamelCase	=  int(__lowercase					)
       except (TypeError, ValueError):
              raise TypeError('Parameter n must be int or castable to int.'					)
       if n <= 0:
              raise ValueError('Parameter n must be greater than or equal to one.'					)
       __UpperCamelCase	=  0
       while 1:
              i += n * (n - 1)
              __UpperCamelCase	=  0
              for j in range(2    ,  __lowercase					):
                     if i % j != 0:
                            __UpperCamelCase	=  1
                            break
              if nfound == 0:
                     if i == 0:
                            __UpperCamelCase	=  1
                     return i
       return None


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