
"""simple docstring"""
import itertools
import random
import unittest

import numpy as np

from transformers import EncodecFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
			import torch


lowercase		:						Optional[int] =					random.Random()


def     lowerCamelCase_    (	lowerCamelCase_	,				lowerCamelCase_=1.0	,				lowerCamelCase_=None	,				lowerCamelCase_=None )     ->			Any:


					'''simple docstring'''
					if rng is None:
										__a:						int		    =					global_rng

					__a:						Optional[Any]		    =					[]
					for batch_idx in range(shape[0] ):
										values.append([] )
										for _ in range(shape[1] ):
															values[-1].append(rng.random() * scale )

					return values




@require_torch
class    _snake_case  (						unittest.TestCase       ):






							def __init__(					self						:			Any						, snake_case__						:			Union[str, Any]						, snake_case__						:			Tuple=7						, snake_case__						:			Optional[Any]=4_0_0						, snake_case__						:			Dict=2_0_0_0						, snake_case__						:			List[str]=1						, snake_case__						:			List[str]=0.0						, snake_case__						:			Tuple=2_4_0_0_0						, snake_case__						:			Tuple=True						, ):






												"""simple docstring"""



												__a:						Any		    =					parent
												__a:						Optional[Any]		    =					batch_size
												__a:						Optional[Any]		    =					min_seq_length
												__a:						Any		    =					max_seq_length
												__a:						Union[str, Any]		    =					(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
												__a:						List[Any]		    =					feature_size
												__a:						Any		    =					padding_value
												__a:						Tuple		    =					sampling_rate
												__a:						Optional[Any]		    =					return_attention_mask






							def 							__lowercase  (					self						:			List[str]    ):






												"""simple docstring"""



												return {
												    "feature_size": self.feature_size,
												    "padding_value": self.padding_value,
												    "sampling_rate": self.sampling_rate,
												    "return_attention_mask": self.return_attention_mask,
												}






							def 							__lowercase  (					self						:			Tuple						, snake_case__						:			Union[str, Any]=False						, snake_case__						:			int=False    ):






												"""simple docstring"""



												def _flatten(snake_case__						:			Optional[Any]    ):
																	return list(itertools.chain(*snake_case__    )    )

												if equal_length:
																	__a:						Tuple		    =					floats_list((self.batch_size, self.max_seq_length)    )
												else:
																	# make sure that inputs increase in size
																	__a:						int		    =					[
																	    _flatten(floats_list((x, self.feature_size)    )    )
																	    for x in range(self.min_seq_length						, self.max_seq_length						, self.seq_length_diff    )
																	]

												if numpify:
																	__a:						Union[str, Any]		    =					[np.asarray(snake_case__    ) for x in audio_inputs]

												return audio_inputs






@require_torch
class    _snake_case  (						_lowercase ,				unittest.TestCase       ):
							SCREAMING_SNAKE_CASE		     =						EncodecFeatureExtractor






							def 							__lowercase  (					self						:			Dict    ):






												"""simple docstring"""



												__a:						List[Any]		    =					EnCodecFeatureExtractionTester(self    )






							def 							__lowercase  (					self						:			Dict    ):






												"""simple docstring"""



												__a:						Optional[Any]		    =					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()    )
												# create three inputs of length 800, 1000, and 1200
												__a:						Optional[Any]		    =					[floats_list((1, x)    )[0] for x in range(8_0_0						, 1_4_0_0						, 2_0_0    )]
												__a:						List[Any]		    =					[np.asarray(snake_case__    ) for audio_input in audio_inputs]

												# Test not batched input
												__a:						Tuple		    =					feat_extract(audio_inputs[0]						, return_tensors="""np"""    ).input_values
												__a:						Union[str, Any]		    =					feat_extract(np_audio_inputs[0]						, return_tensors="""np"""    ).input_values
												self.assertTrue(np.allclose(snake_case__						, snake_case__						, atol=1e-3    )    )

												# Test batched
												__a:						Tuple		    =					feat_extract(snake_case__						, padding=snake_case__						, return_tensors="""np"""    ).input_values
												__a:						int		    =					feat_extract(snake_case__						, padding=snake_case__						, return_tensors="""np"""    ).input_values
												for enc_seq_a, enc_seq_a in zip(snake_case__						, snake_case__    ):
																	self.assertTrue(np.allclose(snake_case__						, snake_case__						, atol=1e-3    )    )






							def 							__lowercase  (					self						:			Dict    ):






												"""simple docstring"""



												__a:						Optional[Any]		    =					self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()    )
												__a:						List[Any]		    =					np.random.rand(1_0_0    ).astype(np.floataa    )
												__a:						int		    =					np_audio_inputs.tolist()

												for inputs in [py_audio_inputs, np_audio_inputs]:
																	__a:						Union[str, Any]		    =					feature_extractor.pad([{"""input_values""": inputs}]						, return_tensors="""np"""    )
																	self.assertTrue(np_processed.input_values.dtype == np.floataa    )
																	__a:						Optional[int]		    =					feature_extractor.pad([{"""input_values""": inputs}]						, return_tensors="""pt"""    )
																	self.assertTrue(pt_processed.input_values.dtype == torch.floataa    )






							def 							__lowercase  (					self						:			Dict						, snake_case__						:			int    ):






												"""simple docstring"""



												from datasets import load_dataset

												__a:						Dict		    =					load_dataset("""hf-internal-testing/librispeech_asr_dummy"""						, """clean"""						, split="""validation"""    )
												# automatic decoding with librispeech
												__a:						List[Any]		    =					ds.sort("""id"""    ).select(range(snake_case__    )    )[:num_samples]["""audio"""]

												return [x["array"] for x in audio_samples]






							def 							__lowercase  (					self						:			str    ):






												"""simple docstring"""



												__a:						Union[str, Any]		    =					torch.tensor(
												    [2.3804e-03, 2.0752e-03, 1.9836e-03, 2.1057e-03, 1.6174e-03,
												     3.0518e-04, 9.1553e-05, 3.3569e-04, 9.7656e-04, 1.8311e-03,
												     2.0142e-03, 2.1057e-03, 1.7395e-03, 4.5776e-04, -3.9673e-04,
												     4.5776e-04, 1.0071e-03, 9.1553e-05, 4.8828e-04, 1.1597e-03,
												     7.3242e-04, 9.4604e-04, 1.8005e-03, 1.8311e-03, 8.8501e-04,
												     4.2725e-04, 4.8828e-04, 7.3242e-04, 1.0986e-03, 2.1057e-03]    )
												# fmt: on
												__a:						List[Any]		    =					self._load_datasamples(1    )
												__a:						Optional[int]		    =					EncodecFeatureExtractor()
												__a:						Optional[int]		    =					feature_extractor(snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(input_values.shape						, (1, 1, 9_3_6_8_0)    )
												self.assertTrue(torch.allclose(input_values[0, 0, :3_0]						, snake_case__						, atol=1e-6    )    )






							def 							__lowercase  (					self						:			Optional[Any]    ):






												"""simple docstring"""



												__a:						List[str]		    =					torch.tensor(
												    [2.3804e-03, 2.0752e-03, 1.9836e-03, 2.1057e-03, 1.6174e-03,
												     3.0518e-04, 9.1553e-05, 3.3569e-04, 9.7656e-04, 1.8311e-03,
												     2.0142e-03, 2.1057e-03, 1.7395e-03, 4.5776e-04, -3.9673e-04,
												     4.5776e-04, 1.0071e-03, 9.1553e-05, 4.8828e-04, 1.1597e-03,
												     7.3242e-04, 9.4604e-04, 1.8005e-03, 1.8311e-03, 8.8501e-04,
												     4.2725e-04, 4.8828e-04, 7.3242e-04, 1.0986e-03, 2.1057e-03]    )
												# fmt: on
												__a:						Tuple		    =					self._load_datasamples(1    )
												__a:						Tuple		    =					[np.tile(input_audio[0][None]						, reps=(2, 1)    )]
												input_audio[0][1] *= 0.5
												__a:						Optional[Any]		    =					EncodecFeatureExtractor(feature_size=2    )
												__a:						List[Any]		    =					feature_extractor(snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(input_values.shape						, (1, 2, 9_3_6_8_0)    )
												self.assertTrue(torch.allclose(input_values[0, 0, :3_0]						, snake_case__						, atol=1e-6    )    )
												self.assertTrue(torch.allclose(input_values[0, 1, :3_0]						, EXPECTED_INPUT_VALUES * 0.5						, atol=1e-6    )    )






							def 							__lowercase  (					self						:			str    ):






												"""simple docstring"""



												__a:						Union[str, Any]		    =					self._load_datasamples(2    )
												# would be easier if the stride was like
												__a:						Optional[Any]		    =					EncodecFeatureExtractor(feature_size=1						, chunk_length_s=1						, overlap=0.01    )

												# pad and trunc raise an error ?
												with self.assertRaisesRegex(
												    snake_case__						, """^Both padding and truncation were set. Make sure you only set one.$"""						, ):
																	__a:						Tuple		    =					feature_extractor(
																	    snake_case__						, padding="""max_length"""						, truncation=snake_case__						, return_tensors="""pt"""    ).input_values

												# truncate to chunk
												__a:						Optional[int]		    =					feature_extractor(snake_case__						, truncation=snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (2, 1, 7_1_5_2_0)    )  # 2 chunks

												# force truncate to max_length
												__a:						Any		    =					feature_extractor(
												    snake_case__						, truncation=snake_case__						, max_length=4_8_0_0_0						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (2, 1, 4_8_0_0_0)    )

												# pad to chunk
												__a:						List[Any]		    =					feature_extractor(snake_case__						, padding=snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(padded_outputs.shape						, (2, 1, 9_5_2_8_0)    )

												# pad to chunk
												__a:						int		    =					feature_extractor(snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (2, 1, 9_5_2_8_0)    )

												# force pad to max length
												__a:						List[str]		    =					feature_extractor(
												    snake_case__						, padding="""max_length"""						, max_length=1_0_0_0_0_0						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (2, 1, 1_0_0_0_0_0)    )

												# force no pad
												with self.assertRaisesRegex(
												    snake_case__						, """^Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.$"""						, ):
																	__a:						Optional[int]		    =					feature_extractor(snake_case__						, padding=snake_case__						, return_tensors="""pt"""    ).input_values

												__a:						Optional[int]		    =					feature_extractor(input_audio[0]						, padding=snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (1, 1, 9_3_6_8_0)    )

												# no pad if no chunk_length_s
												__a:						Union[str, Any]		    =					None
												with self.assertRaisesRegex(
												    snake_case__						, """^Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.$"""						, ):
																	__a:						Any		    =					feature_extractor(snake_case__						, padding=snake_case__						, return_tensors="""pt"""    ).input_values

												__a:						str		    =					feature_extractor(input_audio[0]						, padding=snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (1, 1, 9_3_6_8_0)    )

												# no pad if no overlap
												__a:						str		    =					2
												__a:						Optional[Any]		    =					None
												with self.assertRaisesRegex(
												    snake_case__						, """^Unable to create tensor, you should probably activate padding with 'padding=True' to have batched tensors with the same length.$"""						, ):
																	__a:						str		    =					feature_extractor(snake_case__						, padding=snake_case__						, return_tensors="""pt"""    ).input_values

												__a:						str		    =					feature_extractor(input_audio[0]						, padding=snake_case__						, return_tensors="""pt"""    ).input_values
												self.assertEquals(truncated_outputs.shape						, (1, 1, 9_3_6_8_0)    )


"""simple docstring"""
import json
import os
import shutil
import sys
import tempfile
import unittest
from unittest import TestCase
from unittest.mock import patch

import faiss
import numpy as np
from datasets import Dataset

from transformers import BartConfig, BartTokenizer, DPRConfig, DPRQuestionEncoderTokenizer, RagConfig
from transformers.file_utils import is_datasets_available, is_faiss_available, is_psutil_available, is_torch_available
from transformers.integrations import is_ray_available
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES as DPR_VOCAB_FILES_NAMES
from transformers.models.rag.retrieval_rag import CustomHFIndex, RagRetriever
from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES as BART_VOCAB_FILES_NAMES
from transformers.testing_utils import require_ray


sys.path.append(os.path.join(os.getcwd()))  # noqa: E402 # noqa: E402 # isort:skip

if is_torch_available():
			from distributed_pytorch_retriever import RagPyTorchDistributedRetriever  # noqa: E402 # isort:skip
else:
			lowercase		:						str =					None

if is_ray_available():
			import ray  # noqa: E402 # isort:skip
			from distributed_ray_retriever import RagRayDistributedRetriever, RayRetriever  # noqa: E402 # isort:skip
else:
			lowercase		:						Optional[int] =					None
			lowercase		:						Union[str, Any] =					None
			lowercase		:						List[str] =					None


def     lowerCamelCase_    (	lowerCamelCase_ )     ->			Union[str, Any]:


					'''simple docstring'''
					if not (is_datasets_available() and is_faiss_available() and is_psutil_available()):
										__a:						int		    =					unittest.skip("""test requires Datasets, Faiss, psutil""" )(lowerCamelCase_ )
					return test_case




@require_distributed_retrieval
class    _snake_case  (						_lowercase       ):






							def 							__lowercase  (					self						:			Any    ):






												"""simple docstring"""



												__a:						Optional[Any]		    =					tempfile.mkdtemp()
												__a:						int		    =					8

												# DPR tok
												__a:						Any		    =					[
												    """[UNK]""",
												    """[CLS]""",
												    """[SEP]""",
												    """[PAD]""",
												    """[MASK]""",
												    """want""",
												    """##want""",
												    """##ed""",
												    """wa""",
												    """un""",
												    """runn""",
												    """##ing""",
												    """,""",
												    """low""",
												    """lowest""",
												]
												__a:						str		    =					os.path.join(self.tmpdirname						, """dpr_tokenizer"""    )
												os.makedirs(snake_case__						, exist_ok=snake_case__    )
												__a:						Tuple		    =					os.path.join(snake_case__						, DPR_VOCAB_FILES_NAMES["""vocab_file"""]    )
												with open(self.vocab_file						, """w"""						, encoding="""utf-8"""    ) as vocab_writer:
																	vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]    )    )

												# BART tok
												__a:						Any		    =					[
												    """l""",
												    """o""",
												    """w""",
												    """e""",
												    """r""",
												    """s""",
												    """t""",
												    """i""",
												    """d""",
												    """n""",
												    """\u0120""",
												    """\u0120l""",
												    """\u0120n""",
												    """\u0120lo""",
												    """\u0120low""",
												    """er""",
												    """\u0120lowest""",
												    """\u0120newer""",
												    """\u0120wider""",
												    """<unk>""",
												]
												__a:						List[str]		    =					dict(zip(snake_case__						, range(len(snake_case__    )    )    )    )
												__a:						List[str]		    =					["""#version: 0.2""", """\u0120 l""", """\u0120l o""", """\u0120lo w""", """e r""", """"""]
												__a:						List[str]		    =					{"""unk_token""": """<unk>"""}

												__a:						Optional[int]		    =					os.path.join(self.tmpdirname						, """bart_tokenizer"""    )
												os.makedirs(snake_case__						, exist_ok=snake_case__    )
												__a:						Tuple		    =					os.path.join(snake_case__						, BART_VOCAB_FILES_NAMES["""vocab_file"""]    )
												__a:						str		    =					os.path.join(snake_case__						, BART_VOCAB_FILES_NAMES["""merges_file"""]    )
												with open(self.vocab_file						, """w"""						, encoding="""utf-8"""    ) as fp:
																	fp.write(json.dumps(snake_case__    ) + """\n"""    )
												with open(self.merges_file						, """w"""						, encoding="""utf-8"""    ) as fp:
																	fp.write("""\n""".join(snake_case__    )    )






							def 							__lowercase  (					self						:			Any    ):






												"""simple docstring"""



												return DPRQuestionEncoderTokenizer.from_pretrained(os.path.join(self.tmpdirname						, """dpr_tokenizer"""    )    )






							def 							__lowercase  (					self						:			Any    ):






												"""simple docstring"""



												return BartTokenizer.from_pretrained(os.path.join(self.tmpdirname						, """bart_tokenizer"""    )    )






							def 							__lowercase  (					self						:			Tuple    ):






												"""simple docstring"""



												shutil.rmtree(self.tmpdirname    )






							def 							__lowercase  (					self						:			int    ):






												"""simple docstring"""



												__a:						int		    =					Dataset.from_dict(
												    {
												        """id""": ["""0""", """1"""],
												        """text""": ["""foo""", """bar"""],
												        """title""": ["""Foo""", """Bar"""],
												        """embeddings""": [np.ones(self.retrieval_vector_size    ), 2 * np.ones(self.retrieval_vector_size    )],
												    }    )
												dataset.add_faiss_index("""embeddings"""						, string_factory="""Flat"""						, metric_type=faiss.METRIC_INNER_PRODUCT    )
												return dataset






							def 							__lowercase  (					self						:			Any						, snake_case__						:			bool						, snake_case__						:			Dict=1_2_3_4_5    ):






												"""simple docstring"""



												__a:						str		    =					self.get_dummy_dataset()
												__a:						int		    =					RagConfig(
												    retrieval_vector_size=self.retrieval_vector_size						, question_encoder=DPRConfig().to_dict()						, generator=BartConfig().to_dict()						, )
												with patch("""transformers.models.rag.retrieval_rag.load_dataset"""    ) as mock_load_dataset:
																	__a:						List[str]		    =					dataset
																	__a:						List[Any]		    =					RagPyTorchDistributedRetriever(
																	    snake_case__						, question_encoder_tokenizer=self.get_dpr_tokenizer()						, generator_tokenizer=self.get_bart_tokenizer()						, )
																	if init_retrieval:
																						retriever.init_retrieval(snake_case__    )
												return retriever






							def 							__lowercase  (					self						:			Dict						, snake_case__						:			bool    ):






												"""simple docstring"""



												ray.init(local_mode=snake_case__    )
												__a:						int		    =					RagConfig(
												    retrieval_vector_size=self.retrieval_vector_size						, question_encoder=DPRConfig().to_dict()						, generator=BartConfig().to_dict()						, )
												__a:						List[str]		    =					ray.remote(snake_case__    )
												__a:						Tuple		    =					[remote_cls.remote() for _ in range(1    )]
												with patch("""transformers.models.rag.retrieval_rag.load_dataset"""    ) as mock_load_dataset:
																	__a:						int		    =					self.get_dummy_dataset()
																	__a:						List[Any]		    =					RagRayDistributedRetriever(
																	    snake_case__						, question_encoder_tokenizer=self.get_dpr_tokenizer()						, generator_tokenizer=self.get_bart_tokenizer()						, retrieval_workers=snake_case__						, )
																	if init_retrieval:
																						retriever.init_retrieval()
												return retriever






							def 							__lowercase  (					self						:			str						, snake_case__						:			bool						, snake_case__						:			bool						, snake_case__						:			Union[str, Any]=1_2_3_4_5    ):






												"""simple docstring"""



												__a:						List[Any]		    =					self.get_dummy_dataset()
												__a:						Optional[Any]		    =					RagConfig(
												    retrieval_vector_size=self.retrieval_vector_size						, question_encoder=DPRConfig().to_dict()						, generator=BartConfig().to_dict()						, index_name="""custom"""						, )
												if from_disk:
																	__a:						int		    =					os.path.join(self.tmpdirname						, """dataset"""    )
																	__a:						int		    =					os.path.join(self.tmpdirname						, """index.faiss"""    )
																	dataset.get_index("""embeddings"""    ).save(os.path.join(self.tmpdirname						, """index.faiss"""    )    )
																	dataset.drop_index("""embeddings"""    )
																	dataset.save_to_disk(os.path.join(self.tmpdirname						, """dataset"""    )    )
																	del dataset
																	__a:						str		    =					RagPyTorchDistributedRetriever(
																	    snake_case__						, question_encoder_tokenizer=self.get_dpr_tokenizer()						, generator_tokenizer=self.get_bart_tokenizer()						, )
												else:
																	__a:						List[Any]		    =					RagPyTorchDistributedRetriever(
																	    snake_case__						, question_encoder_tokenizer=self.get_dpr_tokenizer()						, generator_tokenizer=self.get_bart_tokenizer()						, index=CustomHFIndex(config.retrieval_vector_size						, snake_case__    )						, )
												if init_retrieval:
																	retriever.init_retrieval(snake_case__    )
												return retriever






							def 							__lowercase  (					self						:			str						, snake_case__						:			bool						, snake_case__						:			bool    ):






												"""simple docstring"""



												ray.init(local_mode=snake_case__    )
												__a:						Tuple		    =					self.get_dummy_dataset()
												__a:						Dict		    =					RagConfig(
												    retrieval_vector_size=self.retrieval_vector_size						, question_encoder=DPRConfig().to_dict()						, generator=BartConfig().to_dict()						, index_name="""custom"""						, )
												__a:						Optional[Any]		    =					ray.remote(snake_case__    )
												__a:						Any		    =					[remote_cls.remote() for _ in range(1    )]
												if from_disk:
																	__a:						List[Any]		    =					os.path.join(self.tmpdirname						, """dataset"""    )
																	__a:						Any		    =					os.path.join(self.tmpdirname						, """index.faiss"""    )
																	dataset.get_index("""embeddings"""    ).save(os.path.join(self.tmpdirname						, """index.faiss"""    )    )
																	dataset.drop_index("""embeddings"""    )
																	dataset.save_to_disk(os.path.join(self.tmpdirname						, """dataset"""    )    )
																	del dataset
																	__a:						Any		    =					RagRayDistributedRetriever(
																	    snake_case__						, question_encoder_tokenizer=self.get_dpr_tokenizer()						, generator_tokenizer=self.get_bart_tokenizer()						, retrieval_workers=snake_case__						, index=CustomHFIndex.load_from_disk(
																	        vector_size=config.retrieval_vector_size						, dataset_path=config.passages_path						, index_path=config.index_path						, )						, )
												else:
																	__a:						Any		    =					RagRayDistributedRetriever(
																	    snake_case__						, question_encoder_tokenizer=self.get_dpr_tokenizer()						, generator_tokenizer=self.get_bart_tokenizer()						, retrieval_workers=snake_case__						, index=CustomHFIndex(config.retrieval_vector_size						, snake_case__    )						, )
												if init_retrieval:
																	retriever.init_retrieval()
												return retriever






							def 							__lowercase  (					self						:			str						, snake_case__						:			RagRetriever						, snake_case__						:			np.array						, snake_case__						:			int    ):






												"""simple docstring"""



												__a    ,				__a    ,				__a:						Optional[Any]		    =					retriever.retrieve(snake_case__						, n_docs=snake_case__    )
												self.assertEqual(retrieved_doc_embeds.shape						, (2, n_docs, self.retrieval_vector_size)    )
												self.assertEqual(len(snake_case__    )						, 2    )
												self.assertEqual(sorted(doc_dicts[0]    )						, ["""embeddings""", """id""", """text""", """title"""]    )
												self.assertEqual(len(doc_dicts[0]["""id"""]    )						, snake_case__    )
												self.assertEqual(doc_dicts[0]["""id"""][0]						, """1"""    )  # max inner product is reached with second doc
												self.assertEqual(doc_dicts[1]["""id"""][0]						, """0"""    )  # max inner product is reached with first doc
												self.assertListEqual(doc_ids.tolist()						, [[1], [0]]    )






							def 							__lowercase  (					self						:			List[str]    ):






												"""simple docstring"""



												__a:						int		    =					1
												__a:						Tuple		    =					np.array(
												    [np.ones(self.retrieval_vector_size    ), -np.ones(self.retrieval_vector_size    )]						, dtype=np.floataa    )

												self.distributed_retriever_check(
												    self.get_dummy_pytorch_distributed_retriever(init_retrieval=snake_case__    )						, snake_case__						, snake_case__    )






							def 							__lowercase  (					self						:			str    ):






												"""simple docstring"""



												__a:						Tuple		    =					1
												__a:						Tuple		    =					np.array(
												    [np.ones(self.retrieval_vector_size    ), -np.ones(self.retrieval_vector_size    )]						, dtype=np.floataa    )

												self.distributed_retriever_check(
												    self.get_dummy_custom_hf_index_pytorch_retriever(init_retrieval=snake_case__						, from_disk=snake_case__    )						, snake_case__						, snake_case__						, )






							def 							__lowercase  (					self						:			List[Any]    ):






												"""simple docstring"""



												__a:						List[Any]		    =					1
												__a:						int		    =					np.array(
												    [np.ones(self.retrieval_vector_size    ), -np.ones(self.retrieval_vector_size    )]						, dtype=np.floataa    )

												self.distributed_retriever_check(
												    self.get_dummy_custom_hf_index_pytorch_retriever(init_retrieval=snake_case__						, from_disk=snake_case__    )						, snake_case__						, snake_case__						, )






							@require_ray
							def 							__lowercase  (					self						:			str    ):






												"""simple docstring"""



												__a:						int		    =					1
												__a:						str		    =					np.array(
												    [np.ones(self.retrieval_vector_size    ), -np.ones(self.retrieval_vector_size    )]						, dtype=np.floataa    )

												self.distributed_retriever_check(
												    self.get_dummy_ray_distributed_retriever(init_retrieval=snake_case__    )						, snake_case__						, snake_case__    )
												ray.shutdown()






							@require_ray
							def 							__lowercase  (					self						:			Dict    ):






												"""simple docstring"""



												__a:						List[Any]		    =					1
												__a:						List[str]		    =					np.array(
												    [np.ones(self.retrieval_vector_size    ), -np.ones(self.retrieval_vector_size    )]						, dtype=np.floataa    )
												with self.assertRaises(snake_case__    ):
																	self.distributed_retriever_check(
																	    self.get_dummy_custom_hf_index_ray_retriever(init_retrieval=snake_case__						, from_disk=snake_case__    )						, snake_case__						, snake_case__						, )
												ray.shutdown()






							@require_ray
							def 							__lowercase  (					self						:			List[str]    ):






												"""simple docstring"""



												__a:						Tuple		    =					1
												__a:						str		    =					np.array(
												    [np.ones(self.retrieval_vector_size    ), -np.ones(self.retrieval_vector_size    )]						, dtype=np.floataa    )

												self.distributed_retriever_check(
												    self.get_dummy_custom_hf_index_ray_retriever(init_retrieval=snake_case__						, from_disk=snake_case__    )						, snake_case__						, snake_case__    )
												ray.shutdown()
