
"""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__ (		__magic_name__ ,      __magic_name__=True ,      __magic_name__=True ,      __magic_name__=True			)	->Dict:
			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(__magic_name__ ,      nn.Linear			) and to_transformer_engine and _convert_linear:
									# Return early if the linear layer weights are not multiples of 16
									if any(p % 1_6 != 0 for p in module.weight.shape			):
												return
									__lowercase						      =					module.bias is not None
									__lowercase						      =					te.Linear(
									    module.in_features ,      module.out_features ,      bias=__magic_name__ ,      params_dtype=module.weight.dtype			)
									__lowercase						      =					module.weight.data.clone()
									if has_bias:
												__lowercase						      =					module.bias.data.clone()

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

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

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

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







def     lowerCAmelCase__ (		__magic_name__			)	->Union[str, Any]:
			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(__magic_name__ ,      (te.LayerNorm, te.Linear)			):
									return True
			return False







"""simple docstring"""






def     lowerCAmelCase__ (		__magic_name__ ,      __magic_name__			)	->list:
			__lowercase						      =					len(__magic_name__			)
			__lowercase						      =					len(__magic_name__			)
			__lowercase						      =					(
			    first_input_list_length
			    if first_input_list_length > second_input_list_length
			    else second_input_list_length
			)
			__lowercase						      =					[]
			for char_count in range(__magic_name__			):
						if char_count < first_input_list_length:
									output_result_list.append(first_input_list[char_count]			)
						if char_count < second_input_list_length:
									output_result_list.append(second_input_list[char_count]			)

			return output_result_list


if __name__ == "__main__":
					print(alternative_list_arrange(['''A''', '''B''', '''C'''], [1, 2, 3, 4, 5]), end=''' ''')





