





'''simple docstring'''


from __future__ import annotations

import unittest

from transformers import XGLMConfig, XGLMTokenizer, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
       import tensorflow as tf

       from transformers.models.xglm.modeling_tf_xglm import (
           TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST,
           TFXGLMForCausalLM,
           TFXGLMModel,
       )

@require_tf
class    lowerCAmelCase_		:

 '''simple docstring'''





 __lowerCamelCase						:							Dict         =					XGLMConfig
 __lowerCamelCase						:							int         =					{}
 __lowerCamelCase						:							Dict         =					"gelu"




 def __init__(	self			,     _lowerCAmelCase			,     _lowerCAmelCase=14			,     _lowerCAmelCase=7			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=True			,     _lowerCAmelCase=99			,     _lowerCAmelCase=32			,     _lowerCAmelCase=2			,     _lowerCAmelCase=4			,     _lowerCAmelCase=37			,     _lowerCAmelCase="gelu"			,     _lowerCAmelCase=0.1			,     _lowerCAmelCase=0.1			,     _lowerCAmelCase=512			,     _lowerCAmelCase=0.02			,     )    ->							Union[str, Any]:
     _lowerCAmelCase				=      parent
     _lowerCAmelCase				=      batch_size
     _lowerCAmelCase				=      seq_length
     _lowerCAmelCase				=      is_training
     _lowerCAmelCase				=      use_input_mask
     _lowerCAmelCase				=      use_labels
     _lowerCAmelCase				=      vocab_size
     _lowerCAmelCase				=      d_model
     _lowerCAmelCase				=      num_hidden_layers
     _lowerCAmelCase				=      num_attention_heads
     _lowerCAmelCase				=      ffn_dim
     _lowerCAmelCase				=      activation_function
     _lowerCAmelCase				=      activation_dropout
     _lowerCAmelCase				=      attention_dropout
     _lowerCAmelCase				=      max_position_embeddings
     _lowerCAmelCase				=      initializer_range
     _lowerCAmelCase				=      None
     _lowerCAmelCase				=      0
     _lowerCAmelCase				=      2
     _lowerCAmelCase				=      1




 def 							_snake_case   (	self		)    ->							Optional[int]:
     return XGLMConfig.from_pretrained("facebook/xglm-564M"		)




 def 							_snake_case   (	self		)    ->							int:
     _lowerCAmelCase				=      tf.clip_by_value(
         ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size		)			,     clip_value_min=0			,     clip_value_max=3		)

     _lowerCAmelCase				=      None
     if self.use_input_mask:
         _lowerCAmelCase				=      random_attention_mask([self.batch_size, self.seq_length]		)

     _lowerCAmelCase				=      self.get_config()

     _lowerCAmelCase				=      floats_tensor([self.num_hidden_layers, self.num_attention_heads]			,     2		)

     return (
         config,
         input_ids,
         input_mask,
         head_mask,
     )




 def 							_snake_case   (	self		)    ->							Tuple:
     return XGLMConfig(
         vocab_size=self.vocab_size			,     d_model=self.hidden_size			,     num_layers=self.num_hidden_layers			,     attention_heads=self.num_attention_heads			,     ffn_dim=self.ffn_dim			,     activation_function=self.activation_function			,     activation_dropout=self.activation_dropout			,     attention_dropout=self.attention_dropout			,     max_position_embeddings=self.max_position_embeddings			,     initializer_range=self.initializer_range			,     use_cache=_lowerCAmelCase			,     bos_token_id=self.bos_token_id			,     eos_token_id=self.eos_token_id			,     pad_token_id=self.pad_token_id			,     return_dict=_lowerCAmelCase			,     )





 def 							_snake_case   (	self		)    ->							str:
     _lowerCAmelCase				=      self.prepare_config_and_inputs()

     (
         (
         _lowerCAmelCase			
     )			,			(
         _lowerCAmelCase			
     )			,			(
         _lowerCAmelCase			
     )			,			(
         _lowerCAmelCase			
     )			,						
     )				=      config_and_inputs

     _lowerCAmelCase				=      {
         "input_ids": input_ids,
         "head_mask": head_mask,
     }

     return config, inputs_dict







@require_tf
class    lowerCAmelCase_		(		__magic_name__						,__magic_name__						,unittest.TestCase		):

 '''simple docstring'''





 __lowerCamelCase						:							Optional[int]         =					(TFXGLMModel, TFXGLMForCausalLM) if is_tf_available() else ()
 __lowerCamelCase						:							str         =					(TFXGLMForCausalLM,) if is_tf_available() else ()
 __lowerCamelCase						:							List[str]         =					(
     {"feature-extraction": TFXGLMModel, "text-generation": TFXGLMForCausalLM} if is_tf_available() else {}
 )
 __lowerCamelCase						:							Optional[int]         =					False
 __lowerCamelCase						:							List[str]         =					False
 __lowerCamelCase						:							Any         =					False




 def 							_snake_case   (	self		)    ->							List[Any]:
     _lowerCAmelCase				=      TFXGLMModelTester(self		)
     _lowerCAmelCase				=      ConfigTester(self			,     config_class=_lowerCAmelCase			,     n_embd=37		)




 def 							_snake_case   (	self		)    ->							Optional[int]:
     self.config_tester.run_common_tests()




 @slow
 def 							_snake_case   (	self		)    ->							List[str]:
     for model_name in TF_XGLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _lowerCAmelCase				=      TFXGLMModel.from_pretrained(_lowerCAmelCase		)
         self.assertIsNotNone(_lowerCAmelCase		)





 @unittest.skip(reason="Currently, model embeddings are going to undergo a major refactor."		)
 def 							_snake_case   (	self		)    ->							List[Any]:
     super().test_resize_token_embeddings()







@require_tf
class    lowerCAmelCase_		(		unittest.TestCase		):

 '''simple docstring'''





 @slow
 def 							_snake_case   (	self			,     _lowerCAmelCase=True		)    ->							Any:
     _lowerCAmelCase				=      TFXGLMForCausalLM.from_pretrained("facebook/xglm-564M"		)
     _lowerCAmelCase				=      tf.convert_to_tensor([[2, 268, 9865]]			,     dtype=tf.intaa		)  # The dog
     # </s> The dog is a very friendly dog. He is very affectionate and loves to play with other
     # fmt: off
     _lowerCAmelCase				=      [2, 268, 9865, 67, 11, 1988, 57252, 9865, 5, 984, 67, 1988, 213838, 1658, 53, 70446, 33, 6657, 278, 1581]
     # fmt: on
     _lowerCAmelCase				=      model.generate(_lowerCAmelCase			,     do_sample=_lowerCAmelCase			,     num_beams=1		)
     if verify_outputs:
         self.assertListEqual(output_ids[0].numpy().tolist()			,     _lowerCAmelCase		)




 @slow
 def 							_snake_case   (	self		)    ->							str:
     _lowerCAmelCase				=      XGLMTokenizer.from_pretrained("facebook/xglm-564M"		)
     _lowerCAmelCase				=      TFXGLMForCausalLM.from_pretrained("facebook/xglm-564M"		)

     tf.random.set_seed(0		)
     _lowerCAmelCase				=      tokenizer("Today is a nice day and"			,     return_tensors="tf"		)
     _lowerCAmelCase				=      tokenized.input_ids
     # forces the generation to happen on CPU, to avoid GPU-related quirks (and assure same output regardless of the available devices)
     with tf.device(":/CPU:0"		):
         _lowerCAmelCase				=      model.generate(_lowerCAmelCase			,     do_sample=_lowerCAmelCase			,     seed=[7, 0]		)
     _lowerCAmelCase				=      tokenizer.decode(output_ids[0]			,     skip_special_tokens=_lowerCAmelCase		)

     _lowerCAmelCase				=      (
         "Today is a nice day and warm evening here over Southern Alberta!! Today when they closed schools due"
     )
     self.assertEqual(_lowerCAmelCase			,     _lowerCAmelCase		)





 @slow
 def 							_snake_case   (	self		)    ->							List[Any]:
     _lowerCAmelCase				=      TFXGLMForCausalLM.from_pretrained("facebook/xglm-564M"		)
     _lowerCAmelCase				=      XGLMTokenizer.from_pretrained("facebook/xglm-564M"		)

     _lowerCAmelCase				=      "left"

     # use different length sentences to test batching
     _lowerCAmelCase				=      [
         "This is an extremelly long sentence that only exists to test the ability of the model to cope with "
         "left-padding, such as in batched generation. The output for the sequence below should be the same "
         "regardless of whether left padding is applied or not. When",
         "Hello, my dog is a little",
     ]

     _lowerCAmelCase				=      tokenizer(_lowerCAmelCase			,     return_tensors="tf"			,     padding=_lowerCAmelCase		)
     _lowerCAmelCase				=      inputs["input_ids"]

     _lowerCAmelCase				=      model.generate(input_ids=_lowerCAmelCase			,     attention_mask=inputs["attention_mask"]			,     max_new_tokens=12		)

     _lowerCAmelCase				=      tokenizer(sentences[0]			,     return_tensors="tf"		).input_ids
     _lowerCAmelCase				=      model.generate(input_ids=_lowerCAmelCase			,     max_new_tokens=12		)

     _lowerCAmelCase				=      tokenizer(sentences[1]			,     return_tensors="tf"		).input_ids
     _lowerCAmelCase				=      model.generate(input_ids=_lowerCAmelCase			,     max_new_tokens=12		)

     _lowerCAmelCase				=      tokenizer.batch_decode(_lowerCAmelCase			,     skip_special_tokens=_lowerCAmelCase		)
     _lowerCAmelCase				=      tokenizer.decode(output_non_padded[0]			,     skip_special_tokens=_lowerCAmelCase		)
     _lowerCAmelCase				=      tokenizer.decode(output_padded[0]			,     skip_special_tokens=_lowerCAmelCase		)

     _lowerCAmelCase				=      [
         "This is an extremelly long sentence that only exists to test the ability of the model to cope with "
         "left-padding, such as in batched generation. The output for the sequence below should be the same "
         "regardless of whether left padding is applied or not. When left padding is applied, the sequence will be "
         "a single",
         "Hello, my dog is a little bit of a shy one, but he is very friendly",
     ]
     self.assertListEqual(_lowerCAmelCase			,     _lowerCAmelCase		)
     self.assertListEqual(_lowerCAmelCase			,     [non_padded_sentence, padded_sentence]		)









'''simple docstring'''


from __future__ import annotations


def 	__a(SCREAMING_SNAKE_CASE_  :					list[float]		,       SCREAMING_SNAKE_CASE_  :					list[float]    ):



    '''simple docstring'''





    _lowerCAmelCase				=      sorted(numsa + numsa    )
    _lowerCAmelCase			,			_lowerCAmelCase				=      divmod(len(SCREAMING_SNAKE_CASE_    )		,       2    )
    if mod == 1:
        return all_numbers[div]
    else:
        return (all_numbers[div] + all_numbers[div - 1]) / 2


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       _SCREAMING_SNAKE_CASE	 =							[float(x) for x in input("Enter the elements of first array: ").split()]
       _SCREAMING_SNAKE_CASE	 =							[float(x) for x in input("Enter the elements of second array: ").split()]
       print(f'''The median of two arrays is: {median_of_two_arrays(array_a, array_a)}''')


