

import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
    import torch

    from transformers import CamembertModel

@require_torch
@require_sentencepiece
@require_tokenizers
class 						__snake_case						(							unittest.TestCase     ):
       """simple docstring"""







       @slow
       def  a		(		self      )			->       str:






              """simple docstring"""


              __snake_case					  =       CamembertModel.from_pretrained("""camembert-base"""      )
              model.to(_UpperCamelCase      )

              __snake_case					  =       torch.tensor(
                  [[5, 1_21, 11, 6_60, 16, 7_30, 2_55_43, 1_10, 83, 6]]			,   device=_UpperCamelCase			,   dtype=torch.long			,   )  # J'aime le camembert !
              with torch.no_grad():
                     __snake_case					  =       model(_UpperCamelCase      )["""last_hidden_state"""]
              __snake_case					  =       torch.Size((1, 10, 7_68)      )
              self.assertEqual(output.shape			,   _UpperCamelCase      )
              # compare the actual values for a slice.
              __snake_case					  =       torch.tensor(
                  [[[-0.0254, 0.0235, 0.1027], [0.0606, -0.1811, -0.0418], [-0.1561, -0.1127, 0.2687]]]			,   device=_UpperCamelCase			,   dtype=torch.float			,   )
              # camembert = torch.hub.load('pytorch/fairseq', 'camembert.v0')
              # camembert.eval()
              # expected_slice = roberta.model.forward(input_ids)[0][:, :3, :3].detach()

              self.assertTrue(torch.allclose(output[:, :3, :3]			,   _UpperCamelCase			,   atol=1E-4      )      )




import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__		   =    logging.get_logger(__name__)

UpperCamelCase__		   =    {
    '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}

class 						__snake_case						(							snake_case__     ):
       """simple docstring"""







       __SCREAMING_SNAKE_CASE													=       "hubert"


       def __init__(		self			,   _UpperCamelCase=32			,   _UpperCamelCase=7_68			,   _UpperCamelCase=12			,   _UpperCamelCase=12			,   _UpperCamelCase=30_72			,   _UpperCamelCase="gelu"			,   _UpperCamelCase=0.1			,   _UpperCamelCase=0.1			,   _UpperCamelCase=0.1			,   _UpperCamelCase=True			,   _UpperCamelCase=0.0			,   _UpperCamelCase=0.1			,   _UpperCamelCase=0.1			,   _UpperCamelCase=0.02			,   _UpperCamelCase=1E-5			,   _UpperCamelCase="group"			,   _UpperCamelCase="gelu"			,   _UpperCamelCase=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)			,   _UpperCamelCase=(5, 2, 2, 2, 2, 2, 2)			,   _UpperCamelCase=(10, 3, 3, 3, 3, 2, 2)			,   _UpperCamelCase=False			,   _UpperCamelCase=1_28			,   _UpperCamelCase=16			,   _UpperCamelCase=False			,   _UpperCamelCase=True			,   _UpperCamelCase=0.05			,   _UpperCamelCase=10			,   _UpperCamelCase=2			,   _UpperCamelCase=0.0			,   _UpperCamelCase=10			,   _UpperCamelCase=0			,   _UpperCamelCase="sum"			,   _UpperCamelCase=False			,   _UpperCamelCase=False			,   _UpperCamelCase=2_56			,   _UpperCamelCase=0			,   _UpperCamelCase=1			,   _UpperCamelCase=2			,   **_UpperCamelCase			,   )			->       Any:






              """simple docstring"""


              super().__init__(**_UpperCamelCase			,   pad_token_id=_UpperCamelCase			,   bos_token_id=_UpperCamelCase			,   eos_token_id=_UpperCamelCase      )
              __snake_case					  =       hidden_size
              __snake_case					  =       feat_extract_norm
              __snake_case					  =       feat_extract_activation
              __snake_case					  =       list(_UpperCamelCase      )
              __snake_case					  =       list(_UpperCamelCase      )
              __snake_case					  =       list(_UpperCamelCase      )
              __snake_case					  =       conv_bias
              __snake_case					  =       num_conv_pos_embeddings
              __snake_case					  =       num_conv_pos_embedding_groups
              __snake_case					  =       len(self.conv_dim      )
              __snake_case					  =       num_hidden_layers
              __snake_case					  =       intermediate_size
              __snake_case					  =       hidden_act
              __snake_case					  =       num_attention_heads
              __snake_case					  =       hidden_dropout
              __snake_case					  =       attention_dropout
              __snake_case					  =       activation_dropout
              __snake_case					  =       feat_proj_layer_norm
              __snake_case					  =       feat_proj_dropout
              __snake_case					  =       final_dropout
              __snake_case					  =       layerdrop
              __snake_case					  =       layer_norm_eps
              __snake_case					  =       initializer_range
              __snake_case					  =       vocab_size
              __snake_case					  =       do_stable_layer_norm
              __snake_case					  =       use_weighted_layer_sum
              __snake_case					  =       classifier_proj_size

              if (
                  (len(self.conv_stride      ) != self.num_feat_extract_layers)
                  or (len(self.conv_kernel      ) != self.num_feat_extract_layers)
                  or (len(self.conv_dim      ) != self.num_feat_extract_layers)
              ):
                     raise ValueError(
                         """Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="""
                         """ `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="""
                         F' {len(self.conv_dim      )}`, `len(config.conv_stride) = {len(self.conv_stride      )}`,'
                         F' `len(config.conv_kernel) = {len(self.conv_kernel      )}`.'      )

              # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
              __snake_case					  =       apply_spec_augment
              __snake_case					  =       mask_time_prob
              __snake_case					  =       mask_time_length
              __snake_case					  =       mask_time_min_masks
              __snake_case					  =       mask_feature_prob
              __snake_case					  =       mask_feature_length
              __snake_case					  =       mask_feature_min_masks

              # ctc loss
              __snake_case					  =       ctc_loss_reduction
              __snake_case					  =       ctc_zero_infinity






       @property
       def  a		(		self      )			->       Union[str, Any]:






              """simple docstring"""


              return functools.reduce(operator.mul			,   self.conv_stride			,   1      )

