





'''simple docstring'''


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 		UpperCamelCase__     (       unittest.TestCase							):
      '''simple docstring'''






      @slow
      def 	snake_case  (     self )				->  Optional[Any]:
        __lowerCAmelCase		:    str			     =  CamembertModel.from_pretrained('camembert-base' )
        model.to(SCREAMING_SNAKE_CASE )

        __lowerCAmelCase		:    List[Any]			     =  torch.tensor(
            [[5, 1_21, 11, 6_60, 16, 7_30, 2_55_43, 1_10, 83, 6]]     , device=SCREAMING_SNAKE_CASE     , dtype=torch.long     , )  # J'aime le camembert !
        with torch.no_grad():
          __lowerCAmelCase		:    Union[str, Any]			     =  model(SCREAMING_SNAKE_CASE )['last_hidden_state']
        __lowerCAmelCase		:    List[Any]			     =  torch.Size((1, 10, 7_68) )
        self.assertEqual(output.shape     , SCREAMING_SNAKE_CASE )
        # compare the actual values for a slice.
        __lowerCAmelCase		:    Union[str, Any]			     =  torch.tensor(
            [[[-0.0_2_5_4, 0.0_2_3_5, 0.1_0_2_7], [0.0_6_0_6, -0.1_8_1_1, -0.0_4_1_8], [-0.1_5_6_1, -0.1_1_2_7, 0.2_6_8_7]]]     , device=SCREAMING_SNAKE_CASE     , 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]     , SCREAMING_SNAKE_CASE     , atol=1e-4 ) )












'''simple docstring'''


from __future__ import annotations




def       A							(      _UpperCAmelCase   :				list					)  ->				int | float:


  '''simple docstring'''




  __lowerCAmelCase		:    List[Any]			     =  sorted(_UpperCAmelCase					)
  __lowerCAmelCase		:    List[str]			     =  len(_UpperCAmelCase					)
  __lowerCAmelCase		:    Any			     =  length >> 1
  return (
      (sorted_list[mid_index] + sorted_list[mid_index - 1]) / 2
      if length % 2 == 0
      else sorted_list[mid_index]
  )




def       A							(      )  ->				Union[str, Any]:


  '''simple docstring'''




  import doctest

  doctest.testmod()


if __name__ == "__main__":
    main()





