code: 
  
  
  
  
  
  from functools import partial
  from typing import Any, Callable, Dict, List, Type, TypeVar, Union, overload
  
  import torch
  import torch.nn as nn
  import torch.types
  
  
  
  
  def       a__						(		snake_case__				:       Dict	,      snake_case__				:       Optional[int]	,      snake_case__				:       Tuple    ):
  
  
  
  
  
  
    if not inplace:
      _UpperCAmelCase		:       Dict       =    ma + ma
    else:
      ma += ma
  
    return ma
  
  
  
  
  def       a__						(		snake_case__				:       int	,      snake_case__				:       List[str]    ):
    _UpperCAmelCase		:       List[Any]       =    -1 * len(UpperCamelCase__    )
    _UpperCAmelCase		:       Union[str, Any]       =    list(range(len(tensor.shape[:zero_index]    )    )    )
    return tensor.permute(first_inds + [zero_index + i for i in inds]    )
  
  
  
  
  def       a__						(		snake_case__				:       Optional[Any]	,      snake_case__				:       Optional[Any]    ):
    return t.reshape(t.shape[:-no_dims] + (-1,)    )
  
  
  
  
  def       a__						(		snake_case__				:       Optional[Any]	,      snake_case__				:       List[Any]	,      snake_case__				:       Dict	,      snake_case__				:       Union[str, Any] = 1e-4    ):
    _UpperCAmelCase		:       Tuple       =    mask.expand(*value.shape    )
    return torch.sum(mask * value	,      dim=UpperCamelCase__    ) / (eps + torch.sum(UpperCamelCase__	,      dim=UpperCamelCase__    ))
  
  
  
  
  def       a__						(		snake_case__				:       Dict	,      snake_case__				:       int = 2.3125	,      snake_case__				:       Dict = 21.6875	,      snake_case__				:       Optional[Any] = 64    ):
    _UpperCAmelCase		:       Dict       =    torch.linspace(UpperCamelCase__	,      UpperCamelCase__	,      no_bins - 1	,      device=pts.device    )
    _UpperCAmelCase		:       str       =    torch.sqrt(torch.sum((pts.unsqueeze(-2    ) - pts.unsqueeze(-3    )) ** 2	,      dim=-1    )    )
    return torch.bucketize(UpperCamelCase__	,      UpperCamelCase__    )
  
  
  
  
  def       a__						(		snake_case__				:       str	,      snake_case__				:       str    ):
    _UpperCAmelCase		:       Dict       =    dicts[0]
    _UpperCAmelCase		:       Any       =    {}
    for k, v in first.items():
      _UpperCAmelCase		:       Any       =    [d[k] for d in dicts]
      if isinstance(UpperCamelCase__	,      UpperCamelCase__    ):
        _UpperCAmelCase		:       int       =    dict_multimap(UpperCamelCase__	,      UpperCamelCase__    )
      else:
        _UpperCAmelCase		:       Optional[Any]       =    fn(UpperCamelCase__    )
  
    return new_dict
  
  
  
  
  def       a__						(		snake_case__				:       List[str]	,      snake_case__				:       Optional[Any]    ):
    _UpperCAmelCase		:       str       =    v_bins.view(((1,) * len(x.shape    )) + (len(UpperCamelCase__    ),)    )
    _UpperCAmelCase		:       Any       =    x[..., None] - reshaped_bins
    _UpperCAmelCase		:       Union[str, Any]       =    torch.argmin(torch.abs(UpperCamelCase__    )	,      dim=-1    )
    return nn.functional.one_hot(UpperCamelCase__	,      num_classes=len(UpperCamelCase__    )    ).float()
  
  
  
  
  def       a__						(		snake_case__				:       Optional[Any]	,      snake_case__				:       Union[str, Any]	,      snake_case__				:       Dict = 0	,      snake_case__				:       str = 0    ):
    _UpperCAmelCase		:       str       =    []
    for i, s in enumerate(data.shape[:no_batch_dims]    ):
      _UpperCAmelCase		:       int       =    torch.arange(UpperCamelCase__    )
      _UpperCAmelCase		:       Union[str, Any]       =    r.view(*(*((1,) * i), -1, *((1,) * (len(inds.shape    ) - i - 1)))    )
      ranges.append(UpperCamelCase__    )
  
    _UpperCAmelCase		:       Any       =    [slice(UpperCamelCase__    ) for _ in range(len(data.shape    ) - no_batch_dims    )]
    _UpperCAmelCase		:       Any       =    inds
    ranges.extend(UpperCamelCase__    )
    # Matt note: Editing this to get around the behaviour of using a list as an array index changing
    # in recent Numpy versions
    return data[tuple(UpperCamelCase__    )]
  
  
  SCREAMING_SNAKE_CASE__				:    List[Any]         =    TypeVar('T')
  
  
  
  
  def       a__						(		snake_case__				:       Union[str, Any]	,      snake_case__				:       List[str]	,      snake_case__				:       Union[str, Any]    ):
    _UpperCAmelCase		:       Tuple       =    {}
    for k, v in dic.items():
      if isinstance(UpperCamelCase__	,      UpperCamelCase__    ):
        _UpperCAmelCase		:       Any       =    dict_map(UpperCamelCase__	,      UpperCamelCase__	,      UpperCamelCase__    )
      else:
        _UpperCAmelCase		:       str       =    tree_map(UpperCamelCase__	,      UpperCamelCase__	,      UpperCamelCase__    )
  
    return new_dict
  
  
  
  
  @overload
  def       a__						(		snake_case__				:       Optional[int]	,      snake_case__				:       List[Any]	,      snake_case__				:       Union[str, Any]    ):
    ...
  
  
  
  
  @overload
  def       a__						(		snake_case__				:       int	,      snake_case__				:       Optional[int]	,      snake_case__				:       Optional[Any]    ):
    ...
  
  
  
  
  @overload
  def       a__						(		snake_case__				:       str	,      snake_case__				:       Tuple	,      snake_case__				:       List[str]    ):
    ...
  
  
  
  
  @overload
  def       a__						(		snake_case__				:       str	,      snake_case__				:       Dict	,      snake_case__				:       Any    ):
    ...
  
  
  
  
  def       a__						(		snake_case__				:       str	,      snake_case__				:       Optional[int]	,      snake_case__				:       Tuple    ):
  
  
  
  
  
  
    if isinstance(UpperCamelCase__	,      UpperCamelCase__    ):
      return dict_map(UpperCamelCase__	,      UpperCamelCase__	,      UpperCamelCase__    )
    elif isinstance(UpperCamelCase__	,      UpperCamelCase__    ):
      return [tree_map(UpperCamelCase__	,      UpperCamelCase__	,      UpperCamelCase__    ) for x in tree]
    elif isinstance(UpperCamelCase__	,      UpperCamelCase__    ):
      return tuple(tree_map(UpperCamelCase__	,      UpperCamelCase__	,      UpperCamelCase__    ) for x in tree    )
    elif isinstance(UpperCamelCase__	,      UpperCamelCase__    ):
      return fn(UpperCamelCase__    )
    else:
      print(type(UpperCamelCase__    )    )
      raise ValueError("""Not supported"""    )
  
  
  
  
  
  SCREAMING_SNAKE_CASE__				:    int         =    partial(tree_map, leaf_type=torch.Tensor)
  
  
  
  
  
  
style_context: 
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available
  
  
  SCREAMING_SNAKE_CASE__				:    List[str]         =    {
      'configuration_flaubert': ['FLAUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'FlaubertConfig', 'FlaubertOnnxConfig'],
      'tokenization_flaubert': ['FlaubertTokenizer'],
  }
  
  try:
   if not is_torch_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   SCREAMING_SNAKE_CASE__				:    int         =    [
       'FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'FlaubertForMultipleChoice',
       'FlaubertForQuestionAnswering',
       'FlaubertForQuestionAnsweringSimple',
       'FlaubertForSequenceClassification',
       'FlaubertForTokenClassification',
       'FlaubertModel',
       'FlaubertWithLMHeadModel',
       'FlaubertPreTrainedModel',
   ]
  
  try:
   if not is_tf_available():
    raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
   pass
  else:
   SCREAMING_SNAKE_CASE__				:    Dict         =    [
       'TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'TFFlaubertForMultipleChoice',
       'TFFlaubertForQuestionAnsweringSimple',
       'TFFlaubertForSequenceClassification',
       'TFFlaubertForTokenClassification',
       'TFFlaubertModel',
       'TFFlaubertPreTrainedModel',
       'TFFlaubertWithLMHeadModel',
   ]
  
  
  if TYPE_CHECKING:
   from .configuration_flaubert import FLAUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, FlaubertConfig, FlaubertOnnxConfig
   from .tokenization_flaubert import FlaubertTokenizer
  
   try:
    if not is_torch_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .modeling_flaubert import (
        FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        FlaubertForMultipleChoice,
        FlaubertForQuestionAnswering,
        FlaubertForQuestionAnsweringSimple,
        FlaubertForSequenceClassification,
        FlaubertForTokenClassification,
        FlaubertModel,
        FlaubertPreTrainedModel,
        FlaubertWithLMHeadModel,
    )
  
   try:
    if not is_tf_available():
     raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
    pass
   else:
    from .modeling_tf_flaubert import (
        TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFFlaubertForMultipleChoice,
        TFFlaubertForQuestionAnsweringSimple,
        TFFlaubertForSequenceClassification,
        TFFlaubertForTokenClassification,
        TFFlaubertModel,
        TFFlaubertPreTrainedModel,
        TFFlaubertWithLMHeadModel,
    )
  
  else:
   import sys
  
   SCREAMING_SNAKE_CASE__				:    List[Any]         =    _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
  
  
  
  
  
  