





'''simple docstring'''







import unittest

import torch

from diffusers import DDIMScheduler, TextToVideoZeroPipeline
from diffusers.utils import load_pt, require_torch_gpu, slow

from ..test_pipelines_common import assert_mean_pixel_difference


@slow
@require_torch_gpu
class        __a   (unittest.TestCase  ):

							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	'''runwayml/stable-diffusion-v1-5'''
													UpperCAmelCase_      :   Any      =	TextToVideoZeroPipeline.from_pretrained(__magic_name__							,  torch_dtype=torch.floataa ).to('''cuda''' )
													UpperCAmelCase_      :   Any      =	DDIMScheduler.from_config(pipe.scheduler.config )
													UpperCAmelCase_      :   Optional[Any]      =	torch.Generator(device='''cuda''' ).manual_seed(0 )

													UpperCAmelCase_      :   Dict      =	'''A bear is playing a guitar on Times Square'''
													UpperCAmelCase_      :   List[Any]      =	pipe(prompt=__magic_name__							,  generator=__magic_name__ ).images

													UpperCAmelCase_      :   Any      =	load_pt(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text-to-video/A bear is playing a guitar on Times Square.pt''' )

													assert_mean_pixel_difference(__magic_name__							,  __magic_name__ )










'''simple docstring'''
from transformers import (
    DPRContextEncoderTokenizer,
    DPRContextEncoderTokenizerFast,
    DPRQuestionEncoderTokenizer,
    DPRQuestionEncoderTokenizerFast,
    DPRReaderOutput,
    DPRReaderTokenizer,
    DPRReaderTokenizerFast,
)
from transformers.testing_utils import require_tokenizers, slow
from transformers.tokenization_utils_base import BatchEncoding

from ..bert.test_tokenization_bert import BertTokenizationTest



@require_tokenizers
class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     List[str]       =      DPRContextEncoderTokenizer
		_SCREAMING_SNAKE_CASE       :     Optional[int]       =      DPRContextEncoderTokenizerFast
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      True



@require_tokenizers
class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     str       =      DPRQuestionEncoderTokenizer
		_SCREAMING_SNAKE_CASE       :     List[str]       =      DPRQuestionEncoderTokenizerFast
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      True



@require_tokenizers
class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     List[str]       =      DPRReaderTokenizer
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      DPRReaderTokenizerFast
		_SCREAMING_SNAKE_CASE       :     Dict       =      True





		@slow
		def 				__A							(  self					)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self.tokenizer_class.from_pretrained("""bert-base-uncased"""					)

					__UpperCAmelCase :   int    					=  tokenizer.encode("""question sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[Any]    					=  tokenizer.encode("""title sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Any    					=  tokenizer.encode("""text sequence """ * 4			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Tuple    					=  [[101] + text_a + [102] + text_a + [102] + text_a]
					__UpperCAmelCase :   Optional[int]    					=  BatchEncoding({"""input_ids""": input_ids}					)

					__UpperCAmelCase :   str    					=  [[0] * len(input_ids[0]					)]
					__UpperCAmelCase :   str    					=  [[0] * len(input_ids[0]					)]
					__UpperCAmelCase :   Optional[int]    					=  [0]
					__UpperCAmelCase :   List[str]    					=  DPRReaderOutput(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

					__UpperCAmelCase					,	__UpperCAmelCase :   Any    					=  8, 9
					__UpperCAmelCase :   Optional[int]    					=  10
					__UpperCAmelCase :   int    					=  10
					__UpperCAmelCase :   str    					=  tokenizer.decode_best_spans(__UpperCAmelCase			,							__UpperCAmelCase					)
					self.assertEqual(predicted_spans[0].start_index			,							__UpperCAmelCase					)
					self.assertEqual(predicted_spans[0].end_index			,							__UpperCAmelCase					)
					self.assertEqual(predicted_spans[0].doc_id			,							0					)





		@slow
		def 				__A							(  self					)							->  int:

					'''simple docstring'''
					__UpperCAmelCase :   Any    					=  self.tokenizer_class.from_pretrained("""bert-base-uncased"""					)

					__UpperCAmelCase :   List[Any]    					=  tokenizer.encode("""question sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   List[str]    					=  tokenizer.encode("""title sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Union[str, Any]    					=  tokenizer.encode("""text sequence"""			,							add_special_tokens=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[int]    					=  [101] + text_a + [102] + text_a + [102] + text_a
					__UpperCAmelCase :   int    					=  tokenizer(questions=["""question sequence"""]			,							titles=["""title sequence"""]			,							texts=["""text sequence"""]					)
					self.assertIn("""input_ids"""			,							__UpperCAmelCase					)
					self.assertIn("""attention_mask"""			,							__UpperCAmelCase					)
					self.assertListEqual(encoded_input["""input_ids"""][0]			,							__UpperCAmelCase					)




