
from transformers import HfArgumentParser, PyTorchBenchmark, PyTorchBenchmarkArguments

def a__   (	):






  '''simple docstring'''





  __magic_name__    					=	HfArgumentParser(A_ )
  try:
    __magic_name__    					=	parser.parse_args_into_dataclasses()[0]
  except ValueError as e:
    __magic_name__    					=	"""Arg --no_{0} is no longer used, please use --no-{0} instead."""
    __magic_name__    					=	""" """.join(str(A_ ).split(""" """ )[:-1] )
    __magic_name__    					=	""""""
    __magic_name__    					=	eval(str(A_ ).split(""" """ )[-1] )
    __magic_name__    					=	[]
    for arg in depreciated_args:
      # arg[2:] removes '--'
      if arg[2:] in PyTorchBenchmarkArguments.deprecated_args:
        # arg[5:] removes '--no_'
        full_error_msg += arg_error_msg.format(arg[5:] )
      else:
        wrong_args.append(A_ )
    if len(A_ ) > 0:
      __magic_name__    					=	full_error_msg + begin_error_msg + str(A_ )
    raise ValueError(A_ )

  __magic_name__    					=	PyTorchBenchmark(args=A_ )
  benchmark.run()


if __name__ == "__main__":
    main()



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

