





"""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'''

import warnings

from ...utils import logging
from .image_processing_levit import LevitImageProcessor


a__         =     logging.get_logger(__name__)





class __magic_name__(						__lowerCAmelCase      ):






						def __init__(   self						:						Optional[Any]					,   *__UpperCamelCase						:						Union[str, Any]					,   **__UpperCamelCase						:						Dict       ):



									'''simple docstring'''






									warnings.warn(
									    """The class LevitFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"""
									    """ use LevitImageProcessor instead."""					,   __UpperCamelCase					,   )
									super().__init__(*__UpperCamelCase					,   **__UpperCamelCase       )