


'''simple docstring'''
import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    MODEL_MAPPING,
		    SegformerForImageClassification,
		    SegformerForSemanticSegmentation,
		    SegformerModel,
		)
		from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
		from PIL import Image

		from transformers import SegformerImageProcessor
class    lowercase	(							A__					):

		"""simple docstring"""

		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Union[str, Any]												= self.config_class(**self.inputs_dict							)
							self.parent.assertTrue(hasattr(UpperCamelCase_    ,   '''hidden_sizes'''							)							)
							self.parent.assertTrue(hasattr(UpperCamelCase_    ,   '''num_attention_heads'''							)							)
							self.parent.assertTrue(hasattr(UpperCamelCase_    ,   '''num_encoder_blocks'''							)							)



class    lowercase	:

		"""simple docstring"""

		def __init__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_=13    ,   UpperCamelCase_=64    ,   UpperCamelCase_=3    ,   UpperCamelCase_=4    ,   UpperCamelCase_=[2, 2, 2, 2]    ,   UpperCamelCase_=[8, 4, 2, 1]    ,   UpperCamelCase_=[16, 32, 64, 128]    ,   UpperCamelCase_=[1, 4, 8, 16]    ,   UpperCamelCase_=[1, 2, 4, 8]    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_="gelu"    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=0.02    ,   UpperCamelCase_=3    ,   UpperCamelCase_=None    ,   ):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= parent
							UpperCamelCase__   :int												= batch_size
							UpperCamelCase__   :Tuple												= image_size
							UpperCamelCase__   :Tuple												= num_channels
							UpperCamelCase__   :List[str]												= num_encoder_blocks
							UpperCamelCase__   :Any												= sr_ratios
							UpperCamelCase__   :Any												= depths
							UpperCamelCase__   :Union[str, Any]												= hidden_sizes
							UpperCamelCase__   :Union[str, Any]												= downsampling_rates
							UpperCamelCase__   :List[str]												= num_attention_heads
							UpperCamelCase__   :Optional[int]												= is_training
							UpperCamelCase__   :str												= use_labels
							UpperCamelCase__   :Any												= hidden_act
							UpperCamelCase__   :Union[str, Any]												= hidden_dropout_prob
							UpperCamelCase__   :Tuple												= attention_probs_dropout_prob
							UpperCamelCase__   :Optional[int]												= initializer_range
							UpperCamelCase__   :Optional[int]												= num_labels
							UpperCamelCase__   :Any												= scope




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

							UpperCamelCase__   :List[str]												= None
							if self.use_labels:
												UpperCamelCase__   :Tuple												= ids_tensor([self.batch_size, self.image_size, self.image_size]    ,   self.num_labels							)

							UpperCamelCase__   :Union[str, Any]												= self.get_config()
							return config, pixel_values, labels




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							return SegformerConfig(
							    image_size=self.image_size    ,   num_channels=self.num_channels    ,   num_encoder_blocks=self.num_encoder_blocks    ,   depths=self.depths    ,   hidden_sizes=self.hidden_sizes    ,   num_attention_heads=self.num_attention_heads    ,   hidden_act=self.hidden_act    ,   hidden_dropout_prob=self.hidden_dropout_prob    ,   attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,   initializer_range=self.initializer_range    ,   )




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= SegformerModel(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :List[str]												= model(UpperCamelCase_							)
							UpperCamelCase__   :Optional[int]												= self.image_size // (self.downsampling_rates[-1] * 2)
							self.parent.assertEqual(
							    result.last_hidden_state.shape    ,   (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= self.num_labels
							UpperCamelCase__   :Any												= SegformerForSemanticSegmentation(UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :List[Any]												= model(UpperCamelCase_							)
							self.parent.assertEqual(
							    result.logits.shape    ,   (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)							)
							UpperCamelCase__   :Union[str, Any]												= model(UpperCamelCase_    ,   labels=UpperCamelCase_							)
							self.parent.assertEqual(
							    result.logits.shape    ,   (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)							)
							self.parent.assertGreater(result.loss    ,   0.0							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= 1
							UpperCamelCase__   :Dict												= SegformerForSemanticSegmentation(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Optional[Any]												= torch.randint(0    ,   1    ,   (self.batch_size, self.image_size, self.image_size)							).to(UpperCamelCase_							)
							UpperCamelCase__   :Tuple												= model(UpperCamelCase_    ,   labels=UpperCamelCase_							)
							self.parent.assertGreater(result.loss    ,   0.0							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :int												= self.prepare_config_and_inputs()
							UpperCamelCase__					,				UpperCamelCase__					,				UpperCamelCase__   :Union[str, Any]												= config_and_inputs
							UpperCamelCase__   :int												= {'''pixel_values''': pixel_values}
							return config, inputs_dict



@require_torch
class    lowercase	(							A__	,		A__	,		unittest.TestCase					):

		"""simple docstring"""

		_a     =				(
		    (
		        SegformerModel,
		        SegformerForSemanticSegmentation,
		        SegformerForImageClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		_a     =				(
		    {
		        'feature-extraction': SegformerModel,
		        'image-classification': SegformerForImageClassification,
		        'image-segmentation': SegformerForSemanticSegmentation,
		    }
		    if is_torch_available()
		    else {}
		)

		_a     =				True
		_a     =				False
		_a     =				False
		_a     =				False




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= SegformerModelTester(self							)
							UpperCamelCase__   :Tuple												= SegformerConfigTester(self    ,   config_class=UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_binary_image_segmentation(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_image_segmentation(*UpperCamelCase_							)




		@unittest.skip('''SegFormer does not use inputs_embeds'''							)
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass




		@unittest.skip('''SegFormer does not have get_input_embeddings method and get_output_embeddings methods'''							)
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__					,				UpperCamelCase__   :Union[str, Any]												= self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__   :List[Any]												= model_class(UpperCamelCase_							)
												UpperCamelCase__   :Optional[int]												= inspect.signature(model.forward							)
												# signature.parameters is an OrderedDict => so arg_names order is deterministic
												UpperCamelCase__   :List[Any]												= [*signature.parameters.keys()]

												UpperCamelCase__   :Dict												= ['''pixel_values''']
												self.assertListEqual(arg_names[:1]    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__					,				UpperCamelCase__   :List[str]												= self.model_tester.prepare_config_and_inputs_for_common()
							UpperCamelCase__   :Union[str, Any]												= True

							for model_class in self.all_model_classes:
												UpperCamelCase__   :List[str]												= True
												UpperCamelCase__   :List[Any]												= False
												UpperCamelCase__   :Optional[Any]												= True
												UpperCamelCase__   :List[Any]												= model_class(UpperCamelCase_							)
												model.to(UpperCamelCase_							)
												model.eval()
												with torch.no_grad():
																	UpperCamelCase__   :int												= model(**self._prepare_for_class(UpperCamelCase_    ,   UpperCamelCase_							)							)
												UpperCamelCase__   :str												= outputs.attentions

												UpperCamelCase__   :Any												= sum(self.model_tester.depths							)
												self.assertEqual(len(UpperCamelCase_							)    ,   UpperCamelCase_							)

												# check that output_attentions also work using config
												del inputs_dict["output_attentions"]
												UpperCamelCase__   :Optional[Any]												= True
												UpperCamelCase__   :Tuple												= model_class(UpperCamelCase_							)
												model.to(UpperCamelCase_							)
												model.eval()
												with torch.no_grad():
																	UpperCamelCase__   :Optional[Any]												= model(**self._prepare_for_class(UpperCamelCase_    ,   UpperCamelCase_							)							)
												UpperCamelCase__   :int												= outputs.attentions

												self.assertEqual(len(UpperCamelCase_							)    ,   UpperCamelCase_							)

												# verify the first attentions (first block, first layer)
												UpperCamelCase__   :str												= (self.model_tester.image_size // 4) ** 2
												UpperCamelCase__   :str												= (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
												self.assertListEqual(
												    list(attentions[0].shape[-3:]							)    ,   [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]    ,   )

												# verify the last attentions (last block, last layer)
												UpperCamelCase__   :Union[str, Any]												= (self.model_tester.image_size // 32) ** 2
												UpperCamelCase__   :List[str]												= (self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
												self.assertListEqual(
												    list(attentions[-1].shape[-3:]							)    ,   [self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]    ,   )
												UpperCamelCase__   :Union[str, Any]												= len(UpperCamelCase_							)

												# Check attention is always last and order is fine
												UpperCamelCase__   :Union[str, Any]												= True
												UpperCamelCase__   :Tuple												= True
												UpperCamelCase__   :str												= model_class(UpperCamelCase_							)
												model.to(UpperCamelCase_							)
												model.eval()
												with torch.no_grad():
																	UpperCamelCase__   :Any												= model(**self._prepare_for_class(UpperCamelCase_    ,   UpperCamelCase_							)							)

												self.assertEqual(out_len + 1    ,   len(UpperCamelCase_							)							)

												UpperCamelCase__   :Tuple												= outputs.attentions

												self.assertEqual(len(UpperCamelCase_							)    ,   UpperCamelCase_							)
												# verify the first attentions (first block, first layer)
												UpperCamelCase__   :Any												= (self.model_tester.image_size // 4) ** 2
												UpperCamelCase__   :List[Any]												= (self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
												self.assertListEqual(
												    list(self_attentions[0].shape[-3:]							)    ,   [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]    ,   )




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							def check_hidden_states_output(UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):
												UpperCamelCase__   :Optional[Any]												= model_class(UpperCamelCase_							)
												model.to(UpperCamelCase_							)
												model.eval()

												with torch.no_grad():
																	UpperCamelCase__   :Optional[Any]												= model(**self._prepare_for_class(UpperCamelCase_    ,   UpperCamelCase_							)							)

												UpperCamelCase__   :str												= outputs.hidden_states

												UpperCamelCase__   :Optional[Any]												= self.model_tester.num_encoder_blocks
												self.assertEqual(len(UpperCamelCase_							)    ,   UpperCamelCase_							)

												# verify the first hidden states (first block)
												self.assertListEqual(
												    list(hidden_states[0].shape[-3:]							)    ,   [
												        self.model_tester.hidden_sizes[0],
												        self.model_tester.image_size // 4,
												        self.model_tester.image_size // 4,
												    ]    ,   )

							UpperCamelCase__					,				UpperCamelCase__   :Optional[int]												= self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
												UpperCamelCase__   :Union[str, Any]												= True
												check_hidden_states_output(UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							)

												# check that output_hidden_states also work using config
												del inputs_dict["output_hidden_states"]
												UpperCamelCase__   :str												= True

												check_hidden_states_output(UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							if not self.model_tester.is_training:
												return

							UpperCamelCase__					,				UpperCamelCase__   :Tuple												= self.model_tester.prepare_config_and_inputs_for_common()
							UpperCamelCase__   :List[Any]												= True

							for model_class in self.all_model_classes:
												if model_class in get_values(UpperCamelCase_							):
																	continue

												UpperCamelCase__   :Tuple												= model_class(UpperCamelCase_							)
												model.to(UpperCamelCase_							)
												model.train()
												UpperCamelCase__   :int												= self._prepare_for_class(UpperCamelCase_    ,   UpperCamelCase_    ,   return_labels=UpperCamelCase_							)
												UpperCamelCase__   :Dict												= model(**UpperCamelCase_							).loss
												loss.backward()




		@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							pass




		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__   :List[str]												= SegformerModel.from_pretrained(UpperCamelCase_							)
												self.assertIsNotNone(UpperCamelCase_							)



def 			a      (			)  ->	str:



					'''simple docstring'''






					UpperCamelCase__   :Tuple												= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
					return image







@require_torch
class    lowercase	(							unittest.TestCase					):

		"""simple docstring"""

		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= SegformerImageProcessor(
							    image_scale=(512, 512)    ,   keep_ratio=UpperCamelCase_    ,   align=UpperCamelCase_    ,   do_random_crop=UpperCamelCase_							)
							UpperCamelCase__   :Dict												= SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512'''							).to(
							    UpperCamelCase_							)

							UpperCamelCase__   :Dict												= prepare_img()
							UpperCamelCase__   :Union[str, Any]												= image_processor(images=UpperCamelCase_    ,   return_tensors='''pt'''							)
							UpperCamelCase__   :Any												= encoded_inputs.pixel_values.to(UpperCamelCase_							)

							with torch.no_grad():
												UpperCamelCase__   :Optional[Any]												= model(UpperCamelCase_							)

							UpperCamelCase__   :Tuple												= torch.Size((1, model.config.num_labels, 128, 128)							)
							self.assertEqual(outputs.logits.shape    ,   UpperCamelCase_							)

							UpperCamelCase__   :int												= torch.tensor(
							    [
							        [[-4.6310, -5.5232, -6.2356], [-5.1921, -6.1444, -6.5996], [-5.4424, -6.2790, -6.7574]],
							        [[-12.1391, -13.3122, -13.9554], [-12.8732, -13.9352, -14.3563], [-12.9438, -13.8226, -14.2513]],
							        [[-12.5134, -13.4686, -14.4915], [-12.8669, -14.4343, -14.7758], [-13.2523, -14.5819, -15.0694]],
							    ]							).to(UpperCamelCase_							)
							self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]    ,   UpperCamelCase_    ,   atol=1e-4							)							)




		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= SegformerImageProcessor(
							    image_scale=(512, 512)    ,   keep_ratio=UpperCamelCase_    ,   align=UpperCamelCase_    ,   do_random_crop=UpperCamelCase_							)
							UpperCamelCase__   :List[str]												= SegformerForSemanticSegmentation.from_pretrained(
							    '''nvidia/segformer-b1-finetuned-cityscapes-1024-1024'''							).to(UpperCamelCase_							)

							UpperCamelCase__   :Optional[int]												= prepare_img()
							UpperCamelCase__   :Any												= image_processor(images=UpperCamelCase_    ,   return_tensors='''pt'''							)
							UpperCamelCase__   :Tuple												= encoded_inputs.pixel_values.to(UpperCamelCase_							)

							with torch.no_grad():
												UpperCamelCase__   :Tuple												= model(UpperCamelCase_							)

							UpperCamelCase__   :int												= torch.Size((1, model.config.num_labels, 128, 128)							)
							self.assertEqual(outputs.logits.shape    ,   UpperCamelCase_							)

							UpperCamelCase__   :Union[str, Any]												= torch.tensor(
							    [
							        [[-13.5748, -13.9111, -12.6500], [-14.3500, -15.3683, -14.2328], [-14.7532, -16.0424, -15.6087]],
							        [[-17.1651, -15.8725, -12.9653], [-17.2580, -17.3718, -14.8223], [-16.6058, -16.8783, -16.7452]],
							        [[-3.6456, -3.0209, -1.4203], [-3.0797, -3.1959, -2.0000], [-1.8757, -1.9217, -1.6997]],
							    ]							).to(UpperCamelCase_							)
							self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]    ,   UpperCamelCase_    ,   atol=1e-1							)							)




		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= SegformerImageProcessor(
							    image_scale=(512, 512)    ,   keep_ratio=UpperCamelCase_    ,   align=UpperCamelCase_    ,   do_random_crop=UpperCamelCase_							)
							UpperCamelCase__   :str												= SegformerForSemanticSegmentation.from_pretrained('''nvidia/segformer-b0-finetuned-ade-512-512'''							).to(
							    UpperCamelCase_							)

							UpperCamelCase__   :List[Any]												= prepare_img()
							UpperCamelCase__   :List[Any]												= image_processor(images=UpperCamelCase_    ,   return_tensors='''pt'''							)
							UpperCamelCase__   :str												= encoded_inputs.pixel_values.to(UpperCamelCase_							)

							with torch.no_grad():
												UpperCamelCase__   :str												= model(UpperCamelCase_							)

							UpperCamelCase__   :Optional[int]												= outputs.logits.detach().cpu()

							UpperCamelCase__   :Dict												= image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase_    ,   target_sizes=[(500, 300)]							)
							UpperCamelCase__   :Any												= torch.Size((500, 300)							)
							self.assertEqual(segmentation[0].shape    ,   UpperCamelCase_							)

							UpperCamelCase__   :Any												= image_processor.post_process_semantic_segmentation(outputs=UpperCamelCase_							)
							UpperCamelCase__   :Optional[int]												= torch.Size((128, 128)							)
							self.assertEqual(segmentation[0].shape    ,   UpperCamelCase_							)





# flake8: noqa
# Lint as: python3

from typing import Dict, List, Optional, Type

from .. import config
from ..utils import logging
from .formatting import (
    ArrowFormatter,
    CustomFormatter,
    Formatter,
    PandasFormatter,
    PythonFormatter,
    TensorFormatter,
    format_table,
    query_table,
)
from .np_formatter import NumpyFormatter


__UpperCamelCase					:       List[str]    					=      logging.get_logger(__name__)

__UpperCamelCase					:       Dict[Optional[str], Type[Formatter]]    					=      {}
__UpperCamelCase					:       Dict[Optional[str], str]    					=      {}
__UpperCamelCase					:       Dict[Optional[str], Exception]    					=      {}





def 		__A		(	__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase = None							,			)      ->       Optional[int]:
	a										=							aliases if aliases is not None else []
	if format_type in _FORMAT_TYPES:
		logger.warning(
		    f'Overwriting format type \'{format_type}\' ({_FORMAT_TYPES[format_type].__name__} -> {formatter_cls.__name__})'    )
	a										=							formatter_cls
	for alias in set(aliases + [format_type]    ):
		if alias in _FORMAT_TYPES_ALIASES:
			logger.warning(
			    f'Overwriting format type alias \'{alias}\' ({_FORMAT_TYPES_ALIASES[alias]} -> {format_type})'    )
		a										=							format_type





def 		__A		(	__lowerCamelCase							,			__lowerCamelCase							,			__lowerCamelCase = None    )      ->       List[str]:
	a										=							aliases if aliases is not None else []
	for alias in set(aliases + [format_type]    ):
		a										=							unavailable_error


# Here we define all the available formatting functions that can be used by `Dataset.set_format`
_register_formatter(PythonFormatter, None, aliases=["python"])
_register_formatter(ArrowFormatter, "arrow", aliases=["pa", "pyarrow"])
_register_formatter(NumpyFormatter, "numpy", aliases=["np"])
_register_formatter(PandasFormatter, "pandas", aliases=["pd"])
_register_formatter(CustomFormatter, "custom")

if config.TORCH_AVAILABLE:
		from .torch_formatter import TorchFormatter

		_register_formatter(TorchFormatter, "torch", aliases=["pt", "pytorch"])
else:
		__UpperCamelCase					:       str    					=      ValueError("PyTorch needs to be installed to be able to return PyTorch tensors.")
		_register_unavailable_formatter(_torch_error, "torch", aliases=["pt", "pytorch"])

if config.TF_AVAILABLE:
		from .tf_formatter import TFFormatter

		_register_formatter(TFFormatter, "tensorflow", aliases=["tf"])
else:
		__UpperCamelCase					:       List[str]    					=      ValueError("Tensorflow needs to be installed to be able to return Tensorflow tensors.")
		_register_unavailable_formatter(_tf_error, "tensorflow", aliases=["tf"])

if config.JAX_AVAILABLE:
		from .jax_formatter import JaxFormatter

		_register_formatter(JaxFormatter, "jax", aliases=[])
else:
		__UpperCamelCase					:       List[str]    					=      ValueError("JAX needs to be installed to be able to return JAX arrays.")
		_register_unavailable_formatter(_jax_error, "jax", aliases=[])





def 		__A		(	__lowerCamelCase    )      ->       Optional[str]:
	if format_type in _FORMAT_TYPES_ALIASES:
		return _FORMAT_TYPES_ALIASES[format_type]
	else:
		return format_type





def 		__A		(	__lowerCamelCase							,			**__lowerCamelCase    )      ->       Formatter:
	a										=							get_format_type_from_alias(__lowerCamelCase    )
	if format_type in _FORMAT_TYPES:
		return _FORMAT_TYPES[format_type](**__lowerCamelCase    )
	if format_type in _FORMAT_TYPES_ALIASES_UNAVAILABLE:
		raise _FORMAT_TYPES_ALIASES_UNAVAILABLE[format_type]
	else:
		raise ValueError(
		    f'Return type should be None or selected in {list(type for type in _FORMAT_TYPES.keys() if type != None    )}, but got \'{format_type}\''    )

