

import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
     import torch


@is_pipeline_test
class  A						(							unittest.TestCase ):







    """simple docstring"""





    lowerCamelCase			=							MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
    lowerCamelCase			=							TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING


    def 						snake_case__     (      self :       List[Any],lowercase_ :       Union[str, Any],lowercase_ :       int,lowercase_ :       Dict		)->    Any:





        '''simple docstring'''







        A__          =   TextaTextGenerationPipeline(model=lowercase_,tokenizer=lowercase_		)
        return generator, ["Something to write", "Something else"]


    def 						snake_case__     (      self :       int,lowercase_ :       List[str],lowercase_ :       List[Any]		)->    Optional[int]:





        '''simple docstring'''







        A__          =   generator('Something there'		)
        self.assertEqual(lowercase_,[{'generated_text': ANY(lowercase_		)}]		)
        # These are encoder decoder, they don't just append to incoming string
        self.assertFalse(outputs[0]['generated_text'].startswith('Something there'		)		)

        A__          =   generator(['This is great !', 'Something else'],num_return_sequences=2,do_sample=lowercase_		)
        self.assertEqual(
            lowercase_,[
                [{'generated_text': ANY(lowercase_		)}, {'generated_text': ANY(lowercase_		)}],
                [{'generated_text': ANY(lowercase_		)}, {'generated_text': ANY(lowercase_		)}],
            ],)

        A__          =   generator(
            ['This is great !', 'Something else'],num_return_sequences=2,batch_size=2,do_sample=lowercase_		)
        self.assertEqual(
            lowercase_,[
                [{'generated_text': ANY(lowercase_		)}, {'generated_text': ANY(lowercase_		)}],
                [{'generated_text': ANY(lowercase_		)}, {'generated_text': ANY(lowercase_		)}],
            ],)

        with self.assertRaises(lowercase_		):
            generator(4		)


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





        '''simple docstring'''







        A__          =   pipeline('text2text-generation',model='patrickvonplaten/t5-tiny-random',framework='pt'		)
        # do_sample=False necessary for reproducibility
        A__          =   generator('Something there',do_sample=lowercase_		)
        self.assertEqual(lowercase_,[{'generated_text': ''}]		)

        A__          =   3
        A__          =   generator(
            'Something there',num_return_sequences=lowercase_,num_beams=lowercase_,)
        A__          =   [
            {'generated_text': 'Beide Beide Beide Beide Beide Beide Beide Beide Beide'},
            {'generated_text': 'Beide Beide Beide Beide Beide Beide Beide Beide'},
            {'generated_text': ''},
        ]
        self.assertEqual(lowercase_,lowercase_		)

        A__          =   generator('This is a test',do_sample=lowercase_,num_return_sequences=2,return_tensors=lowercase_		)
        self.assertEqual(
            lowercase_,[
                {'generated_token_ids': ANY(torch.Tensor		)},
                {'generated_token_ids': ANY(torch.Tensor		)},
            ],)
        A__          =   generator.model.config.eos_token_id
        A__          =   '<pad>'
        A__          =   generator(
            ['This is a test', 'This is a second test'],do_sample=lowercase_,num_return_sequences=2,batch_size=2,return_tensors=lowercase_,)
        self.assertEqual(
            lowercase_,[
                [
                    {'generated_token_ids': ANY(torch.Tensor		)},
                    {'generated_token_ids': ANY(torch.Tensor		)},
                ],
                [
                    {'generated_token_ids': ANY(torch.Tensor		)},
                    {'generated_token_ids': ANY(torch.Tensor		)},
                ],
            ],)


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





        '''simple docstring'''







        A__          =   pipeline('text2text-generation',model='patrickvonplaten/t5-tiny-random',framework='tf'		)
        # do_sample=False necessary for reproducibility
        A__          =   generator('Something there',do_sample=lowercase_		)
        self.assertEqual(lowercase_,[{'generated_text': ''}]		)




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


lowercase_       		=  logging.get_logger(__name__)

lowercase_       		=  {
    "s-JoL/Open-Llama-V1": "https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json",
}


class  A						(							_UpperCAmelCase ):







    """simple docstring"""





    lowerCamelCase			=							'open-llama'


    def __init__(      self :       Any,lowercase_ :       Optional[int]=1_0_0_0_0_0,lowercase_ :       Union[str, Any]=4_0_9_6,lowercase_ :       Dict=1_1_0_0_8,lowercase_ :       Dict=3_2,lowercase_ :       Optional[int]=3_2,lowercase_ :       Dict="silu",lowercase_ :       Union[str, Any]=2_0_4_8,lowercase_ :       Optional[int]=0.02,lowercase_ :       Dict=1E-6,lowercase_ :       Dict=True,lowercase_ :       List[Any]=0,lowercase_ :       Optional[int]=1,lowercase_ :       str=2,lowercase_ :       str=False,lowercase_ :       str=True,lowercase_ :       int=0.1,lowercase_ :       List[Any]=0.1,lowercase_ :       List[Any]=True,lowercase_ :       Union[str, Any]=True,lowercase_ :       Any=None,**lowercase_ :       List[Any],)->    Tuple:





        '''simple docstring'''







        A__          =   vocab_size
        A__          =   max_position_embeddings
        A__          =   hidden_size
        A__          =   intermediate_size
        A__          =   num_hidden_layers
        A__          =   num_attention_heads
        A__          =   hidden_act
        A__          =   initializer_range
        A__          =   rms_norm_eps
        A__          =   use_cache
        A__          =   kwargs.pop(
            'use_memorry_efficient_attention',lowercase_		)
        A__          =   hidden_dropout_prob
        A__          =   attention_dropout_prob
        A__          =   use_stable_embedding
        A__          =   shared_input_output_embedding
        A__          =   rope_scaling
        self._rope_scaling_validation()

        super().__init__(
            pad_token_id=lowercase_,bos_token_id=lowercase_,eos_token_id=lowercase_,tie_word_embeddings=lowercase_,**lowercase_,)


    def 						snake_case__     (      self :       str		)->    str:





        '''simple docstring'''







        if self.rope_scaling is None:
            return

        if not isinstance(self.rope_scaling,lowercase_		) or len(self.rope_scaling		) != 2:
            raise ValueError(
                '`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '
                F'got {self.rope_scaling}'		)
        A__          =   self.rope_scaling.get('type',lowercase_		)
        A__          =   self.rope_scaling.get('factor',lowercase_		)
        if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
            raise ValueError(
                F'`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}'		)
        if rope_scaling_factor is None or not isinstance(lowercase_,lowercase_		) or rope_scaling_factor <= 1.0:
            raise ValueError(F'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}'		)

