# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import ast
import difflib
from collections.abc import Mapping
from typing import Any, Callable, Dict

class 						_SCREAMING_SNAKE_CASE				(  _lowercase				):






		"""simple docstring"""







		pass






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_=None				,						lowerCamelCase_=False	):



			"""simple docstring"""





			try:
						_snake_case														=   ast.parse(lowerCamelCase_	)
			except SyntaxError as e:
						print("The code generated by the agent is not valid.\n"				,						lowerCamelCase_	)
						return
			if state is None:
						_snake_case														=   {}
			_snake_case														=   None
			for idx, node in enumerate(expression.body	):
						try:
									_snake_case														=   evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
						except InterpretorError as e:
									_snake_case														=   f'Evaluation of the code stopped at line {idx} before the end because of the following error'
									if chat_mode:
												msg += (
												    f'. Copy paste the following error message and send it back to the agent:\nI get an error: \'{e}\''
												)
									else:
												msg += f':\n{e}'
									print(lowerCamelCase_	)
									break
						if line_result is not None:
									_snake_case														=   line_result

			return result






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			if isinstance(lowerCamelCase_				,						ast.Assign	):
						# Assignement -> we evaluate the assignement which should update the state
						# We return the variable assigned as it may be used to determine the final result.
						return evaluate_assign(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.Call	):
						# Function call -> we return the value of the function call
						return evaluate_call(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.Constant	):
						# Constant -> just return the value
						return expression.value
			elif isinstance(lowerCamelCase_				,						ast.Dict	):
						# Dict -> evaluate all keys and values
						_snake_case														=   [evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	) for k in expression.keys]
						_snake_case														=   [evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	) for v in expression.values]
						return dict(zip(lowerCamelCase_				,						lowerCamelCase_	)	)
			elif isinstance(lowerCamelCase_				,						ast.Expr	):
						# Expression -> evaluate the content
						return evaluate_ast(expression.value				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.For	):
						# For loop -> execute the loop
						return evaluate_for(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.FormattedValue	):
						# Formatted value (part of f-string) -> evaluate the content and return
						return evaluate_ast(expression.value				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.If	):
						# If -> execute the right branch
						return evaluate_if(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif hasattr(lowerCamelCase_				,						"Index"	) and isinstance(lowerCamelCase_				,						ast.Index	):
						return evaluate_ast(expression.value				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.JoinedStr	):
						return "".join([str(evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)	) for v in expression.values]	)
			elif isinstance(lowerCamelCase_				,						ast.List	):
						# List -> evaluate all elements
						return [evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	) for elt in expression.elts]
			elif isinstance(lowerCamelCase_				,						ast.Name	):
						# Name -> pick up the value in the state
						return evaluate_name(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
			elif isinstance(lowerCamelCase_				,						ast.Subscript	):
						# Subscript -> return the value of the indexing
						return evaluate_subscript(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
			else:
						# For now we refuse anything else. Let's add things as we need them.
						raise InterpretorError(f'{expression.__class__.__name__} is not supported.'	)






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			_snake_case														=   assign.targets
			_snake_case														=   evaluate_ast(assign.value				,						lowerCamelCase_				,						lowerCamelCase_	)

			if len(lowerCamelCase_	) == 1:
						_snake_case														=   result
			else:
						if len(lowerCamelCase_	) != len(lowerCamelCase_	):
									raise InterpretorError(f'Expected {len(lowerCamelCase_	)} values but got {len(lowerCamelCase_	)}.'	)
						for var_name, r in zip(lowerCamelCase_				,						lowerCamelCase_	):
									_snake_case														=   r
			return result






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			if not isinstance(call.func				,						ast.Name	):
						raise InterpretorError(
						    f'It is not permitted to evaluate other functions than the provided tools (tried to execute {call.func} of '
						    f'type {type(call.func	)}.'	)
			_snake_case														=   call.func.id
			if func_name not in tools:
						raise InterpretorError(
						    f'It is not permitted to evaluate other functions than the provided tools (tried to execute {call.func.id}).'	)

			_snake_case														=   tools[func_name]
			# Todo deal with args
			_snake_case														=   [evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	) for arg in call.args]
			_snake_case														=   {keyword.arg: evaluate_ast(keyword.value				,						lowerCamelCase_				,						lowerCamelCase_	) for keyword in call.keywords}
			return func(*lowerCamelCase_				,						**lowerCamelCase_	)






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			_snake_case														=   evaluate_ast(subscript.slice				,						lowerCamelCase_				,						lowerCamelCase_	)
			_snake_case														=   evaluate_ast(subscript.value				,						lowerCamelCase_				,						lowerCamelCase_	)
			if isinstance(lowerCamelCase_				,						(list, tuple)	):
						return value[int(lowerCamelCase_	)]
			if index in value:
						return value[index]
			if isinstance(lowerCamelCase_				,						lowerCamelCase_	) and isinstance(lowerCamelCase_				,						lowerCamelCase_	):
						_snake_case														=   difflib.get_close_matches(lowerCamelCase_				,						list(value.keys()	)	)
						if len(lowerCamelCase_	) > 0:
									return value[close_matches[0]]

			raise InterpretorError(f'Could not index {value} with \'{index}\'.'	)






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			if name.id in state:
						return state[name.id]
			_snake_case														=   difflib.get_close_matches(name.id				,						list(state.keys()	)	)
			if len(lowerCamelCase_	) > 0:
						return state[close_matches[0]]
			raise InterpretorError(f'The variable `{name.id}` is not defined.'	)






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			if len(condition.ops	) > 1:
						raise InterpretorError("Cannot evaluate conditions with multiple operators"	)

			_snake_case														=   evaluate_ast(condition.left				,						lowerCamelCase_				,						lowerCamelCase_	)
			_snake_case														=   condition.ops[0]
			_snake_case														=   evaluate_ast(condition.comparators[0]				,						lowerCamelCase_				,						lowerCamelCase_	)

			if isinstance(lowerCamelCase_				,						ast.Eq	):
						return left == right
			elif isinstance(lowerCamelCase_				,						ast.NotEq	):
						return left != right
			elif isinstance(lowerCamelCase_				,						ast.Lt	):
						return left < right
			elif isinstance(lowerCamelCase_				,						ast.LtE	):
						return left <= right
			elif isinstance(lowerCamelCase_				,						ast.Gt	):
						return left > right
			elif isinstance(lowerCamelCase_				,						ast.GtE	):
						return left >= right
			elif isinstance(lowerCamelCase_				,						ast.Is	):
						return left is right
			elif isinstance(lowerCamelCase_				,						ast.IsNot	):
						return left is not right
			elif isinstance(lowerCamelCase_				,						ast.In	):
						return left in right
			elif isinstance(lowerCamelCase_				,						ast.NotIn	):
						return left not in right
			else:
						raise InterpretorError(f'Operator not supported: {comparator}'	)






def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			_snake_case														=   None
			if evaluate_condition(if_statement.test				,						lowerCamelCase_				,						lowerCamelCase_	):
						for line in if_statement.body:
									_snake_case														=   evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
									if line_result is not None:
												_snake_case														=   line_result
			else:
						for line in if_statement.orelse:
									_snake_case														=   evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
									if line_result is not None:
												_snake_case														=   line_result
			return result







def  UpperCAmelCase__(    lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	):



			"""simple docstring"""





			_snake_case														=   None
			_snake_case														=   evaluate_ast(for_loop.iter				,						lowerCamelCase_				,						lowerCamelCase_	)
			for counter in iterator:
						_snake_case														=   counter
						for expression in for_loop.body:
									_snake_case														=   evaluate_ast(lowerCamelCase_				,						lowerCamelCase_				,						lowerCamelCase_	)
									if line_result is not None:
												_snake_case														=   line_result
			return result


import tempfile
import unittest

from transformers import DPRConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import DPRContextEncoder, DPRQuestionEncoder, DPRReader, DPRReaderTokenizer
			from transformers.models.dpr.modeling_dpr import (
			    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
			    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
			    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
			)

class 						_SCREAMING_SNAKE_CASE				:






		"""simple docstring"""







		def __init__(      self     :					List[Any]	,       __SCREAMING_SNAKE_CASE     :					List[Any]	,       __SCREAMING_SNAKE_CASE     :					List[Any]=13	,       __SCREAMING_SNAKE_CASE     :					str=7	,       __SCREAMING_SNAKE_CASE     :					Any=False	,       __SCREAMING_SNAKE_CASE     :					Dict=True	,       __SCREAMING_SNAKE_CASE     :					Any=True	,       __SCREAMING_SNAKE_CASE     :					List[str]=True	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]=99	,       __SCREAMING_SNAKE_CASE     :					Dict=32	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]=5	,       __SCREAMING_SNAKE_CASE     :					Dict=4	,       __SCREAMING_SNAKE_CASE     :					Tuple=37	,       __SCREAMING_SNAKE_CASE     :					List[str]="gelu"	,       __SCREAMING_SNAKE_CASE     :					List[str]=0.1	,       __SCREAMING_SNAKE_CASE     :					Optional[Any]=0.1	,       __SCREAMING_SNAKE_CASE     :					List[Any]=512	,       __SCREAMING_SNAKE_CASE     :					Optional[int]=16	,       __SCREAMING_SNAKE_CASE     :					Any=2	,       __SCREAMING_SNAKE_CASE     :					Dict=0.0_2	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]=3	,       __SCREAMING_SNAKE_CASE     :					int=4	,       __SCREAMING_SNAKE_CASE     :					Optional[Any]=None	,       __SCREAMING_SNAKE_CASE     :					List[Any]=0	,       ):






					"""simple docstring"""
					_snake_case														=   parent
					_snake_case														=   batch_size
					_snake_case														=   seq_length
					_snake_case														=   is_training
					_snake_case														=   use_input_mask
					_snake_case														=   use_token_type_ids
					_snake_case														=   use_labels
					_snake_case														=   vocab_size
					_snake_case														=   hidden_size
					_snake_case														=   num_hidden_layers
					_snake_case														=   num_attention_heads
					_snake_case														=   intermediate_size
					_snake_case														=   hidden_act
					_snake_case														=   hidden_dropout_prob
					_snake_case														=   attention_probs_dropout_prob
					_snake_case														=   max_position_embeddings
					_snake_case														=   type_vocab_size
					_snake_case														=   type_sequence_label_size
					_snake_case														=   initializer_range
					_snake_case														=   num_labels
					_snake_case														=   num_choices
					_snake_case														=   scope
					_snake_case														=   projection_dim



		def 					_a					(      self     :					Tuple ):






					"""simple docstring"""
					_snake_case														=   ids_tensor([self.batch_size, self.seq_length]	,       self.vocab_size )

					_snake_case														=   None
					if self.use_input_mask:
								_snake_case														=   random_attention_mask([self.batch_size, self.seq_length] )

					_snake_case														=   None
					if self.use_token_type_ids:
								_snake_case														=   ids_tensor([self.batch_size, self.seq_length]	,       self.type_vocab_size )

					_snake_case														=   None
					_snake_case														=   None
					_snake_case														=   None
					if self.use_labels:
								_snake_case														=   ids_tensor([self.batch_size]	,       self.type_sequence_label_size )
								_snake_case														=   ids_tensor([self.batch_size, self.seq_length]	,       self.num_labels )
								_snake_case														=   ids_tensor([self.batch_size]	,       self.num_choices )

					_snake_case														=   self.get_config()

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



		def 					_a					(      self     :					List[Any] ):






					"""simple docstring"""
					return DPRConfig(
					    projection_dim=self.projection_dim	,       vocab_size=self.vocab_size	,       hidden_size=self.hidden_size	,       num_hidden_layers=self.num_hidden_layers	,       num_attention_heads=self.num_attention_heads	,       intermediate_size=self.intermediate_size	,       hidden_act=self.hidden_act	,       hidden_dropout_prob=self.hidden_dropout_prob	,       attention_probs_dropout_prob=self.attention_probs_dropout_prob	,       max_position_embeddings=self.max_position_embeddings	,       type_vocab_size=self.type_vocab_size	,       initializer_range=self.initializer_range	,       )



		def 					_a					(      self     :					List[Any]	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]	,       __SCREAMING_SNAKE_CASE     :					List[str]	,       __SCREAMING_SNAKE_CASE     :					List[str]	,       __SCREAMING_SNAKE_CASE     :					List[Any]	,       __SCREAMING_SNAKE_CASE     :					Any	,       __SCREAMING_SNAKE_CASE     :					List[Any]	,       __SCREAMING_SNAKE_CASE     :					List[str] ):






					"""simple docstring"""
					_snake_case														=   DPRContextEncoder(config=__SCREAMING_SNAKE_CASE )
					model.to(__SCREAMING_SNAKE_CASE )
					model.eval()
					_snake_case														=   model(__SCREAMING_SNAKE_CASE	,       attention_mask=__SCREAMING_SNAKE_CASE	,       token_type_ids=__SCREAMING_SNAKE_CASE )
					_snake_case														=   model(__SCREAMING_SNAKE_CASE	,       token_type_ids=__SCREAMING_SNAKE_CASE )
					_snake_case														=   model(__SCREAMING_SNAKE_CASE )
					self.parent.assertEqual(result.pooler_output.shape	,       (self.batch_size, self.projection_dim or self.hidden_size) )



		def 					_a					(      self     :					str	,       __SCREAMING_SNAKE_CASE     :					Optional[Any]	,       __SCREAMING_SNAKE_CASE     :					List[str]	,       __SCREAMING_SNAKE_CASE     :					List[str]	,       __SCREAMING_SNAKE_CASE     :					List[str]	,       __SCREAMING_SNAKE_CASE     :					Dict	,       __SCREAMING_SNAKE_CASE     :					Optional[Any]	,       __SCREAMING_SNAKE_CASE     :					str ):






					"""simple docstring"""
					_snake_case														=   DPRQuestionEncoder(config=__SCREAMING_SNAKE_CASE )
					model.to(__SCREAMING_SNAKE_CASE )
					model.eval()
					_snake_case														=   model(__SCREAMING_SNAKE_CASE	,       attention_mask=__SCREAMING_SNAKE_CASE	,       token_type_ids=__SCREAMING_SNAKE_CASE )
					_snake_case														=   model(__SCREAMING_SNAKE_CASE	,       token_type_ids=__SCREAMING_SNAKE_CASE )
					_snake_case														=   model(__SCREAMING_SNAKE_CASE )
					self.parent.assertEqual(result.pooler_output.shape	,       (self.batch_size, self.projection_dim or self.hidden_size) )



		def 					_a					(      self     :					List[str]	,       __SCREAMING_SNAKE_CASE     :					int	,       __SCREAMING_SNAKE_CASE     :					List[Any]	,       __SCREAMING_SNAKE_CASE     :					int	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]	,       __SCREAMING_SNAKE_CASE     :					Any	,       __SCREAMING_SNAKE_CASE     :					Optional[int]	,       __SCREAMING_SNAKE_CASE     :					Any ):






					"""simple docstring"""
					_snake_case														=   DPRReader(config=__SCREAMING_SNAKE_CASE )
					model.to(__SCREAMING_SNAKE_CASE )
					model.eval()
					_snake_case														=   model(
					    __SCREAMING_SNAKE_CASE	,       attention_mask=__SCREAMING_SNAKE_CASE	,       )

					self.parent.assertEqual(result.start_logits.shape	,       (self.batch_size, self.seq_length) )
					self.parent.assertEqual(result.end_logits.shape	,       (self.batch_size, self.seq_length) )
					self.parent.assertEqual(result.relevance_logits.shape	,       (self.batch_size,) )







		def 					_a					(      self     :					Any ):






					"""simple docstring"""
					_snake_case														=   self.prepare_config_and_inputs()
					(
					    (
					    _snake_case
					)							,			(
					    _snake_case
					)							,			(
					    _snake_case
					)							,			(
					    _snake_case
					)							,			(
					    _snake_case
					)							,			(
					    _snake_case
					)							,			(
					    _snake_case
					)							,			
					)														=   config_and_inputs
					_snake_case														=   {"input_ids": input_ids}
					return config, inputs_dict

@require_torch
class 						_SCREAMING_SNAKE_CASE				(  _lowercase   ,  _lowercase   ,  unittest.TestCase				):






		"""simple docstring"""







		A_    			=   (
		    (
		        DPRContextEncoder,
		        DPRQuestionEncoder,
		        DPRReader,
		    )
		    if is_torch_available()
		    else ()
		)
		A_    			=   {'''feature-extraction''': DPRQuestionEncoder} if is_torch_available() else {}

		A_    			=   False
		A_    			=   False  # why?
		A_    			=   False
		A_    			=   False



		def 					_a					(      self     :					Union[str, Any] ):






					"""simple docstring"""
					_snake_case														=   DPRModelTester(self )
					_snake_case														=   ConfigTester(self	,       config_class=__SCREAMING_SNAKE_CASE	,       hidden_size=37 )



		def 					_a					(      self     :					int ):






					"""simple docstring"""
					self.config_tester.run_common_tests()



		def 					_a					(      self     :					List[str] ):






					"""simple docstring"""
					_snake_case														=   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_context_encoder(*__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					List[str] ):






					"""simple docstring"""
					_snake_case														=   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_question_encoder(*__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					Optional[Any] ):






					"""simple docstring"""
					_snake_case														=   self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_reader(*__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					Optional[Any] ):






					"""simple docstring"""
					_snake_case														=   self.model_tester.prepare_config_and_inputs()[0]

					_snake_case														=   DPRQuestionEncoder(config=__SCREAMING_SNAKE_CASE )
					model.to(__SCREAMING_SNAKE_CASE )
					model.eval()

					with tempfile.TemporaryDirectory() as tmp_dirname:
								model.save_pretrained(__SCREAMING_SNAKE_CASE )
								_snake_case														=   DPRQuestionEncoder.from_pretrained(__SCREAMING_SNAKE_CASE	,       projection_dim=512 )

					self.assertIsNotNone(__SCREAMING_SNAKE_CASE )







		@slow
		def 					_a					(      self     :					List[str] ):






					"""simple docstring"""
					for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_snake_case														=   DPRContextEncoder.from_pretrained(__SCREAMING_SNAKE_CASE )
								self.assertIsNotNone(__SCREAMING_SNAKE_CASE )

					for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_snake_case														=   DPRContextEncoder.from_pretrained(__SCREAMING_SNAKE_CASE )
								self.assertIsNotNone(__SCREAMING_SNAKE_CASE )

					for model_name in DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_snake_case														=   DPRQuestionEncoder.from_pretrained(__SCREAMING_SNAKE_CASE )
								self.assertIsNotNone(__SCREAMING_SNAKE_CASE )

					for model_name in DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								_snake_case														=   DPRReader.from_pretrained(__SCREAMING_SNAKE_CASE )
								self.assertIsNotNone(__SCREAMING_SNAKE_CASE )

@require_torch
class 						_SCREAMING_SNAKE_CASE				(  unittest.TestCase				):






		"""simple docstring"""







		@slow
		def 					_a					(      self     :					Dict ):






					"""simple docstring"""
					_snake_case														=   DPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base"	,       return_dict=__SCREAMING_SNAKE_CASE )
					model.to(__SCREAMING_SNAKE_CASE )

					_snake_case														=   torch.tensor(
					    [[101, 7_592, 1_010, 2_003, 2_026, 3_899, 10_140, 1_029, 102]]	,       dtype=torch.long	,       device=__SCREAMING_SNAKE_CASE )  # [CLS] hello, is my dog cute? [SEP]
					_snake_case														=   model(__SCREAMING_SNAKE_CASE )[0]  # embedding shape = (1, 768)
					# compare the actual values for a slice.
					_snake_case														=   torch.tensor(
					    [
					        [
					            0.0_3_2_3_6_2_5_3,
					            0.1_2_7_5_3_3_3_5,
					            0.1_6_8_1_8_5_0_9,
					            0.0_0_2_7_9_7_8_6,
					            0.3_8_9_6_9_3_3,
					            0.2_4_2_6_4_9_4_5,
					            0.2_1_7_8_9_7_1,
					            -0.0_2_3_3_5_2_2_7,
					            -0.0_8_4_8_1_9_5_9,
					            -0.1_4_3_2_4_1_1_7,
					        ]
					    ]	,       dtype=torch.float	,       device=__SCREAMING_SNAKE_CASE	,       )
					self.assertTrue(torch.allclose(output[:, :10]	,       __SCREAMING_SNAKE_CASE	,       atol=1e-4 ) )







		@slow
		def 					_a					(      self     :					Optional[int] ):






					"""simple docstring"""
					_snake_case														=   DPRReaderTokenizer.from_pretrained("facebook/dpr-reader-single-nq-base" )
					_snake_case														=   DPRReader.from_pretrained("facebook/dpr-reader-single-nq-base" )
					model.to(__SCREAMING_SNAKE_CASE )

					_snake_case														=   tokenizer(
					    questions="What is love ?"	,       titles="Haddaway"	,       texts="What Is Love is a song recorded by the artist Haddaway"	,       padding=__SCREAMING_SNAKE_CASE	,       return_tensors="pt"	,       )
					encoded_inputs.to(__SCREAMING_SNAKE_CASE )

					_snake_case														=   model(**__SCREAMING_SNAKE_CASE )

					# compare the actual values for a slice.
					_snake_case														=   torch.tensor(
					    [[-1_0.3_0_0_5, -1_0.7_7_6_5, -1_1.4_8_7_2, -1_1.6_8_4_1, -1_1.9_3_1_2, -1_0.3_0_0_2, -9.8_5_4_4, -1_1.7_3_7_8, -1_2.0_8_2_1, -1_0.2_9_7_5]]	,       dtype=torch.float	,       device=__SCREAMING_SNAKE_CASE	,       )

					_snake_case														=   torch.tensor(
					    [[-1_1.0_6_8_4, -1_1.7_0_4_1, -1_1.5_3_9_7, -1_0.3_4_6_5, -1_0.8_7_9_1, -6.8_4_4_3, -1_1.9_9_5_9, -1_1.0_3_6_4, -1_0.0_0_9_6, -6.8_4_0_5]]	,       dtype=torch.float	,       device=__SCREAMING_SNAKE_CASE	,       )
					self.assertTrue(torch.allclose(outputs.start_logits[:, :10]	,       __SCREAMING_SNAKE_CASE	,       atol=1e-4 ) )
					self.assertTrue(torch.allclose(outputs.end_logits[:, :10]	,       __SCREAMING_SNAKE_CASE	,       atol=1e-4 ) )

