



import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)

class  __snake_case      (   unittest.TestCase):







							'''simple docstring'''






							def _a      (							self		):
											a__				      =		['''a''', '''b''', '''c''']

											# Defaults to last layer if both are None
											a__				      =		get_aligned_output_features_output_indices(lowercase__  ,  lowercase__  ,  lowercase__		)
											self.assertEqual(lowercase__  ,  ["""c"""]		)
											self.assertEqual(lowercase__  ,  [2]		)

											# Out indices set to match out features
											a__				      =		get_aligned_output_features_output_indices(["""a""", """c"""]  ,  lowercase__  ,  lowercase__		)
											self.assertEqual(lowercase__  ,  ["""a""", """c"""]		)
											self.assertEqual(lowercase__  ,  [0, 2]		)

											# Out features set to match out indices
											a__				      =		get_aligned_output_features_output_indices(lowercase__  ,  [0, 2]  ,  lowercase__		)
											self.assertEqual(lowercase__  ,  ["""a""", """c"""]		)
											self.assertEqual(lowercase__  ,  [0, 2]		)

											# Out features selected from negative indices
											a__				      =		get_aligned_output_features_output_indices(lowercase__  ,  [-3, -1]  ,  lowercase__		)
											self.assertEqual(lowercase__  ,  ["""a""", """c"""]		)
											self.assertEqual(lowercase__  ,  [-3, -1]		)


							def _a      (							self		):





											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(["""a""", """b"""]  ,  (0, 1)  ,  lowercase__		)

											# Out features must be a list
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(("""a""", """b""")  ,  (0, 1)  ,  ["""a""", """b"""]		)

											# Out features must be a subset of stage names
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(["""a""", """b"""]  ,  (0, 1)  ,  ["""a"""]		)

											# Out indices must be a list or tuple
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(lowercase__  ,  0  ,  ["""a""", """b"""]		)

											# Out indices must be a subset of stage names
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(lowercase__  ,  (0, 1)  ,  ["""a"""]		)

											# Out features and out indices must be the same length
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(["""a""", """b"""]  ,  (0,)  ,  ["""a""", """b""", """c"""]		)

											# Out features should match out indices
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(["""a""", """b"""]  ,  (0, 2)  ,  ["""a""", """b""", """c"""]		)

											# Out features and out indices should be in order
											with self.assertRaises(lowercase__		):
															verify_out_features_out_indices(["""b""", """a"""]  ,  (0, 1)  ,  ["""a""", """b"""]		)

											# Check passes with valid inputs
											verify_out_features_out_indices(["""a""", """b""", """d"""]  ,  (0, 1, -1)  ,  ["""a""", """b""", """c""", """d"""]		)







							def _a      (							self		):
											a__				      =		BackboneMixin()

											a__				      =		['''a''', '''b''', '''c''']
											a__				      =		['''a''', '''c''']
											a__				      =		[0, 2]

											# Check that the output features and indices are set correctly
											self.assertEqual(backbone.out_features  ,  ["""a""", """c"""]		)
											self.assertEqual(backbone.out_indices  ,  [0, 2]		)

											# Check out features and indices are updated correctly
											a__				      =		['''a''', '''b''']
											self.assertEqual(backbone.out_features  ,  ["""a""", """b"""]		)
											self.assertEqual(backbone.out_indices  ,  [0, 1]		)

											a__				      =		[-3, -1]
											self.assertEqual(backbone.out_features  ,  ["""a""", """c"""]		)
											self.assertEqual(backbone.out_indices  ,  [-3, -1]		)






from typing import TYPE_CHECKING

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


UpperCAmelCase							 =					{
    """configuration_xlm_roberta""": [
        """XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """XLMRobertaConfig""",
        """XLMRobertaOnnxConfig""",
    ],
}

try:
	if not is_sentencepiece_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase							 =					["""XLMRobertaTokenizer"""]

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase							 =					["""XLMRobertaTokenizerFast"""]

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase							 =					[
	    """XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """XLMRobertaForCausalLM""",
	    """XLMRobertaForMaskedLM""",
	    """XLMRobertaForMultipleChoice""",
	    """XLMRobertaForQuestionAnswering""",
	    """XLMRobertaForSequenceClassification""",
	    """XLMRobertaForTokenClassification""",
	    """XLMRobertaModel""",
	    """XLMRobertaPreTrainedModel""",
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase							 =					[
	    """TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """TFXLMRobertaForCausalLM""",
	    """TFXLMRobertaForMaskedLM""",
	    """TFXLMRobertaForMultipleChoice""",
	    """TFXLMRobertaForQuestionAnswering""",
	    """TFXLMRobertaForSequenceClassification""",
	    """TFXLMRobertaForTokenClassification""",
	    """TFXLMRobertaModel""",
	    """TFXLMRobertaPreTrainedModel""",
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase							 =					[
	    """FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """FlaxXLMRobertaForMaskedLM""",
	    """FlaxXLMRobertaForCausalLM""",
	    """FlaxXLMRobertaForMultipleChoice""",
	    """FlaxXLMRobertaForQuestionAnswering""",
	    """FlaxXLMRobertaForSequenceClassification""",
	    """FlaxXLMRobertaForTokenClassification""",
	    """FlaxXLMRobertaModel""",
	    """FlaxXLMRobertaPreTrainedModel""",
	]

if TYPE_CHECKING:
	from .configuration_xlm_roberta import (
	    XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    XLMRobertaConfig,
	    XLMRobertaOnnxConfig,
	)

	try:
		if not is_sentencepiece_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_xlm_roberta import XLMRobertaTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_xlm_roberta_fast import XLMRobertaTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_xlm_roberta import (
		    XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
		    XLMRobertaForCausalLM,
		    XLMRobertaForMaskedLM,
		    XLMRobertaForMultipleChoice,
		    XLMRobertaForQuestionAnswering,
		    XLMRobertaForSequenceClassification,
		    XLMRobertaForTokenClassification,
		    XLMRobertaModel,
		    XLMRobertaPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_xlm_roberta import (
		    TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFXLMRobertaForCausalLM,
		    TFXLMRobertaForMaskedLM,
		    TFXLMRobertaForMultipleChoice,
		    TFXLMRobertaForQuestionAnswering,
		    TFXLMRobertaForSequenceClassification,
		    TFXLMRobertaForTokenClassification,
		    TFXLMRobertaModel,
		    TFXLMRobertaPreTrainedModel,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_xlm_roberta import (
		    FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
		    FlaxXLMRobertaForCausalLM,
		    FlaxXLMRobertaForMaskedLM,
		    FlaxXLMRobertaForMultipleChoice,
		    FlaxXLMRobertaForQuestionAnswering,
		    FlaxXLMRobertaForSequenceClassification,
		    FlaxXLMRobertaForTokenClassification,
		    FlaxXLMRobertaModel,
		    FlaxXLMRobertaPreTrainedModel,
		)

else:
	import sys

	UpperCAmelCase							 =					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

