


def       lowerCAmelCase			(		lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)->			list[int]:
				if hue < 0 or hue > 360:
								raise Exception('''hue should be between 0 and 360'''			)

				if saturation < 0 or saturation > 1:
								raise Exception('''saturation should be between 0 and 1'''			)

				if value < 0 or value > 1:
								raise Exception('''value should be between 0 and 1'''			)

				lowerCAmelCase_			:   Tuple     					=					value * saturation
				lowerCAmelCase_			:   int     					=					hue / 60
				lowerCAmelCase_			:   Optional[int]     					=					chroma * (1 - abs(hue_section % 2 - 1			))
				lowerCAmelCase_			:   Union[str, Any]     					=					value - chroma

				if hue_section >= 0 and hue_section <= 1:
								lowerCAmelCase_			:   Any     					=					round(255 * (chroma + match_value)			)
								lowerCAmelCase_			:   Optional[Any]     					=					round(255 * (second_largest_component + match_value)			)
								lowerCAmelCase_			:   Optional[Any]     					=					round(255 * (match_value)			)
				elif hue_section > 1 and hue_section <= 2:
								lowerCAmelCase_			:   Dict     					=					round(255 * (second_largest_component + match_value)			)
								lowerCAmelCase_			:   Optional[int]     					=					round(255 * (chroma + match_value)			)
								lowerCAmelCase_			:   int     					=					round(255 * (match_value)			)
				elif hue_section > 2 and hue_section <= 3:
								lowerCAmelCase_			:   Dict     					=					round(255 * (match_value)			)
								lowerCAmelCase_			:   str     					=					round(255 * (chroma + match_value)			)
								lowerCAmelCase_			:   Dict     					=					round(255 * (second_largest_component + match_value)			)
				elif hue_section > 3 and hue_section <= 4:
								lowerCAmelCase_			:   Any     					=					round(255 * (match_value)			)
								lowerCAmelCase_			:   Any     					=					round(255 * (second_largest_component + match_value)			)
								lowerCAmelCase_			:   Tuple     					=					round(255 * (chroma + match_value)			)
				elif hue_section > 4 and hue_section <= 5:
								lowerCAmelCase_			:   Optional[int]     					=					round(255 * (second_largest_component + match_value)			)
								lowerCAmelCase_			:   List[str]     					=					round(255 * (match_value)			)
								lowerCAmelCase_			:   Dict     					=					round(255 * (chroma + match_value)			)
				else:
								lowerCAmelCase_			:   Union[str, Any]     					=					round(255 * (chroma + match_value)			)
								lowerCAmelCase_			:   Any     					=					round(255 * (match_value)			)
								lowerCAmelCase_			:   Union[str, Any]     					=					round(255 * (second_largest_component + match_value)			)

				return [red, green, blue]



def       lowerCAmelCase			(		lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)->			list[float]:
				if red < 0 or red > 255:
								raise Exception('''red should be between 0 and 255'''			)

				if green < 0 or green > 255:
								raise Exception('''green should be between 0 and 255'''			)

				if blue < 0 or blue > 255:
								raise Exception('''blue should be between 0 and 255'''			)

				lowerCAmelCase_			:   Optional[Any]     					=					red / 255
				lowerCAmelCase_			:   str     					=					green / 255
				lowerCAmelCase_			:   List[Any]     					=					blue / 255
				lowerCAmelCase_			:   Any     					=					max(lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)
				lowerCAmelCase_			:   Any     					=					value - min(lowerCAmelCase_			, lowerCAmelCase_			, lowerCAmelCase_			)
				lowerCAmelCase_			:   Optional[int]     					=					0 if value == 0 else chroma / value

				if chroma == 0:
								lowerCAmelCase_			:   List[str]     					=					0.0
				elif value == float_red:
								lowerCAmelCase_			:   List[str]     					=					60 * (0 + (float_green - float_blue) / chroma)
				elif value == float_green:
								lowerCAmelCase_			:   Union[str, Any]     					=					60 * (2 + (float_blue - float_red) / chroma)
				else:
								lowerCAmelCase_			:   Tuple     					=					60 * (4 + (float_red - float_green) / chroma)

				lowerCAmelCase_			:   Optional[Any]     					=					(hue + 360) % 360

				return [hue, saturation, value]




def       lowerCAmelCase			(		lowerCAmelCase_			, lowerCAmelCase_			)->			bool:
				lowerCAmelCase_			:   Any     					=					abs(hsv_a[0] - hsv_a[0]			) < 0.2
				lowerCAmelCase_			:   Any     					=					abs(hsv_a[1] - hsv_a[1]			) < 0.002
				lowerCAmelCase_			:   str     					=					abs(hsv_a[2] - hsv_a[2]			) < 0.002

				return check_hue and check_saturation and check_value



import torch.nn as nn

from .imports import is_fpa_available


if is_fpa_available():
						import transformer_engine.pytorch as te



def       lowerCAmelCase			(		lowerCAmelCase_			, lowerCAmelCase_=True			, lowerCAmelCase_=True			, lowerCAmelCase_=True			)->			Union[str, Any]:
				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(lowerCAmelCase_			, 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
												lowerCAmelCase_			:   Optional[int]     					=					module.bias is not None
												lowerCAmelCase_			:   Any     					=					te.Linear(
												    module.in_features			, module.out_features			, bias=lowerCAmelCase_			, params_dtype=module.weight.dtype			)
												lowerCAmelCase_			:   Dict     					=					module.weight.data.clone()
												if has_bias:
																lowerCAmelCase_			:   Any     					=					module.bias.data.clone()

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

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

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

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




def       lowerCAmelCase			(		lowerCAmelCase_			)->			str:
				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(lowerCAmelCase_			, (te.LayerNorm, te.Linear)			):
												return True
				return False