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

     UpperCamelCase__      :		Tuple       							=  "0.12"  # assumed parallelism: 8


if is_torch_available():
     import torch
def    lowerCAmelCase_	(				SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_=None						)     ->     Union[str, Any]:




   """simple docstring"""
   if rng is None:
      _SCREAMING_SNAKE_CASE      =				random.Random()

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

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

   _SCREAMING_SNAKE_CASE      =				np.array(_lowerCAmelCase    ,      dtype=jnp.intaa						).reshape(_lowerCAmelCase						)

   return output
def    lowerCAmelCase_	(				SCREAMING_SNAKE_CASE_    ,      SCREAMING_SNAKE_CASE_=None						)     ->     int:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE      =				ids_tensor(_lowerCAmelCase    ,      vocab_size=2    ,      rng=_lowerCAmelCase						)
   # make sure that at least one token is attended to for each batch
   _SCREAMING_SNAKE_CASE      =				1
   return attn_mask

@require_flax
class    _a				:
       SCREAMING_SNAKE_CASE      =  None
       SCREAMING_SNAKE_CASE      =  ()






       def        UpperCamelCase				(							self      )    ->			List[str]:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self.model_tester.prepare_config_and_inputs_for_common()

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

          _SCREAMING_SNAKE_CASE      =				jnp.ones_like(_lowerCamelCase      )
          _SCREAMING_SNAKE_CASE      =				attention_mask[:max_batch_size, :sequence_length]

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






       @is_pt_flax_cross_test
       def        UpperCamelCase				(							self      )    ->			Any:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				False
          _SCREAMING_SNAKE_CASE      =				max_length
          _SCREAMING_SNAKE_CASE      =				0

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				flax_model.generate(_lowerCamelCase      ).sequences
             _SCREAMING_SNAKE_CASE      =				pt_model.generate(torch.tensor(_lowerCamelCase       ,							dtype=torch.long      )      )

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

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






       def        UpperCamelCase				(							self      )    ->			Tuple:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				False
          _SCREAMING_SNAKE_CASE      =				max_length

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			Union[str, Any]:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				True
          _SCREAMING_SNAKE_CASE      =				max_length

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			int:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				False
          _SCREAMING_SNAKE_CASE      =				max_length
          _SCREAMING_SNAKE_CASE      =				2

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			Union[str, Any]:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				False
          _SCREAMING_SNAKE_CASE      =				max_length
          _SCREAMING_SNAKE_CASE      =				2
          _SCREAMING_SNAKE_CASE      =				2

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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






       def        UpperCamelCase				(							self      )    ->			Tuple:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				True
          _SCREAMING_SNAKE_CASE      =				max_length
          _SCREAMING_SNAKE_CASE      =				0.8
          _SCREAMING_SNAKE_CASE      =				10
          _SCREAMING_SNAKE_CASE      =				0.3
          _SCREAMING_SNAKE_CASE      =				1
          _SCREAMING_SNAKE_CASE      =				8
          _SCREAMING_SNAKE_CASE      =				9

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			List[Any]:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				max_length
          _SCREAMING_SNAKE_CASE      =				1
          _SCREAMING_SNAKE_CASE      =				8
          _SCREAMING_SNAKE_CASE      =				9

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			Tuple:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()
          _SCREAMING_SNAKE_CASE      =				max_length
          _SCREAMING_SNAKE_CASE      =				2
          _SCREAMING_SNAKE_CASE      =				1
          _SCREAMING_SNAKE_CASE      =				8
          _SCREAMING_SNAKE_CASE      =				9

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			str:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()

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

          _SCREAMING_SNAKE_CASE      =				False
          _SCREAMING_SNAKE_CASE      =				max_length

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase       ,							attention_mask=_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			str:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()

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

          _SCREAMING_SNAKE_CASE      =				True
          _SCREAMING_SNAKE_CASE      =				max_length

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase       ,							attention_mask=_lowerCamelCase      ).sequences

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






       def        UpperCamelCase				(							self      )    ->			Tuple:
          _SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE ,							_SCREAMING_SNAKE_CASE      =				self._get_input_ids_and_config()

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

          _SCREAMING_SNAKE_CASE      =				2
          _SCREAMING_SNAKE_CASE      =				max_length

          for model_class in self.all_generative_model_classes:
             _SCREAMING_SNAKE_CASE      =				model_class(_lowerCamelCase      )

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

             _SCREAMING_SNAKE_CASE      =				jit(model.generate      )
             _SCREAMING_SNAKE_CASE      =				jit_generate(_lowerCamelCase       ,							attention_mask=_lowerCamelCase      ).sequences

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






@require_flax
class    _a				(unittest.TestCase):






       def        UpperCamelCase				(							self      )    ->			List[str]:
          _SCREAMING_SNAKE_CASE      =				AutoTokenizer.from_pretrained("""hf-internal-testing/tiny-bert"""      )
          _SCREAMING_SNAKE_CASE      =				FlaxAutoModelForCausalLM.from_pretrained("""hf-internal-testing/tiny-bert-flax-only"""      )

          _SCREAMING_SNAKE_CASE      =				"""Hello world"""
          _SCREAMING_SNAKE_CASE      =				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"""      ):
             _SCREAMING_SNAKE_CASE      =				{"""foo""": """bar"""}
             model.generate(_lowerCamelCase       ,							**_lowerCamelCase      )








'''simple docstring'''



import sys

UpperCamelCase__      :		int       							=  (
    "73167176531330624919225119674426574742355349194934"
    "96983520312774506326239578318016984801869478851843"
    "85861560789112949495459501737958331952853208805511"
    "12540698747158523863050715693290963295227443043557"
    "66896648950445244523161731856403098711121722383113"
    "62229893423380308135336276614282806444486645238749"
    "30358907296290491560440772390713810515859307960866"
    "70172427121883998797908792274921901699720888093776"
    "65727333001053367881220235421809751254540594752243"
    "52584907711670556013604839586446706324415722155397"
    "53697817977846174064955149290862569321978468622482"
    "83972241375657056057490261407972968652414535100474"
    "82166370484403199890008895243450658541227588666881"
    "16427171479924442928230863465674813919123162824586"
    "17866458359124566529476545682848912883142607690042"
    "24219022671055626321111109370544217506941658960408"
    "07198403850962455444362981230987879927244284909188"
    "84580156166097919133875499200524063689912560717606"
    "05886116467109405077541002256983155200055935729725"
    "71636269561882670428252483600823257530420752963450"
)
def    lowerCAmelCase_	(				SCREAMING_SNAKE_CASE_ = N						)     ->     int:




   """simple docstring"""
   _SCREAMING_SNAKE_CASE      =				-sys.maxsize - 1
   for i in range(len(SCREAMING_SNAKE_CASE_						) - 12						):
      _SCREAMING_SNAKE_CASE      =				1
      for j in range(13						):
         product *= int(n[i + j]						)
      if product > largest_product:
         _SCREAMING_SNAKE_CASE      =				product
   return largest_product


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






