



'''simple docstring'''
from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch


@require_torch
@require_tf
class 	SCREAMING_SNAKE_CASE__					( _UpperCamelCase       ):
	"""simple docstring"""


	def   a__			(		self      )			->				List[str]:
				A:   Optional[int]								= SMALL_MODEL_IDENTIFIER
				A:   str								= """pt"""
				A:   str								= """tf"""


	def   a__			(		self       , A      )			->				Union[str, Any]:
				A:   int								= AutoModel.from_pretrained(self.test_model      )
				model_pt.save_pretrained(UpperCamelCase__      )


	def   a__			(		self       , A      )			->				List[Any]:
				A:   Optional[int]								= TFAutoModel.from_pretrained(self.test_model       , from_pt=UpperCamelCase__      )
				model_tf.save_pretrained(UpperCamelCase__      )


	def   a__			(		self      )			->				Tuple:
				A:   int								= """mock_framework"""

				# Framework provided - return whatever the user provides
				A:   Optional[Any]								= FeaturesManager.determine_framework(self.test_model       , UpperCamelCase__      )
				self.assertEqual(UpperCamelCase__       , UpperCamelCase__      )

				# Local checkpoint and framework provided - return provided framework
				# PyTorch checkpoint
				with TemporaryDirectory() as local_pt_ckpt:
							self._setup_pt_ckpt(UpperCamelCase__      )
							A:   Tuple								= FeaturesManager.determine_framework(UpperCamelCase__       , UpperCamelCase__      )
							self.assertEqual(UpperCamelCase__       , UpperCamelCase__      )

				# TensorFlow checkpoint
				with TemporaryDirectory() as local_tf_ckpt:
							self._setup_tf_ckpt(UpperCamelCase__      )
							A:   Optional[int]								= FeaturesManager.determine_framework(UpperCamelCase__       , UpperCamelCase__      )
							self.assertEqual(UpperCamelCase__       , UpperCamelCase__      )


	def   a__			(		self      )			->				List[str]:
				# PyTorch checkpoint
				with TemporaryDirectory() as local_pt_ckpt:
							self._setup_pt_ckpt(UpperCamelCase__      )
							A:   List[str]								= FeaturesManager.determine_framework(UpperCamelCase__      )
							self.assertEqual(UpperCamelCase__       , self.framework_pt      )

				# TensorFlow checkpoint
				with TemporaryDirectory() as local_tf_ckpt:
							self._setup_tf_ckpt(UpperCamelCase__      )
							A:   List[str]								= FeaturesManager.determine_framework(UpperCamelCase__      )
							self.assertEqual(UpperCamelCase__       , self.framework_tf      )

				# Invalid local checkpoint
				with TemporaryDirectory() as local_invalid_ckpt:
							with self.assertRaises(UpperCamelCase__      ):
										A:   List[str]								= FeaturesManager.determine_framework(UpperCamelCase__      )





	def   a__			(		self      )			->				Union[str, Any]:
				A:   Dict								= MagicMock(return_value=UpperCamelCase__      )
				with patch("""transformers.onnx.features.is_tf_available"""       , UpperCamelCase__      ):
							A:   int								= FeaturesManager.determine_framework(self.test_model      )
							self.assertEqual(UpperCamelCase__       , self.framework_pt      )

				# PyTorch not in environment -> use TensorFlow
				A:   int								= MagicMock(return_value=UpperCamelCase__      )
				with patch("""transformers.onnx.features.is_torch_available"""       , UpperCamelCase__      ):
							A:   Optional[Any]								= FeaturesManager.determine_framework(self.test_model      )
							self.assertEqual(UpperCamelCase__       , self.framework_tf      )

				# Both in environment -> use PyTorch
				A:   Union[str, Any]								= MagicMock(return_value=UpperCamelCase__      )
				A:   Optional[int]								= MagicMock(return_value=UpperCamelCase__      )
				with patch("""transformers.onnx.features.is_tf_available"""       , UpperCamelCase__      ), patch(
				    """transformers.onnx.features.is_torch_available"""       , UpperCamelCase__      ):
							A:   Optional[Any]								= FeaturesManager.determine_framework(self.test_model      )
							self.assertEqual(UpperCamelCase__       , self.framework_pt      )

				# Both not in environment -> raise error
				A:   List[Any]								= MagicMock(return_value=UpperCamelCase__      )
				A:   Optional[int]								= MagicMock(return_value=UpperCamelCase__      )
				with patch("""transformers.onnx.features.is_tf_available"""       , UpperCamelCase__      ), patch(
				    """transformers.onnx.features.is_torch_available"""       , UpperCamelCase__      ):
							with self.assertRaises(UpperCamelCase__      ):
										A:   List[str]								= FeaturesManager.determine_framework(self.test_model      )






'''simple docstring'''






from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)



