





'''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

   lowercase__						:      Optional[int]	=    '0.12'  # assumed parallelism: 8


if is_torch_available():
   import torch







def  a__    (    lowercase :					str, lowercase :					Union[str, Any], lowercase :					Optional[Any]=None				)		->		List[str]:





     """simple docstring"""

     if rng is None:
          _UpperCamelCase       =	random.Random()

     _UpperCamelCase       =	1
     for dim in shape:
          total_dims *= dim

     _UpperCamelCase       =	[]
     for _ in range(lowercase				):
          values.append(rng.randint(0, vocab_size - 1				)				)

     _UpperCamelCase       =	np.array(lowercase, dtype=jnp.intaa				).reshape(lowercase				)

     return output







def  a__    (    lowercase :					int, lowercase :					Optional[int]=None				)		->		Union[str, Any]:





     """simple docstring"""

     _UpperCamelCase       =	ids_tensor(lowercase, vocab_size=2, rng=lowercase				)
     # make sure that at least one token is attended to for each batch
     _UpperCamelCase       =	1
     return attn_mask
@require_flax
class     __lowerCAmelCase					:






       """simple docstring"""
       _snake_case     :					Any						    =   None
       _snake_case     :					int						    =   ()





       def snake_case__						(							self       :		Dict					)   ->					Dict:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase       =	self.model_tester.prepare_config_and_inputs_for_common()

            # cut to half length & take max batch_size 3
            _UpperCamelCase       =	2
            _UpperCamelCase       =	inputs['''input_ids'''].shape[-1] // 2
            _UpperCamelCase       =	inputs['''input_ids'''][:max_batch_size, :sequence_length]

            _UpperCamelCase       =	jnp.ones_like(lowerCAmelCase__					)
            _UpperCamelCase       =	attention_mask[:max_batch_size, :sequence_length]

            # generate max 5 tokens
            _UpperCamelCase       =	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()`
                 _UpperCamelCase       =	config.eos_token_id
            return config, input_ids, attention_mask, max_length





       @is_pt_flax_cross_test
       def snake_case__						(							self       :		str					)   ->					Dict:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	False
            _UpperCamelCase       =	max_length
            _UpperCamelCase       =	0

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model_class.__name__[4:]  # Skip the "Flax" at the beginning
                 _UpperCamelCase       =	getattr(lowerCAmelCase__	,			lowerCAmelCase__					)
                 _UpperCamelCase       =	pt_model_class(lowerCAmelCase__					).eval()
                 _UpperCamelCase       =	load_flax_weights_in_pytorch_model(lowerCAmelCase__	,			flax_model.params					)

                 _UpperCamelCase       =	flax_model.generate(lowerCAmelCase__					).sequences
                 _UpperCamelCase       =	pt_model.generate(torch.tensor(lowerCAmelCase__	,			dtype=torch.long					)					)

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

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





       def snake_case__						(							self       :		Optional[int]					)   ->					Tuple:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	False
            _UpperCamelCase       =	max_length

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__					).sequences

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





       def snake_case__						(							self       :		Optional[Any]					)   ->					Optional[int]:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	True
            _UpperCamelCase       =	max_length

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__					).sequences

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





       def snake_case__						(							self       :		int					)   ->					Optional[Any]:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	False
            _UpperCamelCase       =	max_length
            _UpperCamelCase       =	2

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__					).sequences

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





       def snake_case__						(							self       :		Tuple					)   ->					List[Any]:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	False
            _UpperCamelCase       =	max_length
            _UpperCamelCase       =	2
            _UpperCamelCase       =	2

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[0]	,			input_ids.shape[0] * config.num_return_sequences					)





       def snake_case__						(							self       :		Any					)   ->					Any:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	True
            _UpperCamelCase       =	max_length
            _UpperCamelCase       =	0.8
            _UpperCamelCase       =	10
            _UpperCamelCase       =	0.3
            _UpperCamelCase       =	1
            _UpperCamelCase       =	8
            _UpperCamelCase       =	9

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__					).sequences

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





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

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	max_length
            _UpperCamelCase       =	1
            _UpperCamelCase       =	8
            _UpperCamelCase       =	9

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__					).sequences

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





       def snake_case__						(							self       :		Tuple					)   ->					int:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()
            _UpperCamelCase       =	max_length
            _UpperCamelCase       =	2
            _UpperCamelCase       =	1
            _UpperCamelCase       =	8
            _UpperCamelCase       =	9

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__					).sequences

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





       def snake_case__						(							self       :		str					)   ->					Any:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()

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

            _UpperCamelCase       =	False
            _UpperCamelCase       =	max_length

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__	,			attention_mask=lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__	,			attention_mask=lowerCAmelCase__					).sequences

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





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

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()

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

            _UpperCamelCase       =	True
            _UpperCamelCase       =	max_length

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__	,			attention_mask=lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__	,			attention_mask=lowerCAmelCase__					).sequences

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







       def snake_case__						(							self       :		List[str]					)   ->					str:

            '''simple docstring'''




            _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase       =	self._get_input_ids_and_config()

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

            _UpperCamelCase       =	2
            _UpperCamelCase       =	max_length

            for model_class in self.all_generative_model_classes:
                 _UpperCamelCase       =	model_class(lowerCAmelCase__					)

                 _UpperCamelCase       =	model.generate(lowerCAmelCase__	,			attention_mask=lowerCAmelCase__					).sequences
                 self.assertEqual(generation_outputs.shape[-1]	,			lowerCAmelCase__					)

                 _UpperCamelCase       =	jit(model.generate					)
                 _UpperCamelCase       =	jit_generate(lowerCAmelCase__	,			attention_mask=lowerCAmelCase__					).sequences

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

@require_flax
class     __lowerCAmelCase					(   unittest.TestCase			):






       """simple docstring"""





       def snake_case__						(							self       :		Optional[Any]					)   ->					List[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-bert'''					)
            _UpperCamelCase       =	FlaxAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-bert-flax-only'''					)

            _UpperCamelCase       =	'''Hello world'''
            _UpperCamelCase       =	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'''					):
                 _UpperCamelCase       =	{'''foo''': '''bar'''}
                 model.generate(lowerCAmelCase__	,			**lowerCAmelCase__					)










'''simple docstring'''

def  a__    (    lowercase :					int, lowercase :					int				)		->		int:





     """simple docstring"""

     return x if y == 0 else greatest_common_divisor(lowercase, x % y				)







def  a__    (    lowercase :					int, lowercase :					int				)		->		int:





     """simple docstring"""

     return (x * y) // greatest_common_divisor(lowercase, lowercase				)







def  a__    (    lowercase :					int = 20				)		->		int:





     """simple docstring"""

     _UpperCamelCase       =	1
     for i in range(1, n + 1				):
          _UpperCamelCase       =	lcm(lowercase, lowercase				)
     return g


if __name__ == "__main__":
   print(F"""{solution() = }""")



