



"""simple docstring"""

import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)
class     lowerCAmelCase__						(	unittest.TestCase ):


	'''simple docstring'''







	def 			_lowerCAmelCase     (      self				:       List[Any]    )						->	Optional[int]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							int							=     ['a', 'b', 'c']

					# Defaults to last layer if both are None
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							str							=     get_aligned_output_features_output_indices(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       ['c']    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       [2]    )

					# Out indices set to match out features
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							Tuple							=     get_aligned_output_features_output_indices(['a', 'c']     ,       _SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       ['a', 'c']    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       [0, 2]    )

					# Out features set to match out indices
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							Optional[Any]							=     get_aligned_output_features_output_indices(_SCREAMING_SNAKE_CASE     ,       [0, 2]     ,       _SCREAMING_SNAKE_CASE    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       ['a', 'c']    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       [0, 2]    )

					# Out features selected from negative indices
					SCREAMING_SNAKE_CASE				,						SCREAMING_SNAKE_CASE						:							List[str]							=     get_aligned_output_features_output_indices(_SCREAMING_SNAKE_CASE     ,       [-3, -1]     ,       _SCREAMING_SNAKE_CASE    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       ['a', 'c']    )
					self.assertEqual(_SCREAMING_SNAKE_CASE     ,       [-3, -1]    )





	def 			_lowerCAmelCase     (      self				:       int    )						->	int:





					"""simple docstring"""


					with self.assertRaises(_SCREAMING_SNAKE_CASE    ):
									verify_out_features_out_indices(['a', 'b']     ,       (0, 1)     ,       _SCREAMING_SNAKE_CASE    )

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

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

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

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

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

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

					# Out features and out indices should be in order
					with self.assertRaises(_SCREAMING_SNAKE_CASE    ):
									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 			_lowerCAmelCase     (      self				:       Optional[Any]    )						->	int:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[int]							=     BackboneMixin()

					SCREAMING_SNAKE_CASE						:							Optional[int]							=     ['a', 'b', 'c']
					SCREAMING_SNAKE_CASE						:							Tuple							=     ['a', 'c']
					SCREAMING_SNAKE_CASE						:							Any							=     [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
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     ['a', 'b']
					self.assertEqual(backbone.out_features     ,       ['a', 'b']    )
					self.assertEqual(backbone.out_indices     ,       [0, 1]    )

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     [-3, -1]
					self.assertEqual(backbone.out_features     ,       ['a', 'c']    )
					self.assertEqual(backbone.out_indices     ,       [-3, -1]    )










"""simple docstring"""

from typing import TYPE_CHECKING

from ..utils import _LazyModule


A_						:    str				=      {
    'config': [
        'EXTERNAL_DATA_FORMAT_SIZE_LIMIT',
        'OnnxConfig',
        'OnnxConfigWithPast',
        'OnnxSeq2SeqConfigWithPast',
        'PatchingSpec',
    ],
    'convert': ['export', 'validate_model_outputs'],
    'features': ['FeaturesManager'],
    'utils': ['ParameterFormat', 'compute_serialized_parameters_size'],
}


if TYPE_CHECKING:
							from .config import (
							    EXTERNAL_DATA_FORMAT_SIZE_LIMIT,
							    OnnxConfig,
							    OnnxConfigWithPast,
							    OnnxSeqaSeqConfigWithPast,
							    PatchingSpec,
							)
							from .convert import export, validate_model_outputs
							from .features import FeaturesManager
							from .utils import ParameterFormat, compute_serialized_parameters_size

else:
							import sys

							A_						:    Optional[Any]				=      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





