



'''simple docstring'''





import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
  from transformers.models.roberta.modeling_flax_roberta import (
      FlaxRobertaForCausalLM,
      FlaxRobertaForMaskedLM,
      FlaxRobertaForMultipleChoice,
      FlaxRobertaForQuestionAnswering,
      FlaxRobertaForSequenceClassification,
      FlaxRobertaForTokenClassification,
      FlaxRobertaModel,
  )






class __A     (    unittest.TestCase		):



 '''simple docstring'''







 def __init__(self					,  A					,  A=13					,  A=7					,  A=True					,  A=True					,  A=True					,  A=True					,  A=99					,  A=32					,  A=5					,  A=4					,  A=37					,  A="gelu"					,  A=0.1					,  A=0.1					,  A=512					,  A=16					,  A=2					,  A=0.02					,  A=4					,  )       ->	Optional[int]:


      """simple docstring"""



      _a           =    parent
      _a           =    batch_size
      _a           =    seq_length
      _a           =    is_training
      _a           =    use_attention_mask
      _a           =    use_token_type_ids
      _a           =    use_labels
      _a           =    vocab_size
      _a           =    hidden_size
      _a           =    num_hidden_layers
      _a           =    num_attention_heads
      _a           =    intermediate_size
      _a           =    hidden_act
      _a           =    hidden_dropout_prob
      _a           =    attention_probs_dropout_prob
      _a           =    max_position_embeddings
      _a           =    type_vocab_size
      _a           =    type_sequence_label_size
      _a           =    initializer_range
      _a           =    num_choices



 def    a__    (self			)       ->	Tuple:


      """simple docstring"""



      _a           =    ids_tensor([self.batch_size, self.seq_length]					,  self.vocab_size			)

      _a           =    None
      if self.use_attention_mask:
           _a           =    random_attention_mask([self.batch_size, self.seq_length]			)

      _a           =    None
      if self.use_token_type_ids:
           _a           =    ids_tensor([self.batch_size, self.seq_length]					,  self.type_vocab_size			)

      _a           =    RobertaConfig(
          vocab_size=self.vocab_size					,  hidden_size=self.hidden_size					,  num_hidden_layers=self.num_hidden_layers					,  num_attention_heads=self.num_attention_heads					,  intermediate_size=self.intermediate_size					,  hidden_act=self.hidden_act					,  hidden_dropout_prob=self.hidden_dropout_prob					,  attention_probs_dropout_prob=self.attention_probs_dropout_prob					,  max_position_embeddings=self.max_position_embeddings					,  type_vocab_size=self.type_vocab_size					,  is_decoder=A					,  initializer_range=self.initializer_range					,  )

      return config, input_ids, token_type_ids, attention_mask



 def    a__    (self			)       ->	Tuple:


      """simple docstring"""



      _a           =    self.prepare_config_and_inputs()
      _a    ,       _a    ,       _a    ,       _a           =    config_and_inputs
      _a           =    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
      return config, inputs_dict



 def    a__    (self			)       ->	Optional[int]:


      """simple docstring"""



      _a           =    self.prepare_config_and_inputs()
      _a    ,       _a    ,       _a    ,       _a           =    config_and_inputs

      _a           =    True
      _a           =    floats_tensor([self.batch_size, self.seq_length, self.hidden_size]			)
      _a           =    ids_tensor([self.batch_size, self.seq_length]					,  vocab_size=2			)

      return (
          config,
          input_ids,
          token_type_ids,
          encoder_hidden_states,
          encoder_attention_mask,
      )






@require_flax
class __A     (    A  ,  unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase       :			str		=			True

 __lowerCamelCase       :			int		=			(
     (
         FlaxRobertaModel,
         FlaxRobertaForCausalLM,
         FlaxRobertaForMaskedLM,
         FlaxRobertaForSequenceClassification,
         FlaxRobertaForTokenClassification,
         FlaxRobertaForMultipleChoice,
         FlaxRobertaForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )



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


      """simple docstring"""



      _a           =    FlaxRobertaModelTester(self			)



 @slow
 def    a__    (self			)       ->	Tuple:


      """simple docstring"""



      for model_class_name in self.all_model_classes:
           _a           =    model_class_name.from_pretrained('''roberta-base'''					,  from_pt=A			)
           _a           =    model(np.ones((1, 1)			)			)
           self.assertIsNotNone(A			)








'''simple docstring'''





import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin






class __A     (    A  ,  unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase       :			Union[str, Any]		=			CTRLTokenizer
 __lowerCamelCase       :			Union[str, Any]		=			False
 __lowerCamelCase       :			Any		=			False



 def    a__    (self			)       ->	Optional[int]:


      """simple docstring"""



      super().setUp()

      # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
      _a           =    ['''adapt''', '''re@@''', '''a@@''', '''apt''', '''c@@''', '''t''', '''<unk>''']
      _a           =    dict(zip(A					,  range(len(A			)			)			)			)
      _a           =    ['''#version: 0.2''', '''a p''', '''ap t</w>''', '''r e''', '''a d''', '''ad apt</w>''', '''''']
      _a           =    {'''unk_token''': '''<unk>'''}

      _a           =    os.path.join(self.tmpdirname					,  VOCAB_FILES_NAMES['''vocab_file''']			)
      _a           =    os.path.join(self.tmpdirname					,  VOCAB_FILES_NAMES['''merges_file''']			)
      with open(self.vocab_file					,  '''w'''					,  encoding='''utf-8'''			) as fp:
           fp.write(json.dumps(A			) + '''\n'''			)
      with open(self.merges_file					,  '''w'''					,  encoding='''utf-8'''			) as fp:
           fp.write('''\n'''.join(A			)			)



 def    a__    (self					,  **A			)       ->	int:


      """simple docstring"""



      kwargs.update(self.special_tokens_map			)
      return CTRLTokenizer.from_pretrained(self.tmpdirname					,  **A			)



 def    a__    (self					,  A			)       ->	Tuple:


      """simple docstring"""



      _a           =    '''adapt react readapt apt'''
      _a           =    '''adapt react readapt apt'''
      return input_text, output_text



 def    a__    (self			)       ->	List[Any]:


      """simple docstring"""



      _a           =    CTRLTokenizer(self.vocab_file					,  self.merges_file					,  **self.special_tokens_map			)
      _a           =    '''adapt react readapt apt'''
      _a           =    '''adapt re@@ a@@ c@@ t re@@ adapt apt'''.split()
      _a           =    tokenizer.tokenize(A			)
      self.assertListEqual(A					,  A			)

      _a           =    tokens + [tokenizer.unk_token]

      _a           =    [0, 1, 2, 4, 5, 1, 0, 3, 6]
      self.assertListEqual(tokenizer.convert_tokens_to_ids(A			)					,  A			)



