






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       ):
   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
         lowercase__    :						str       =			module.bias is not None
         lowercase__    :						List[str]       =			te.Linear(
             module.in_features		,					module.out_features		,					bias=A		,					params_dtype=module.weight.dtype       )
         lowercase__    :						Union[str, Any]       =			module.weight.data.clone()
         if has_bias:
            lowercase__    :						Union[str, Any]       =			module.bias.data.clone()

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

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

         setattr(A		,					A		,					A       )
      elif isinstance(A		,					te.LayerNorm       ) and not to_transformer_engine and _convert_ln:
         lowercase__    :						Optional[int]       =			nn.LayerNorm(module.normalized_shape[0]		,					eps=module.eps		,					params_dtype=module.weight.dtype       )
         lowercase__    :						Tuple       =			module.weight.data.clone()
         lowercase__    :						Optional[Any]       =			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       ):
   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










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
    is_vision_available,
)


a 			=							{
    'configuration_mobilevitv2': [
        'MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'MobileViTV2Config',
        'MobileViTV2OnnxConfig',
    ],
}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a 			=							[
     'MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST',
     'MobileViTV2ForImageClassification',
     'MobileViTV2ForSemanticSegmentation',
     'MobileViTV2Model',
     'MobileViTV2PreTrainedModel',
 ]

if TYPE_CHECKING:
 from .configuration_mobilevitva import (
     MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
     MobileViTVaConfig,
     MobileViTVaOnnxConfig,
 )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_mobilevitva import (
      MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
      MobileViTVaForImageClassification,
      MobileViTVaForSemanticSegmentation,
      MobileViTVaModel,
      MobileViTVaPreTrainedModel,
  )

else:
 import sys

 a 			=							_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


