

"""simple docstring"""

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


_UpperCamelCase		     =    logging.get_logger(__name__)

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






class 			__a					(						__magic_name__       ):





       """simple docstring"""


       __UpperCamelCase					:      Any    =						'open-llama'






       def __init__(   self			,					snake_case=100_000			,					snake_case=4_096			,					snake_case=11_008			,					snake_case=32			,					snake_case=32			,					snake_case="silu"			,					snake_case=2_048			,					snake_case=0.02			,					snake_case=1e-6			,					snake_case=True			,					snake_case=0			,					snake_case=1			,					snake_case=2			,					snake_case=False			,					snake_case=True			,					snake_case=0.1			,					snake_case=0.1			,					snake_case=True			,					snake_case=True			,					snake_case=None			,					**snake_case			,					):





        """simple docstring"""

        lowerCAmelCase__   :				int 			=				vocab_size
        lowerCAmelCase__   :				Dict 			=				max_position_embeddings
        lowerCAmelCase__   :				Any 			=				hidden_size
        lowerCAmelCase__   :				Optional[Any] 			=				intermediate_size
        lowerCAmelCase__   :				Any 			=				num_hidden_layers
        lowerCAmelCase__   :				Any 			=				num_attention_heads
        lowerCAmelCase__   :				List[Any] 			=				hidden_act
        lowerCAmelCase__   :				str 			=				initializer_range
        lowerCAmelCase__   :				str 			=				rms_norm_eps
        lowerCAmelCase__   :				int 			=				use_cache
        lowerCAmelCase__   :				str 			=				kwargs.pop(
            "use_memorry_efficient_attention"			,					snake_case   )
        lowerCAmelCase__   :				str 			=				hidden_dropout_prob
        lowerCAmelCase__   :				List[str] 			=				attention_dropout_prob
        lowerCAmelCase__   :				int 			=				use_stable_embedding
        lowerCAmelCase__   :				List[Any] 			=				shared_input_output_embedding
        lowerCAmelCase__   :				Tuple 			=				rope_scaling
        self._rope_scaling_validation()

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






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        if self.rope_scaling is None:
         return

        if not isinstance(self.rope_scaling			,					snake_case   ) 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}"""   )
        lowerCAmelCase__   :				str 			=				self.rope_scaling.get("type"			,					snake_case   )
        lowerCAmelCase__   :				int 			=				self.rope_scaling.get("factor"			,					snake_case   )
        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(snake_case			,					snake_case   ) or rope_scaling_factor <= 1.0:
         raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""   )









"""simple docstring"""

from typing import Union

from ..utils import add_end_docstrings, is_torch_available, is_vision_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
    from PIL import Image

    from ..image_utils import load_image

if is_torch_available():
    from ..models.auto.modeling_auto import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING

_UpperCamelCase		     =    logging.get_logger(__name__)






@add_end_docstrings(__magic_name__       )
class 			__a					(						__magic_name__       ):





       """simple docstring"""


       def __init__(   self			,					*snake_case			,					**snake_case   ):





        """simple docstring"""

        super().__init__(*snake_case			,					**snake_case   )
        self.check_model_type(snake_case   )






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case=None			,					snake_case=None			,					snake_case=None			,					**snake_case   ):





        """simple docstring"""

        lowerCAmelCase__			,						lowerCAmelCase__   :				List[Any] 			=				{}, {}
        if padding is not None:
         lowerCAmelCase__   :				Dict 			=				padding
        if truncation is not None:
         lowerCAmelCase__   :				Tuple 			=				truncation
        if top_k is not None:
         lowerCAmelCase__   :				str 			=				top_k
        return preprocess_params, {}, postprocess_params






       def __call__(   self			,					snake_case			,					snake_case = None			,					**snake_case   ):





        """simple docstring"""

        if isinstance(snake_case			,					(Image.Image, str)   ) and isinstance(snake_case			,					snake_case   ):
         lowerCAmelCase__   :				int 			=				{"image": image, "question": question}
        else:
         lowerCAmelCase__   :				Optional[int] 			=				image
        lowerCAmelCase__   :				Optional[Any] 			=				super().__call__(snake_case			,					**snake_case   )
        return results






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case			,					snake_case=False			,					snake_case=False   ):





        """simple docstring"""

        lowerCAmelCase__   :				Union[str, Any] 			=				load_image(inputs["image"]   )
        lowerCAmelCase__   :				str 			=				self.tokenizer(
            inputs["question"]			,					return_tensors=self.framework			,					padding=snake_case			,					truncation=snake_case   )
        lowerCAmelCase__   :				int 			=				self.image_processor(images=snake_case			,					return_tensors=self.framework   )
        model_inputs.update(snake_case   )
        return model_inputs






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case   ):





        """simple docstring"""

        lowerCAmelCase__   :				Optional[int] 			=				self.model(**snake_case   )
        return model_outputs






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case			,					snake_case=5   ):





        """simple docstring"""

        if top_k > self.model.config.num_labels:
         lowerCAmelCase__   :				List[Any] 			=				self.model.config.num_labels

        if self.framework == "pt":
         lowerCAmelCase__   :				Optional[int] 			=				model_outputs.logits.sigmoid()[0]
         lowerCAmelCase__			,						lowerCAmelCase__   :				Optional[int] 			=				probs.topk(snake_case   )
        else:
         raise ValueError(F"""Unsupported framework: {self.framework}"""   )

        lowerCAmelCase__   :				int 			=				scores.tolist()
        lowerCAmelCase__   :				str 			=				ids.tolist()
        return [{"score": score, "answer": self.model.config.idalabel[_id]} for score, _id in zip(snake_case			,					snake_case   )]






