






"""simple docstring"""



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


_UpperCamelCase		:  Tuple						=		logging.get_logger(__name__)

_UpperCamelCase		:  Any						=		{
    'tanreinama/GPTSAN-2.8B-spout_is_uniform': (
        'https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json'
    ),
}

class        a     (   a_	):
    UpperCAmelCase_ :     Dict	     ="gptsan-japanese"
    UpperCAmelCase_ :     Optional[Any]	     =[
        "past_key_values",
    ]
    UpperCAmelCase_ :     Dict	     ={
        "hidden_size": "d_model",
        "num_attention_heads": "num_heads",
        "num_hidden_layers": "num_layers",
    }







    def __init__(			self							,		_lowerCamelCase=3_6_0_0_0							,		_lowerCamelCase=1_2_8_0							,		_lowerCamelCase=1_0_2_4							,		_lowerCamelCase=8_1_9_2							,		_lowerCamelCase=4_0_9_6							,		_lowerCamelCase=1_2_8							,		_lowerCamelCase=1_0							,		_lowerCamelCase=0							,		_lowerCamelCase=1_6							,		_lowerCamelCase=1_6							,		_lowerCamelCase=1_2_8							,		_lowerCamelCase=0.0							,		_lowerCamelCase=1e-5							,		_lowerCamelCase=False							,		_lowerCamelCase=0.0							,		_lowerCamelCase="float32"							,		_lowerCamelCase=False							,		_lowerCamelCase=False							,		_lowerCamelCase=False							,		_lowerCamelCase=0.0_0_2							,		_lowerCamelCase=False							,		_lowerCamelCase=True							,		_lowerCamelCase=3_5_9_9_8							,		_lowerCamelCase=3_5_9_9_5							,		_lowerCamelCase=3_5_9_9_9							,		**_lowerCamelCase							,		):
      lowercase							    =       vocab_size
      lowercase							    =       max_position_embeddings
      lowercase							    =       d_model
      lowercase							    =       d_ff
      lowercase							    =       d_ext
      lowercase							    =       d_spout
      lowercase							    =       num_switch_layers
      lowercase							    =       num_ext_layers
      lowercase							    =       num_switch_layers + num_ext_layers
      lowercase							    =       num_heads
      lowercase							    =       num_experts
      lowercase							    =       expert_capacity
      lowercase							    =       dropout_rate
      lowercase							    =       layer_norm_epsilon
      lowercase							    =       router_bias
      lowercase							    =       router_jitter_noise
      lowercase							    =       router_dtype
      lowercase							    =       router_ignore_padding_tokens
      lowercase							    =       output_hidden_states
      lowercase							    =       output_attentions
      lowercase							    =       initializer_factor
      lowercase							    =       output_router_logits
      lowercase							    =       use_cache

      super().__init__(
          separator_token_id=_lowerCamelCase							,		pad_token_id=_lowerCamelCase							,		eos_token_id=_lowerCamelCase							,		**_lowerCamelCase							,		)










"""simple docstring"""



import unittest

from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
    from PIL import Image
else:

    class        a     :







        @staticmethod
        def 			UpperCamelCase_      (			*_lowerCamelCase							,		**_lowerCamelCase       ):
          pass

@is_pipeline_test
@require_torch
@require_vision
class        a     (   unittest.TestCase	):
    UpperCAmelCase_ :     Union[str, Any]	     =MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       pipeline('visual-question-answering'							,		model='hf-internal-testing/tiny-vilt-random-vqa'       )
      lowercase							    =       [
          {
              'image': Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       ),
              'question': 'How many cats are there?',
          },
          {
              'image': './tests/fixtures/tests_samples/COCO/000000039769.png',
              'question': 'How many cats are there?',
          },
      ]
      return vqa_pipeline, examples







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase       ):
      lowercase							    =       vqa_pipeline(_lowerCamelCase							,		top_k=1       )
      self.assertEqual(
          _lowerCamelCase							,		[
              [{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}],
              [{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}],
          ]							,		)







    @require_torch
    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       pipeline('visual-question-answering'							,		model='hf-internal-testing/tiny-vilt-random-vqa'       )
      lowercase							    =       './tests/fixtures/tests_samples/COCO/000000039769.png'
      lowercase							    =       'How many cats are there?'

      lowercase							    =       vqa_pipeline(image=_lowerCamelCase							,		question='How many cats are there?'							,		top_k=2       )
      self.assertEqual(
          _lowerCamelCase							,		[{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}, {'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}]       )

      lowercase							    =       vqa_pipeline({'image': image, 'question': question}							,		top_k=2       )
      self.assertEqual(
          _lowerCamelCase							,		[{'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}, {'score': ANY(_lowerCamelCase       ), 'answer': ANY(_lowerCamelCase       )}]       )







    @slow
    @require_torch
    def 			UpperCamelCase_      (			self       ):
      lowercase							    =       pipeline('visual-question-answering'							,		model='dandelin/vilt-b32-finetuned-vqa'       )
      lowercase							    =       './tests/fixtures/tests_samples/COCO/000000039769.png'
      lowercase							    =       'How many cats are there?'

      lowercase							    =       vqa_pipeline(image=_lowerCamelCase							,		question=_lowerCamelCase							,		top_k=2       )
      self.assertEqual(
          nested_simplify(_lowerCamelCase							,		decimals=4       )							,		[{'score': 0.8_7_9_9, 'answer': '2'}, {'score': 0.2_9_6, 'answer': '1'}]       )

      lowercase							    =       vqa_pipeline({'image': image, 'question': question}							,		top_k=2       )
      self.assertEqual(
          nested_simplify(_lowerCamelCase							,		decimals=4       )							,		[{'score': 0.8_7_9_9, 'answer': '2'}, {'score': 0.2_9_6, 'answer': '1'}]       )

      lowercase							    =       vqa_pipeline(
          [{'image': image, 'question': question}, {'image': image, 'question': question}]							,		top_k=2       )
      self.assertEqual(
          nested_simplify(_lowerCamelCase							,		decimals=4       )							,		[[{'score': 0.8_7_9_9, 'answer': '2'}, {'score': 0.2_9_6, 'answer': '1'}]] * 2							,		)







    @require_tf
    @unittest.skip('Visual question answering not implemented in TF'       )
    def 			UpperCamelCase_      (			self       ):
      pass


