
"""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	(						__lowerCamelCase,						__lowerCamelCase=True,						__lowerCamelCase=True,						__lowerCamelCase=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(__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
         UpperCAmelCase_   :   List[str]     	=       module.bias is not None
         UpperCAmelCase_   :   int     	=       te.Linear(
             module.in_features,						module.out_features,						bias=__lowerCamelCase,						params_dtype=module.weight.dtype    )
         UpperCAmelCase_   :   Dict     	=       module.weight.data.clone()
         if has_bias:
            UpperCAmelCase_   :   Dict     	=       module.bias.data.clone()

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

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

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










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCAmelCase_					:		int           = {
    '''configuration_unispeech_sat''': ['''UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''UniSpeechSatConfig'''],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase_					:		Tuple           = [
	    '''UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''UniSpeechSatForAudioFrameClassification''',
	    '''UniSpeechSatForCTC''',
	    '''UniSpeechSatForPreTraining''',
	    '''UniSpeechSatForSequenceClassification''',
	    '''UniSpeechSatForXVector''',
	    '''UniSpeechSatModel''',
	    '''UniSpeechSatPreTrainedModel''',
	]

if TYPE_CHECKING:
	from .configuration_unispeech_sat import UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP, UniSpeechSatConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_unispeech_sat import (
		    UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    UniSpeechSatForAudioFrameClassification,
		    UniSpeechSatForCTC,
		    UniSpeechSatForPreTraining,
		    UniSpeechSatForSequenceClassification,
		    UniSpeechSatForXVector,
		    UniSpeechSatModel,
		    UniSpeechSatPreTrainedModel,
		)

else:
	import sys

	UpperCAmelCase_					:		str           = _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
