





"""simple docstring"""




from collections import OrderedDict
from typing import Mapping

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


UpperCamelCase_           =logging.get_logger(__name__)

UpperCamelCase_           ={
    """flaubert/flaubert_small_cased""": """https://huggingface.co/flaubert/flaubert_small_cased/resolve/main/config.json""",
    """flaubert/flaubert_base_uncased""": """https://huggingface.co/flaubert/flaubert_base_uncased/resolve/main/config.json""",
    """flaubert/flaubert_base_cased""": """https://huggingface.co/flaubert/flaubert_base_cased/resolve/main/config.json""",
    """flaubert/flaubert_large_cased""": """https://huggingface.co/flaubert/flaubert_large_cased/resolve/main/config.json""",
}




class  _a						(      _lowerCAmelCase				):
				UpperCamelCase								=    '''flaubert'''
				UpperCamelCase								=    {
				    '''hidden_size''': '''emb_dim''',
				    '''num_attention_heads''': '''n_heads''',
				    '''num_hidden_layers''': '''n_layers''',
				    '''n_words''': '''vocab_size''',  # For backward compatibility
				}






				def __init__( self		:    Union[str, Any], lowerCAmelCase__		:    List[str]=False, lowerCAmelCase__		:    Optional[Any]=0.0, lowerCAmelCase__		:    Dict=3_0_1_4_5, lowerCAmelCase__		:    Optional[Any]=2_0_4_8, lowerCAmelCase__		:    Tuple=1_2, lowerCAmelCase__		:    Union[str, Any]=1_6, lowerCAmelCase__		:    int=0.1, lowerCAmelCase__		:    Any=0.1, lowerCAmelCase__		:    Union[str, Any]=True, lowerCAmelCase__		:    List[Any]=False, lowerCAmelCase__		:    str=False, lowerCAmelCase__		:    Tuple=False, lowerCAmelCase__		:    List[Any]=1, lowerCAmelCase__		:    int=True, lowerCAmelCase__		:    str=5_1_2, lowerCAmelCase__		:    str=2_0_4_8**-0.5, lowerCAmelCase__		:    Dict=1e-1_2, lowerCAmelCase__		:    Optional[int]=0.02, lowerCAmelCase__		:    Optional[Any]=0, lowerCAmelCase__		:    List[str]=1, lowerCAmelCase__		:    str=2, lowerCAmelCase__		:    str=3, lowerCAmelCase__		:    Optional[int]=5, lowerCAmelCase__		:    List[str]=True, lowerCAmelCase__		:    Dict="first", lowerCAmelCase__		:    Union[str, Any]=True, lowerCAmelCase__		:    List[Any]=None, lowerCAmelCase__		:    Optional[int]=True, lowerCAmelCase__		:    List[Any]=0.1, lowerCAmelCase__		:    Optional[Any]=5, lowerCAmelCase__		:    Optional[int]=5, lowerCAmelCase__		:    List[str]=0, lowerCAmelCase__		:    Optional[int]=0, lowerCAmelCase__		:    str=2, lowerCAmelCase__		:    Optional[int]=0, **lowerCAmelCase__		:    Optional[Any], )	->      Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase			:					List[str]     =    pre_norm
										_UpperCamelCase			:					Any     =    layerdrop
										_UpperCamelCase			:					Optional[int]     =    vocab_size
										_UpperCamelCase			:					Optional[Any]     =    emb_dim
										_UpperCamelCase			:					Optional[int]     =    n_layers
										_UpperCamelCase			:					int     =    n_heads
										_UpperCamelCase			:					Tuple     =    dropout
										_UpperCamelCase			:					str     =    attention_dropout
										_UpperCamelCase			:					Optional[int]     =    gelu_activation
										_UpperCamelCase			:					Dict     =    sinusoidal_embeddings
										_UpperCamelCase			:					Tuple     =    causal
										_UpperCamelCase			:					Any     =    asm
										_UpperCamelCase			:					int     =    n_langs
										_UpperCamelCase			:					Dict     =    use_lang_emb
										_UpperCamelCase			:					Union[str, Any]     =    layer_norm_eps
										_UpperCamelCase			:					str     =    bos_index
										_UpperCamelCase			:					Dict     =    eos_index
										_UpperCamelCase			:					Dict     =    pad_index
										_UpperCamelCase			:					Optional[Any]     =    unk_index
										_UpperCamelCase			:					int     =    mask_index
										_UpperCamelCase			:					str     =    is_encoder
										_UpperCamelCase			:					int     =    max_position_embeddings
										_UpperCamelCase			:					Dict     =    embed_init_std
										_UpperCamelCase			:					Any     =    init_std
										_UpperCamelCase			:					Any     =    summary_type
										_UpperCamelCase			:					List[str]     =    summary_use_proj
										_UpperCamelCase			:					Tuple     =    summary_activation
										_UpperCamelCase			:					Optional[int]     =    summary_proj_to_labels
										_UpperCamelCase			:					int     =    summary_first_dropout
										_UpperCamelCase			:					List[str]     =    start_n_top
										_UpperCamelCase			:					Optional[Any]     =    end_n_top
										_UpperCamelCase			:					Any     =    mask_token_id
										_UpperCamelCase			:					str     =    lang_id

										if "n_words" in kwargs:
																_UpperCamelCase			:					Tuple     =    kwargs['''n_words''']

										super().__init__(pad_token_id=lowerCAmelCase__, bos_token_id=lowerCAmelCase__, **lowerCAmelCase__							)




class  _a						(      _lowerCAmelCase				):






				@property
				def 				snake_case	( self		:    Any							)	->      Mapping[str, Mapping[int, str]]:




										'''simple docstring'''



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










"""simple docstring"""




import torch
from torch import autograd




class  _a						(      autograd.Function				):






				@staticmethod
				def 				snake_case	( lowerCAmelCase__		:    str, lowerCAmelCase__		:    torch.tensor, lowerCAmelCase__		:    float, lowerCAmelCase__		:    bool							)	->      List[Any]:




										'''simple docstring'''



										_UpperCamelCase			:					Optional[Any]     =    inputs.numel()
										_UpperCamelCase			:					int     =    int(0.005 * nb_elems							) + 1
										if sigmoid:
																_UpperCamelCase			:					Dict     =    (torch.sigmoid(lowerCAmelCase__							) > threshold).type(inputs.type()							)
										else:
																_UpperCamelCase			:					Optional[int]     =    (inputs > threshold).type(inputs.type()							)
										if mask.sum() < nb_min:
																# We limit the pruning so that at least 0.5% (half a percent) of the weights are remaining
																_UpperCamelCase			:					int     =    inputs.flatten().kthvalue(max(nb_elems - nb_min, 1							)							).values
																_UpperCamelCase			:					List[str]     =    (inputs > k_threshold).type(inputs.type()							)
										return mask






				@staticmethod
				def 				snake_case	( lowerCAmelCase__		:    str, lowerCAmelCase__		:    Optional[int]							)	->      Union[str, Any]:




										'''simple docstring'''



										return gradOutput, None, None




class  _a						(      autograd.Function				):






				@staticmethod
				def 				snake_case	( lowerCAmelCase__		:    Any, lowerCAmelCase__		:    torch.tensor, lowerCAmelCase__		:    float							)	->      Dict:




										'''simple docstring'''



										_UpperCamelCase			:					str     =    inputs.clone()
										_UpperCamelCase   ,							_UpperCamelCase			:					Union[str, Any]     =    inputs.flatten().sort(descending=lowerCAmelCase__							)
										_UpperCamelCase			:					Optional[Any]     =    int(threshold * inputs.numel()							)

										# flat_out and mask access the same memory.
										_UpperCamelCase			:					Tuple     =    mask.flatten()
										_UpperCamelCase			:					int     =    0
										_UpperCamelCase			:					Tuple     =    1
										return mask






				@staticmethod
				def 				snake_case	( lowerCAmelCase__		:    Any, lowerCAmelCase__		:    Union[str, Any]							)	->      int:




										'''simple docstring'''



										return gradOutput, None




class  _a						(      _lowerCAmelCase				):






				@staticmethod
				def 				snake_case	( lowerCAmelCase__		:    torch.tensor, lowerCAmelCase__		:    float							)	->      Dict:




										'''simple docstring'''



										_UpperCamelCase			:					List[Any]     =    inputs.clone()
										_UpperCamelCase   ,							_UpperCamelCase			:					Optional[int]     =    inputs.abs().flatten().sort(descending=lowerCAmelCase__							)
										_UpperCamelCase			:					List[Any]     =    int(threshold * inputs.numel()							)

										# flat_out and mask access the same memory.
										_UpperCamelCase			:					List[str]     =    mask.flatten()
										_UpperCamelCase			:					List[Any]     =    0
										_UpperCamelCase			:					str     =    1
										return mask



