
import numpy as np

from transformers import Pipeline




def        __UpperCamelCase					(    lowerCAmelCase__							:    str  ):
 __a			:  str		    =  np.max(lowerCAmelCase__  ,       axis=-1  ,       keepdims=lowerCAmelCase__  )
 __a			:  str		    =  np.exp(outputs - maxes  )
 return shifted_exp / shifted_exp.sum(axis=-1  ,       keepdims=lowerCAmelCase__  )



class 		UpperCamelCase__  (	__lowercase   ):
   def 				lowerCAmelCase      (self			: Union[str, Any] ,    **snake_case_			: List[str]       ):
    __a			:  Any		    =  {}
    if "second_text" in kwargs:
     __a			:  Optional[int]		    =  kwargs['''second_text''']
    return preprocess_kwargs, {}, {}
   def 				lowerCAmelCase      (self			: Optional[int] ,    snake_case_			: List[Any] ,    snake_case_			: Dict=None       ):
    return self.tokenizer(snake_case_ ,    text_pair=snake_case_ ,    return_tensors=self.framework       )
   def 				lowerCAmelCase      (self			: List[str] ,    snake_case_			: int       ):
    return self.model(**snake_case_       )







   def 				lowerCAmelCase      (self			: int ,    snake_case_			: Dict       ):
    __a			:  Dict		    =  model_outputs.logits[0].numpy()
    __a			:  Tuple		    =  softmax(snake_case_       )

    __a			:  int		    =  np.argmax(snake_case_       )
    __a			:  int		    =  self.model.config.idalabel[best_class]
    __a			:  Optional[int]		    =  probabilities[best_class].item()
    __a			:  str		    =  logits.tolist()
    return {"label": label, "score": score, "logits": logits}


import os
import sys
import unittest


lowercase__          =os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, 'utils'))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


lowercase__          =os.path.join('tests', 'models', 'bert', 'test_modeling_bert.py')
lowercase__          =os.path.join('tests', 'models', 'blip', 'test_modeling_blip.py')



class 		UpperCamelCase__  (	unittest.TestCase   ):
   def 				lowerCAmelCase      (self			: List[Any]       ):
    __a			:  str		    =  get_test_to_tester_mapping(snake_case_       )
    __a			:  Tuple		    =  get_test_to_tester_mapping(snake_case_       )

    __a			:  Union[str, Any]		    =  {'''BertModelTest''': '''BertModelTester'''}

    __a			:  Tuple		    =  {
        '''BlipModelTest''': '''BlipModelTester''',
        '''BlipTextImageModelTest''': '''BlipTextImageModelsModelTester''',
        '''BlipTextModelTest''': '''BlipTextModelTester''',
        '''BlipTextRetrievalModelTest''': '''BlipTextRetrievalModelTester''',
        '''BlipVQAModelTest''': '''BlipVQAModelTester''',
        '''BlipVisionModelTest''': '''BlipVisionModelTester''',
    }

    self.assertEqual(get_test_info.to_json(snake_case_       ) ,    snake_case_       )
    self.assertEqual(get_test_info.to_json(snake_case_       ) ,    snake_case_       )
   def 				lowerCAmelCase      (self			: str       ):
    __a			:  Optional[int]		    =  get_model_to_test_mapping(snake_case_       )
    __a			:  Any		    =  get_model_to_test_mapping(snake_case_       )

    __a			:  List[Any]		    =  {
        '''BertForMaskedLM''': ['''BertModelTest'''],
        '''BertForMultipleChoice''': ['''BertModelTest'''],
        '''BertForNextSentencePrediction''': ['''BertModelTest'''],
        '''BertForPreTraining''': ['''BertModelTest'''],
        '''BertForQuestionAnswering''': ['''BertModelTest'''],
        '''BertForSequenceClassification''': ['''BertModelTest'''],
        '''BertForTokenClassification''': ['''BertModelTest'''],
        '''BertLMHeadModel''': ['''BertModelTest'''],
        '''BertModel''': ['''BertModelTest'''],
    }

    __a			:  Dict		    =  {
        '''BlipForConditionalGeneration''': ['''BlipTextImageModelTest'''],
        '''BlipForImageTextRetrieval''': ['''BlipTextRetrievalModelTest'''],
        '''BlipForQuestionAnswering''': ['''BlipVQAModelTest'''],
        '''BlipModel''': ['''BlipModelTest'''],
        '''BlipTextModel''': ['''BlipTextModelTest'''],
        '''BlipVisionModel''': ['''BlipVisionModelTest'''],
    }

    self.assertEqual(get_test_info.to_json(snake_case_       ) ,    snake_case_       )
    self.assertEqual(get_test_info.to_json(snake_case_       ) ,    snake_case_       )







   def 				lowerCAmelCase      (self			: int       ):
    __a			:  Any		    =  get_model_to_tester_mapping(snake_case_       )
    __a			:  List[str]		    =  get_model_to_tester_mapping(snake_case_       )

    __a			:  Any		    =  {
        '''BertForMaskedLM''': ['''BertModelTester'''],
        '''BertForMultipleChoice''': ['''BertModelTester'''],
        '''BertForNextSentencePrediction''': ['''BertModelTester'''],
        '''BertForPreTraining''': ['''BertModelTester'''],
        '''BertForQuestionAnswering''': ['''BertModelTester'''],
        '''BertForSequenceClassification''': ['''BertModelTester'''],
        '''BertForTokenClassification''': ['''BertModelTester'''],
        '''BertLMHeadModel''': ['''BertModelTester'''],
        '''BertModel''': ['''BertModelTester'''],
    }

    __a			:  int		    =  {
        '''BlipForConditionalGeneration''': ['''BlipTextImageModelsModelTester'''],
        '''BlipForImageTextRetrieval''': ['''BlipTextRetrievalModelTester'''],
        '''BlipForQuestionAnswering''': ['''BlipVQAModelTester'''],
        '''BlipModel''': ['''BlipModelTester'''],
        '''BlipTextModel''': ['''BlipTextModelTester'''],
        '''BlipVisionModel''': ['''BlipVisionModelTester'''],
    }

    self.assertEqual(get_test_info.to_json(snake_case_       ) ,    snake_case_       )
    self.assertEqual(get_test_info.to_json(snake_case_       ) ,    snake_case_       )
