


import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate




def 	__lowercase		(  _UpperCamelCase   )			->List[str]:







      """simple docstring"""

      return x + 2







class  __SCREAMING_SNAKE_CASE      (	unittest.TestCase      ):


      def 				__lowerCamelCase	(							self						):
            lowercase	:      Dict          =						'''x = 3'''
            lowercase	:      str          =						{}
            lowercase	:      List[str]          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            assert result == 3
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3}						)

            lowercase	:      Optional[Any]          =						'''x = y'''
            lowercase	:      List[str]          =						{'''y''': 5}
            lowercase	:      Union[str, Any]          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            # evaluate returns the value of the last assignment.
            assert result == 5
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 5, '''y''': 5}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      List[str]          =						'''y = add_two(x)'''
            lowercase	:      Tuple          =						{'''x''': 3}
            lowercase	:      Optional[int]          =						evaluate(lowerCamelCase__							,  {'''add_two''': add_two}							,  state=lowerCamelCase__						)
            assert result == 5
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''y''': 5}						)

            # Won't work without the tool
            with CaptureStdout() as out:
                  lowercase	:      int          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            assert result is None
            assert "tried to execute add_two" in out.out


      def 				__lowerCamelCase	(							self						):
            lowercase	:      List[str]          =						'''x = 3'''
            lowercase	:      List[Any]          =						{}
            lowercase	:      Union[str, Any]          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            assert result == 3
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      str          =						'''test_dict = {\'x\': x, \'y\': add_two(x)}'''
            lowercase	:      Any          =						{'''x''': 3}
            lowercase	:      Optional[Any]          =						evaluate(lowerCamelCase__							,  {'''add_two''': add_two}							,  state=lowerCamelCase__						)
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''y''': 5}						)
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      Union[str, Any]          =						'''x = 3\ny = 5'''
            lowercase	:      Optional[int]          =						{}
            lowercase	:      Union[str, Any]          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            # evaluate returns the value of the last assignment.
            assert result == 5
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''y''': 5}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      Union[str, Any]          =						'''text = f\'This is x: {x}.\''''
            lowercase	:      List[Any]          =						{'''x''': 3}
            lowercase	:      List[Any]          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            # evaluate returns the value of the last assignment.
            assert result == "This is x: 3."
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''text''': '''This is x: 3.'''}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      Optional[int]          =						'''if x <= 3:\n    y = 2\nelse:\n    y = 5'''
            lowercase	:      int          =						{'''x''': 3}
            lowercase	:      str          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            # evaluate returns the value of the last assignment.
            assert result == 2
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''y''': 2}						)

            lowercase	:      Optional[Any]          =						{'''x''': 8}
            lowercase	:      Any          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            # evaluate returns the value of the last assignment.
            assert result == 5
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 8, '''y''': 5}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      Optional[Any]          =						'''test_list = [x, add_two(x)]'''
            lowercase	:      List[str]          =						{'''x''': 3}
            lowercase	:      Any          =						evaluate(lowerCamelCase__							,  {'''add_two''': add_two}							,  state=lowerCamelCase__						)
            self.assertListEqual(lowerCamelCase__							,  [3, 5]						)
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''test_list''': [3, 5]}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      Union[str, Any]          =						'''y = x'''
            lowercase	:      str          =						{'''x''': 3}
            lowercase	:      List[Any]          =						evaluate(lowerCamelCase__							,  {}							,  state=lowerCamelCase__						)
            assert result == 3
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''y''': 3}						)


      def 				__lowerCamelCase	(							self						):
            lowercase	:      int          =						'''test_list = [x, add_two(x)]\ntest_list[1]'''
            lowercase	:      Any          =						{'''x''': 3}
            lowercase	:      List[str]          =						evaluate(lowerCamelCase__							,  {'''add_two''': add_two}							,  state=lowerCamelCase__						)
            assert result == 5
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''test_list''': [3, 5]}						)

            lowercase	:      List[Any]          =						'''test_dict = {\'x\': x, \'y\': add_two(x)}\ntest_dict[\'y\']'''
            lowercase	:      Optional[int]          =						{'''x''': 3}
            lowercase	:      List[Any]          =						evaluate(lowerCamelCase__							,  {'''add_two''': add_two}							,  state=lowerCamelCase__						)
            assert result == 5
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 3, '''test_dict''': {'''x''': 3, '''y''': 5}}						)






      def 				__lowerCamelCase	(							self						):
            lowercase	:      Optional[int]          =						'''x = 0\nfor i in range(3):\n    x = i'''
            lowercase	:      List[Any]          =						{}
            lowercase	:      Any          =						evaluate(lowerCamelCase__							,  {'''range''': range}							,  state=lowerCamelCase__						)
            assert result == 2
            self.assertDictEqual(lowerCamelCase__							,  {'''x''': 2, '''i''': 2}						)


"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase__  :  int						     =	logging.get_logger(__name__)

lowerCAmelCase__  :  str						     =	{
    'facebook/xglm-564M': 'https://huggingface.co/facebook/xglm-564M/resolve/main/config.json',
    # See all XGLM models at https://huggingface.co/models?filter=xglm
}
class 				snake_case       ( __UpperCAmelCase				):




					"""simple docstring"""

					snake_case__				    = "xglm"
					snake_case__				    = ["past_key_values"]

					snake_case__				    = {
					    "num_attention_heads": "attention_heads",
					    "hidden_size": "d_model",
					    "num_hidden_layers": "num_layers",
					}







					def __init__(				self   :	Any    ,lowerCamelCase__   :	Any=256_008    ,lowerCamelCase__   :	Optional[Any]=2_048    ,lowerCamelCase__   :	List[str]=1_024    ,lowerCamelCase__   :	List[str]=4_096    ,lowerCamelCase__   :	Tuple=24    ,lowerCamelCase__   :	Optional[int]=16    ,lowerCamelCase__   :	int="gelu"    ,lowerCamelCase__   :	Dict=0.1    ,lowerCamelCase__   :	int=0.1    ,lowerCamelCase__   :	List[Any]=0.0    ,lowerCamelCase__   :	List[str]=0.0    ,lowerCamelCase__   :	Optional[Any]=0.0_2    ,lowerCamelCase__   :	List[str]=True    ,lowerCamelCase__   :	Optional[Any]=True    ,lowerCamelCase__   :	str=2    ,lowerCamelCase__   :	Dict=1    ,lowerCamelCase__   :	Optional[int]=0    ,lowerCamelCase__   :	Tuple=2    ,**lowerCamelCase__   :	List[Any]    ,):
									UpperCAmelCase__             =							vocab_size
									UpperCAmelCase__             =							max_position_embeddings
									UpperCAmelCase__             =							d_model
									UpperCAmelCase__             =							ffn_dim
									UpperCAmelCase__             =							num_layers
									UpperCAmelCase__             =							attention_heads
									UpperCAmelCase__             =							activation_function
									UpperCAmelCase__             =							dropout
									UpperCAmelCase__             =							attention_dropout
									UpperCAmelCase__             =							activation_dropout
									UpperCAmelCase__             =							layerdrop
									UpperCAmelCase__             =							init_std
									UpperCAmelCase__             =							scale_embedding  # scale factor will be sqrt(d_model) if True
									UpperCAmelCase__             =							use_cache

									super().__init__(
									    pad_token_id=lowerCamelCase__    ,bos_token_id=lowerCamelCase__    ,eos_token_id=lowerCamelCase__    ,decoder_start_token_id=lowerCamelCase__    ,**lowerCamelCase__    ,)



