



'''simple docstring'''

import unittest

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

class      __magic_name__						(   unittest.TestCase       ):







							def 							__lowercase      (							self :	List[str]		):
									_a					:				Optional[Any]				=							['a', 'b', 'c']

									# Defaults to last layer if both are None
									_a	, _a					:				List[Any]				=							get_aligned_output_features_output_indices(_UpperCAmelCase     ,_UpperCAmelCase     ,_UpperCAmelCase		)
									self.assertEqual(_UpperCAmelCase     ,['c']		)
									self.assertEqual(_UpperCAmelCase     ,[2]		)

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

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

									# Out features selected from negative indices
									_a	, _a					:				Tuple				=							get_aligned_output_features_output_indices(_UpperCAmelCase     ,[-3, -1]     ,_UpperCAmelCase		)
									self.assertEqual(_UpperCAmelCase     ,['a', 'c']		)
									self.assertEqual(_UpperCAmelCase     ,[-3, -1]		)







							def 							__lowercase      (							self :	Optional[int]		):
									# Stage names must be set
									with self.assertRaises(_UpperCAmelCase		):
											verify_out_features_out_indices(['a', 'b']     ,(0, 1)     ,_UpperCAmelCase		)

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

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

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

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

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

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

									# Out features and out indices should be in order
									with self.assertRaises(_UpperCAmelCase		):
											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 							__lowercase      (							self :	Optional[Any]		):
									_a					:				Tuple				=							BackboneMixin()

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

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









'''simple docstring'''

from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__lowerCAmelCase						      =       logging.get_logger(__name__)

__lowerCAmelCase						      =       {
    '''distilbert-base-uncased''': '''https://huggingface.co/distilbert-base-uncased/resolve/main/config.json''',
    '''distilbert-base-uncased-distilled-squad''': (
        '''https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json'''
    ),
    '''distilbert-base-cased''': '''https://huggingface.co/distilbert-base-cased/resolve/main/config.json''',
    '''distilbert-base-cased-distilled-squad''': (
        '''https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json'''
    ),
    '''distilbert-base-german-cased''': '''https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json''',
    '''distilbert-base-multilingual-cased''': (
        '''https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json'''
    ),
    '''distilbert-base-uncased-finetuned-sst-2-english''': (
        '''https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json'''
    ),
}

class      __magic_name__						(   _UpperCamelCase       ):
							lowerCAmelCase	:   Optional[int]           = 'distilbert'
							lowerCAmelCase	:   Optional[int]           = {
							    'hidden_size': 'dim',
							    'num_attention_heads': 'n_heads',
							    'num_hidden_layers': 'n_layers',
							}







							def __init__(							self :	str     ,_UpperCAmelCase :	Optional[Any]=30522     ,_UpperCAmelCase :	int=512     ,_UpperCAmelCase :	int=False     ,_UpperCAmelCase :	str=6     ,_UpperCAmelCase :	int=12     ,_UpperCAmelCase :	Union[str, Any]=768     ,_UpperCAmelCase :	Optional[Any]=4 * 768     ,_UpperCAmelCase :	int=0.1     ,_UpperCAmelCase :	Union[str, Any]=0.1     ,_UpperCAmelCase :	Tuple="gelu"     ,_UpperCAmelCase :	Any=0.02     ,_UpperCAmelCase :	List[Any]=0.1     ,_UpperCAmelCase :	Dict=0.2     ,_UpperCAmelCase :	Union[str, Any]=0     ,**_UpperCAmelCase :	List[Any]     ,):
									_a					:				Optional[Any]				=							vocab_size
									_a					:				Dict				=							max_position_embeddings
									_a					:				Optional[int]				=							sinusoidal_pos_embds
									_a					:				List[Any]				=							n_layers
									_a					:				Any				=							n_heads
									_a					:				int				=							dim
									_a					:				Optional[Any]				=							hidden_dim
									_a					:				str				=							dropout
									_a					:				Optional[Any]				=							attention_dropout
									_a					:				Any				=							activation
									_a					:				Tuple				=							initializer_range
									_a					:				Union[str, Any]				=							qa_dropout
									_a					:				List[Any]				=							seq_classif_dropout
									super().__init__(**_UpperCAmelCase     ,pad_token_id=_UpperCAmelCase		)

class      __magic_name__						(   _UpperCamelCase       ):







							@property
							def 							__lowercase      (							self :	Union[str, Any]		):
									if self.task == "multiple-choice":
											_a					:				Union[str, Any]				=							{0: 'batch', 1: 'choice', 2: 'sequence'}
									else:
											_a					:				List[str]				=							{0: 'batch', 1: 'sequence'}
									return OrderedDict(
									    [
									        ('input_ids', dynamic_axis),
									        ('attention_mask', dynamic_axis),
									    ]		)




