
__lowerCAmelCase      :					Optional[Any]   	=       1000

def a__   (	A_ ):






  '''simple docstring'''





  return x * x

def a__   (	A_,					A_,					A_,					A_ = 4 ):






  '''simple docstring'''





  assert callable(
      A_ ), f'''the function(object) passed should be callable your input : {function}'''
  assert isinstance(A_,					(float, int) ), f'''a should be float or integer your input : {a}'''
  assert isinstance(function(A_ ),					(float, int) ), (
      "the function should return integer or float return type of your function, "
      f'''{type(A_ )}'''
  )
  assert isinstance(A_,					(float, int) ), f'''b should be float or integer your input : {b}'''
  assert (
      isinstance(A_,					A_ ) and precision > 0
  ), f'''precision should be positive integer your input : {precision}'''

  # just applying the formula of simpson for approximate integration written in
  # mentioned article in first comment of this file and above this function

  __magic_name__    					=	(b - a) / N_STEPS
  __magic_name__    					=	function(A_ ) + function(A_ )

  for i in range(1,					A_ ):
    __magic_name__    					=	a + h * i
    result += function(A_ ) * (4 if i % 2 else 2)

  result *= h / 3
  return round(A_,					A_ )


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 a__   (	A_,					A_=True,					A_=True,					A_=True ):






  '''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(A_,					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
      __magic_name__    					=	module.bias is not None
      __magic_name__    					=	te.Linear(
          module.in_features,					module.out_features,					bias=A_,					params_dtype=module.weight.dtype )
      __magic_name__    					=	module.weight.data.clone()
      if has_bias:
        __magic_name__    					=	module.bias.data.clone()

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

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

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

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





def a__   (	A_ ):






  '''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(A_,					(te.LayerNorm, te.Linear) ):
      return True
  return False

