





"""simple docstring"""



import random
import unittest

import numpy as np

import transformers
from transformers import is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax


if is_flax_available():
       import os

       import jax.numpy as jnp
       from jax import jit

       from transformers import AutoTokenizer, FlaxAutoModelForCausalLM
       from transformers.modeling_flax_pytorch_utils import load_flax_weights_in_pytorch_model

       a_			=      """0.12"""  # assumed parallelism: 8


if is_torch_available():
       import torch







def 		__lowercase					(       snake_case_  :  List[str]    ,snake_case_  :  Any    ,snake_case_  :  int=None						)       ->Dict:



    '''simple docstring'''







    if rng is None:
        __A   :						List[str]									=					random.Random()

    __A   :						List[Any]									=					1
    for dim in shape:
        total_dims *= dim

    __A   :						Union[str, Any]									=					[]
    for _ in range(snake_case_						):
        values.append(rng.randint(0    ,vocab_size - 1						)						)

    __A   :						List[Any]									=					np.array(snake_case_    ,dtype=jnp.intaa						).reshape(snake_case_						)

    return output







def 		__lowercase					(       snake_case_  :  Any    ,snake_case_  :  Tuple=None						)       ->Union[str, Any]:



    '''simple docstring'''







    __A   :						List[Any]									=					ids_tensor(snake_case_    ,vocab_size=2    ,rng=snake_case_						)
    # make sure that at least one token is attended to for each batch
    __A   :						List[str]									=					1
    return attn_mask






@require_flax
class 		__snake_case :





 """simple docstring"""


 _lowerCamelCase				=					None
 _lowerCamelCase				=					()

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A   :						Optional[int]									=					self.model_tester.prepare_config_and_inputs_for_common()

     # cut to half length & take max batch_size 3
     __A   :						Dict									=					2
     __A   :						int									=					inputs['''input_ids'''].shape[-1] // 2
     __A   :						Union[str, Any]									=					inputs['''input_ids'''][:max_batch_size, :sequence_length]

     __A   :						Union[str, Any]									=					jnp.ones_like(__lowerCamelCase  )
     __A   :						Dict									=					attention_mask[:max_batch_size, :sequence_length]

     # generate max 5 tokens
     __A   :						str									=					input_ids.shape[-1] + 5
     if config.eos_token_id is not None and config.pad_token_id is None:
         # hack to allow generate for models such as GPT2 as is done in `generate()`
         __A   :						List[Any]									=					config.eos_token_id
     return config, input_ids, attention_mask, max_length

 @is_pt_flax_cross_test
 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						int									=					self._get_input_ids_and_config()
     __A   :						Any									=					False
     __A   :						Any									=					max_length
     __A   :						int									=					0

     for model_class in self.all_generative_model_classes:
         __A   :						Optional[int]									=					model_class(__lowerCamelCase  )

         __A   :						str									=					model_class.__name__[4:]  # Skip the "Flax" at the beginning
         __A   :						Union[str, Any]									=					getattr(__lowerCamelCase ,						__lowerCamelCase  )
         __A   :						str									=					pt_model_class(__lowerCamelCase  ).eval()
         __A   :						List[Any]									=					load_flax_weights_in_pytorch_model(__lowerCamelCase ,						flax_model.params  )

         __A   :						List[Any]									=					flax_model.generate(__lowerCamelCase  ).sequences
         __A   :						Any									=					pt_model.generate(torch.tensor(__lowerCamelCase ,						dtype=torch.long  )  )

         if flax_generation_outputs.shape[-1] > pt_generation_outputs.shape[-1]:
             __A   :						Any									=					flax_generation_outputs[:, : pt_generation_outputs.shape[-1]]

         self.assertListEqual(pt_generation_outputs.numpy().tolist() ,						flax_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						List[Any]									=					self._get_input_ids_and_config()
     __A   :						Union[str, Any]									=					False
     __A   :						int									=					max_length

     for model_class in self.all_generative_model_classes:
         __A   :						List[str]									=					model_class(__lowerCamelCase  )

         __A   :						List[str]									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						Tuple									=					jit(model.generate  )
         __A   :						Optional[Any]									=					jit_generate(__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						Optional[int]									=					self._get_input_ids_and_config()
     __A   :						Any									=					True
     __A   :						Dict									=					max_length

     for model_class in self.all_generative_model_classes:
         __A   :						List[str]									=					model_class(__lowerCamelCase  )

         __A   :						int									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						Dict									=					jit(model.generate  )
         __A   :						str									=					jit_generate(__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						List[Any]									=					self._get_input_ids_and_config()
     __A   :						List[Any]									=					False
     __A   :						List[str]									=					max_length
     __A   :						Dict									=					2

     for model_class in self.all_generative_model_classes:
         __A   :						str									=					model_class(__lowerCamelCase  )

         __A   :						Optional[Any]									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						List[str]									=					jit(model.generate  )
         __A   :						Union[str, Any]									=					jit_generate(__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						int									=					self._get_input_ids_and_config()
     __A   :						Union[str, Any]									=					False
     __A   :						List[Any]									=					max_length
     __A   :						Union[str, Any]									=					2
     __A   :						List[Any]									=					2

     for model_class in self.all_generative_model_classes:
         __A   :						Any									=					model_class(__lowerCamelCase  )

         __A   :						Union[str, Any]									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[0] ,						input_ids.shape[0] * config.num_return_sequences  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						List[str]									=					self._get_input_ids_and_config()
     __A   :						Any									=					True
     __A   :						List[Any]									=					max_length
     __A   :						Union[str, Any]									=					0.8
     __A   :						Optional[Any]									=					10
     __A   :						Union[str, Any]									=					0.3
     __A   :						Dict									=					1
     __A   :						Union[str, Any]									=					8
     __A   :						Optional[int]									=					9

     for model_class in self.all_generative_model_classes:
         __A   :						List[Any]									=					model_class(__lowerCamelCase  )

         __A   :						List[str]									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						str									=					jit(model.generate  )
         __A   :						str									=					jit_generate(__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						Optional[int]									=					self._get_input_ids_and_config()
     __A   :						int									=					max_length
     __A   :						Union[str, Any]									=					1
     __A   :						List[Any]									=					8
     __A   :						int									=					9

     for model_class in self.all_generative_model_classes:
         __A   :						Tuple									=					model_class(__lowerCamelCase  )

         __A   :						List[Any]									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						Optional[int]									=					jit(model.generate  )
         __A   :						Tuple									=					jit_generate(__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						Dict									=					self._get_input_ids_and_config()
     __A   :						List[str]									=					max_length
     __A   :						List[str]									=					2
     __A   :						Any									=					1
     __A   :						int									=					8
     __A   :						int									=					9

     for model_class in self.all_generative_model_classes:
         __A   :						Optional[int]									=					model_class(__lowerCamelCase  )

         __A   :						str									=					model.generate(__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						Union[str, Any]									=					jit(model.generate  )
         __A   :						str									=					jit_generate(__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						Union[str, Any]									=					self._get_input_ids_and_config()

     # pad attention mask on the left
     __A   :						Union[str, Any]									=					attention_mask.at[(0, 0)].set(0  )

     __A   :						Dict									=					False
     __A   :						List[Any]									=					max_length

     for model_class in self.all_generative_model_classes:
         __A   :						Tuple									=					model_class(__lowerCamelCase  )

         __A   :						List[Any]									=					model.generate(__lowerCamelCase ,						attention_mask=__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						List[str]									=					jit(model.generate  )
         __A   :						str									=					jit_generate(__lowerCamelCase ,						attention_mask=__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )

 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						Tuple									=					self._get_input_ids_and_config()

     # pad attention mask on the left
     __A   :						List[Any]									=					attention_mask.at[(0, 0)].set(0  )

     __A   :						List[Any]									=					True
     __A   :						Optional[int]									=					max_length

     for model_class in self.all_generative_model_classes:
         __A   :						Tuple									=					model_class(__lowerCamelCase  )

         __A   :						str									=					model.generate(__lowerCamelCase ,						attention_mask=__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						Optional[Any]									=					jit(model.generate  )
         __A   :						int									=					jit_generate(__lowerCamelCase ,						attention_mask=__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )







 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A			,	__A			,	__A			,	__A   :						Optional[Any]									=					self._get_input_ids_and_config()

     # pad attention mask on the left
     __A   :						Tuple									=					attention_mask.at[(0, 0)].set(0  )

     __A   :						List[Any]									=					2
     __A   :						Tuple									=					max_length

     for model_class in self.all_generative_model_classes:
         __A   :						int									=					model_class(__lowerCamelCase  )

         __A   :						List[str]									=					model.generate(__lowerCamelCase ,						attention_mask=__lowerCamelCase  ).sequences
         self.assertEqual(generation_outputs.shape[-1] ,						__lowerCamelCase  )

         __A   :						str									=					jit(model.generate  )
         __A   :						Union[str, Any]									=					jit_generate(__lowerCamelCase ,						attention_mask=__lowerCamelCase  ).sequences

         self.assertListEqual(generation_outputs.tolist() ,						jit_generation_outputs.tolist()  )






@require_flax
class 		__snake_case (		unittest.TestCase					):





 """simple docstring"""


 def  UpperCamelCase__(   self  ):



     '''simple docstring'''




     __A   :						List[Any]									=					AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-bert'''  )
     __A   :						Optional[Any]									=					FlaxAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-bert-flax-only'''  )

     __A   :						Tuple									=					'''Hello world'''
     __A   :						int									=					tokenizer(__lowerCamelCase ,						return_tensors='''np'''  ).input_ids

     # typos are quickly detected (the correct argument is `do_sample`)
     with self.assertRaisesRegex(__lowerCamelCase ,						'''do_samples'''  ):
         model.generate(__lowerCamelCase ,						do_samples=__lowerCamelCase  )

     # arbitrary arguments that will not be used anywhere are also not accepted
     with self.assertRaisesRegex(__lowerCamelCase ,						'''foo'''  ):
         __A   :						Tuple									=					{'''foo''': '''bar'''}
         model.generate(__lowerCamelCase ,						**__lowerCamelCase  )











"""simple docstring"""



def 		__lowercase					(       )       ->Tuple:



    '''simple docstring'''







    __A   :						str									=					[]
    __A   :						List[Any]									=					1

    while len(snake_case_						) < 1e6:
        constant.append(str(snake_case_						)						)
        i += 1

    __A   :						Any									=					''''''.join(snake_case_						)

    return (
        int(constant[0]						)
        * int(constant[9]						)
        * int(constant[99]						)
        * int(constant[999]						)
        * int(constant[9999]						)
        * int(constant[99999]						)
        * int(constant[999999]						)
    )


if __name__ == "__main__":
       print(solution())




