





def 	lowerCAmelCase_					(						__UpperCAmelCase:    int	,     __UpperCAmelCase:    int   )   ->			int:
    return int((input_a, input_a).count(0   ) != 0   )




def 	lowerCAmelCase_					(						)   ->			None:
    assert nand_gate(0	,     0   ) == 1
    assert nand_gate(0	,     1   ) == 1
    assert nand_gate(1	,     0   ) == 1
    assert nand_gate(1	,     1   ) == 0


if __name__ == "__main__":
  print(nand_gate(0, 0))
  print(nand_gate(0, 1))
  print(nand_gate(1, 0))
  print(nand_gate(1, 1))








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_  							=				'0.12'  # assumed parallelism: 8


if is_torch_available():
  import torch




def 	lowerCAmelCase_					(						__UpperCAmelCase:    Dict	,     __UpperCAmelCase:    Tuple	,     __UpperCAmelCase:    Optional[Any]=None   )   ->			Union[str, Any]:
    if rng is None:
        UpperCamelCase__							:       Tuple      =   random.Random()

    UpperCamelCase__							:       List[str]      =   1
    for dim in shape:
        total_dims *= dim

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

    UpperCamelCase__							:       Any      =   np.array(__UpperCAmelCase	,     dtype=jnp.intaa   ).reshape(__UpperCAmelCase   )

    return output




def 	lowerCAmelCase_					(						__UpperCAmelCase:    Optional[int]	,     __UpperCAmelCase:    Optional[int]=None   )   ->			Any:
    UpperCamelCase__							:       Any      =   ids_tensor(__UpperCAmelCase	,     vocab_size=2	,     rng=__UpperCAmelCase   )
    # make sure that at least one token is attended to for each batch
    UpperCamelCase__							:       Tuple      =   1
    return attn_mask






@require_flax
class 					lowercase__ :

   '''simple docstring'''


   a		:							Optional[int]     	=	None
   a		:							Union[str, Any]     	=	()




   def    UpperCamelCase__						(					self							)				->   str:






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__							:       Tuple      =   self.model_tester.prepare_config_and_inputs_for_common()

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

       UpperCamelCase__							:       Tuple      =   jnp.ones_like(__magic_name__							)
       UpperCamelCase__							:       Any      =   attention_mask[:max_batch_size, :sequence_length]

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




   @is_pt_flax_cross_test
   def    UpperCamelCase__						(					self							)				->   List[str]:






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Optional[int]      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       Optional[int]      =   False
       UpperCamelCase__							:       Optional[int]      =   max_length
       UpperCamelCase__							:       Dict      =   0

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       str      =   model_class(__magic_name__							)

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

           UpperCamelCase__							:       Optional[int]      =   flax_model.generate(__magic_name__							).sequences
           UpperCamelCase__							:       Union[str, Any]      =   pt_model.generate(torch.tensor(__magic_name__,	dtype=torch.long							)							)

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

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




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






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       List[Any]      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       Dict      =   False
       UpperCamelCase__							:       List[str]      =   max_length

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       Dict      =   model_class(__magic_name__							)

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

           UpperCamelCase__							:       int      =   jit(model.generate							)
           UpperCamelCase__							:       Optional[Any]      =   jit_generate(__magic_name__							).sequences

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




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






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Union[str, Any]      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       Optional[int]      =   True
       UpperCamelCase__							:       List[str]      =   max_length

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       Dict      =   model_class(__magic_name__							)

           UpperCamelCase__							:       Dict      =   model.generate(__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[-1],	__magic_name__							)

           UpperCamelCase__							:       Optional[Any]      =   jit(model.generate							)
           UpperCamelCase__							:       Optional[int]      =   jit_generate(__magic_name__							).sequences

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




   def    UpperCamelCase__						(					self							)				->   Dict:






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Optional[Any]      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       List[str]      =   False
       UpperCamelCase__							:       Dict      =   max_length
       UpperCamelCase__							:       str      =   2

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       Optional[int]      =   model_class(__magic_name__							)

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

           UpperCamelCase__							:       str      =   jit(model.generate							)
           UpperCamelCase__							:       int      =   jit_generate(__magic_name__							).sequences

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




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






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Any      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       Tuple      =   False
       UpperCamelCase__							:       Union[str, Any]      =   max_length
       UpperCamelCase__							:       Optional[Any]      =   2
       UpperCamelCase__							:       List[Any]      =   2

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       List[str]      =   model_class(__magic_name__							)

           UpperCamelCase__							:       List[str]      =   model.generate(__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[0],	input_ids.shape[0] * config.num_return_sequences							)




   def    UpperCamelCase__						(					self							)				->   Dict:






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

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       int      =   model_class(__magic_name__							)

           UpperCamelCase__							:       Union[str, Any]      =   model.generate(__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[-1],	__magic_name__							)

           UpperCamelCase__							:       Any      =   jit(model.generate							)
           UpperCamelCase__							:       List[Any]      =   jit_generate(__magic_name__							).sequences

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




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






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Optional[int]      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       Any      =   max_length
       UpperCamelCase__							:       str      =   1
       UpperCamelCase__							:       Dict      =   8
       UpperCamelCase__							:       List[Any]      =   9

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       Union[str, Any]      =   model_class(__magic_name__							)

           UpperCamelCase__							:       Optional[int]      =   model.generate(__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[-1],	__magic_name__							)

           UpperCamelCase__							:       Dict      =   jit(model.generate							)
           UpperCamelCase__							:       int      =   jit_generate(__magic_name__							).sequences

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




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






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       int      =   self._get_input_ids_and_config()
       UpperCamelCase__							:       Dict      =   max_length
       UpperCamelCase__							:       List[Any]      =   2
       UpperCamelCase__							:       Dict      =   1
       UpperCamelCase__							:       int      =   8
       UpperCamelCase__							:       List[Any]      =   9

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       Union[str, Any]      =   model_class(__magic_name__							)

           UpperCamelCase__							:       Union[str, Any]      =   model.generate(__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[-1],	__magic_name__							)

           UpperCamelCase__							:       Optional[Any]      =   jit(model.generate							)
           UpperCamelCase__							:       Any      =   jit_generate(__magic_name__							).sequences

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




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






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Optional[Any]      =   self._get_input_ids_and_config()

       # pad attention mask on the left
       UpperCamelCase__							:       Optional[int]      =   attention_mask.at[(0, 0)].set(0							)

       UpperCamelCase__							:       Tuple      =   False
       UpperCamelCase__							:       str      =   max_length

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       int      =   model_class(__magic_name__							)

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

           UpperCamelCase__							:       str      =   jit(model.generate							)
           UpperCamelCase__							:       Optional[Any]      =   jit_generate(__magic_name__,	attention_mask=__magic_name__							).sequences

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




   def    UpperCamelCase__						(					self							)				->   Tuple:






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       List[str]      =   self._get_input_ids_and_config()

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

       UpperCamelCase__							:       Any      =   True
       UpperCamelCase__							:       Union[str, Any]      =   max_length

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       Union[str, Any]      =   model_class(__magic_name__							)

           UpperCamelCase__							:       Optional[Any]      =   model.generate(__magic_name__,	attention_mask=__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[-1],	__magic_name__							)

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

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




   def    UpperCamelCase__						(					self							)				->   int:






       """simple docstring"""
       UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__     ,UpperCamelCase__							:       Optional[int]      =   self._get_input_ids_and_config()

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

       UpperCamelCase__							:       Optional[Any]      =   2
       UpperCamelCase__							:       List[str]      =   max_length

       for model_class in self.all_generative_model_classes:
           UpperCamelCase__							:       int      =   model_class(__magic_name__							)

           UpperCamelCase__							:       Any      =   model.generate(__magic_name__,	attention_mask=__magic_name__							).sequences
           self.assertEqual(generation_outputs.shape[-1],	__magic_name__							)

           UpperCamelCase__							:       Tuple      =   jit(model.generate							)
           UpperCamelCase__							:       int      =   jit_generate(__magic_name__,	attention_mask=__magic_name__							).sequences

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






@require_flax
class 					lowercase__ (			unittest.TestCase       ):

   '''simple docstring'''


   def    UpperCamelCase__						(					self							)				->   Tuple:






       """simple docstring"""
       UpperCamelCase__							:       List[str]      =   AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-bert'''							)
       UpperCamelCase__							:       Any      =   FlaxAutoModelForCausalLM.from_pretrained('''hf-internal-testing/tiny-bert-flax-only'''							)

       UpperCamelCase__							:       int      =   '''Hello world'''
       UpperCamelCase__							:       Tuple      =   tokenizer(__magic_name__,	return_tensors='''np'''							).input_ids

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

       # arbitrary arguments that will not be used anywhere are also not accepted
       with self.assertRaisesRegex(__magic_name__,	'''foo'''							):
           UpperCamelCase__							:       Optional[Any]      =   {'''foo''': '''bar'''}
           model.generate(__magic_name__,	**__magic_name__							)

