





"""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_							(				_lowercase			,		_lowercase=True			,		_lowercase=True			,		_lowercase=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(_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     :   Optional[int]      =       module.bias is not None
																		_UpperCamelCase     :   Optional[Any]      =       te.Linear(
																		    module.in_features			,		module.out_features			,		bias=_lowercase			,		params_dtype=module.weight.dtype  )
																		_UpperCamelCase     :   Optional[int]      =       module.weight.data.clone()
																		if has_bias:
																								_UpperCamelCase     :   Optional[int]      =       module.bias.data.clone()

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

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

																		setattr(_lowercase			,		_lowercase			,		_lowercase  )
												elif isinstance(_lowercase			,		te.LayerNorm  ) and not to_transformer_engine and _convert_ln:
																		_UpperCamelCase     :   List[str]      =       nn.LayerNorm(module.normalized_shape[0]			,		eps=module.eps			,		params_dtype=module.weight.dtype  )
																		_UpperCamelCase     :   Optional[int]      =       module.weight.data.clone()
																		_UpperCamelCase     :   Optional[int]      =       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 			a_							(				_lowercase  ):
						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 	snake_case__  (						__lowerCamelCase							:       int = 998001      ):
			"""simple docstring"""

			# fetches the next number
			for number in range(n - 1				,						9999				,						-1      ):
						lowerCamelCase__						:						Optional[int]						      =str(__lowerCamelCase      )

						# checks whether 'str_number' is a palindrome.
						if str_number == str_number[::-1]:
									lowerCamelCase__						:						Optional[int]						      =999

									# if 'number' is a product of two 3-digit numbers
									# then number is the answer otherwise fetch next number.
									while divisor != 99:
												if (number % divisor == 0) and (len(str(number // divisor      )      ) == 3.0):
															return number
												divisor -= 1
			raise ValueError('''That number is larger than our acceptable range.'''      )


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




