code: 
  
  
  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:
  		A_														=      None
  
  if is_ray_available():
  		import ray  # noqa: E402 # isort:skip
  		from distributed_ray_retriever import RagRayDistributedRetriever, RayRetriever  # noqa: E402 # isort:skip
  else:
  		A_														=      None
  		A_														=      None
  		A_														=      None
  
  
  
  
  
  
  
  def 							UpperCAmelCase				(     UpperCAmelCase      )->		int:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					if not (is_datasets_available() and is_faiss_available() and is_psutil_available()):
  										SCREAMING_SNAKE_CASE_	      =       unittest.skip('''test requires Datasets, Faiss, psutil'''      )(UpperCAmelCase      )
  					return test_case
  
  
  
  
  
  
  @require_distributed_retrieval
  class 						snake_case			(       lowerCAmelCase__	):
  			'''simple docstring'''
  
  			def _lowercase (	self     :     Union[str, Any]					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       tempfile.mkdtemp()
  								SCREAMING_SNAKE_CASE_	      =       8
  
  								# DPR tok
  								SCREAMING_SNAKE_CASE_	      =       [
  								    '''[UNK]''',
  								    '''[CLS]''',
  								    '''[SEP]''',
  								    '''[PAD]''',
  								    '''[MASK]''',
  								    '''want''',
  								    '''##want''',
  								    '''##ed''',
  								    '''wa''',
  								    '''un''',
  								    '''runn''',
  								    '''##ing''',
  								    ''',''',
  								    '''low''',
  								    '''lowest''',
  								]
  								SCREAMING_SNAKE_CASE_	      =       os.path.join(self.tmpdirname							,							'''dpr_tokenizer'''					)
  								os.makedirs(lowerCAmelCase_							,							exist_ok=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       os.path.join(lowerCAmelCase_							,							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
  								SCREAMING_SNAKE_CASE_	      =       [
  								    '''l''',
  								    '''o''',
  								    '''w''',
  								    '''e''',
  								    '''r''',
  								    '''s''',
  								    '''t''',
  								    '''i''',
  								    '''d''',
  								    '''n''',
  								    '''\u0120''',
  								    '''\u0120l''',
  								    '''\u0120n''',
  								    '''\u0120lo''',
  								    '''\u0120low''',
  								    '''er''',
  								    '''\u0120lowest''',
  								    '''\u0120newer''',
  								    '''\u0120wider''',
  								    '''<unk>''',
  								]
  								SCREAMING_SNAKE_CASE_	      =       dict(zip(lowerCAmelCase_							,							range(len(lowerCAmelCase_					)					)					)					)
  								SCREAMING_SNAKE_CASE_	      =       ['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
  								SCREAMING_SNAKE_CASE_	      =       {'''unk_token''': '''<unk>'''}
  
  								SCREAMING_SNAKE_CASE_	      =       os.path.join(self.tmpdirname							,							'''bart_tokenizer'''					)
  								os.makedirs(lowerCAmelCase_							,							exist_ok=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       os.path.join(lowerCAmelCase_							,							BART_VOCAB_FILES_NAMES['''vocab_file''']					)
  								SCREAMING_SNAKE_CASE_	      =       os.path.join(lowerCAmelCase_							,							BART_VOCAB_FILES_NAMES['''merges_file''']					)
  								with open(self.vocab_file							,							'''w'''							,							encoding='''utf-8'''					) as fp:
  													fp.write(json.dumps(lowerCAmelCase_					) + '''\n'''					)
  								with open(self.merges_file							,							'''w'''							,							encoding='''utf-8'''					) as fp:
  													fp.write('''\n'''.join(lowerCAmelCase_					)					)
  
  			def _lowercase (	self     :     str					)					->					DPRQuestionEncoderTokenizer:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								return DPRQuestionEncoderTokenizer.from_pretrained(os.path.join(self.tmpdirname							,							'''dpr_tokenizer'''					)					)
  
  			def _lowercase (	self     :     Dict					)					->					BartTokenizer:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								return BartTokenizer.from_pretrained(os.path.join(self.tmpdirname							,							'''bart_tokenizer'''					)					)
  
  			def _lowercase (	self     :     List[Any]					)					->					Union[str, Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								shutil.rmtree(self.tmpdirname					)
  
  			def _lowercase (	self     :     Any					)					->					Union[str, Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       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     :     List[str]							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     List[str]=12_345					)					->					RagPyTorchDistributedRetriever:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_dummy_dataset()
  								SCREAMING_SNAKE_CASE_	      =       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:
  													SCREAMING_SNAKE_CASE_	      =       dataset
  													SCREAMING_SNAKE_CASE_	      =       RagPyTorchDistributedRetriever(
  													    lowerCAmelCase_							,							question_encoder_tokenizer=self.get_dpr_tokenizer()							,							generator_tokenizer=self.get_bart_tokenizer()							,							)
  													if init_retrieval:
  																		retriever.init_retrieval(lowerCAmelCase_					)
  								return retriever
  
  			def _lowercase (	self     :     Optional[int]							,							lowerCAmelCase_     :     bool					)					->					RagRayDistributedRetriever:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								ray.init(local_mode=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       RagConfig(
  								    retrieval_vector_size=self.retrieval_vector_size							,							question_encoder=DPRConfig().to_dict()							,							generator=BartConfig().to_dict()							,							)
  								SCREAMING_SNAKE_CASE_	      =       ray.remote(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       [remote_cls.remote() for _ in range(1					)]
  								with patch('''transformers.models.rag.retrieval_rag.load_dataset'''					) as mock_load_dataset:
  													SCREAMING_SNAKE_CASE_	      =       self.get_dummy_dataset()
  													SCREAMING_SNAKE_CASE_	      =       RagRayDistributedRetriever(
  													    lowerCAmelCase_							,							question_encoder_tokenizer=self.get_dpr_tokenizer()							,							generator_tokenizer=self.get_bart_tokenizer()							,							retrieval_workers=lowerCAmelCase_							,							)
  													if init_retrieval:
  																		retriever.init_retrieval()
  								return retriever
  
  			def _lowercase (	self     :     Tuple							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     List[str]=12_345					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_dummy_dataset()
  								SCREAMING_SNAKE_CASE_	      =       RagConfig(
  								    retrieval_vector_size=self.retrieval_vector_size							,							question_encoder=DPRConfig().to_dict()							,							generator=BartConfig().to_dict()							,							index_name='''custom'''							,							)
  								if from_disk:
  													SCREAMING_SNAKE_CASE_	      =       os.path.join(self.tmpdirname							,							'''dataset'''					)
  													SCREAMING_SNAKE_CASE_	      =       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
  													SCREAMING_SNAKE_CASE_	      =       RagPyTorchDistributedRetriever(
  													    lowerCAmelCase_							,							question_encoder_tokenizer=self.get_dpr_tokenizer()							,							generator_tokenizer=self.get_bart_tokenizer()							,							)
  								else:
  													SCREAMING_SNAKE_CASE_	      =       RagPyTorchDistributedRetriever(
  													    lowerCAmelCase_							,							question_encoder_tokenizer=self.get_dpr_tokenizer()							,							generator_tokenizer=self.get_bart_tokenizer()							,							index=CustomHFIndex(config.retrieval_vector_size							,							lowerCAmelCase_					)							,							)
  								if init_retrieval:
  													retriever.init_retrieval(lowerCAmelCase_					)
  								return retriever
  
  			def _lowercase (	self     :     List[Any]							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     bool					)					->					Dict:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								ray.init(local_mode=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       self.get_dummy_dataset()
  								SCREAMING_SNAKE_CASE_	      =       RagConfig(
  								    retrieval_vector_size=self.retrieval_vector_size							,							question_encoder=DPRConfig().to_dict()							,							generator=BartConfig().to_dict()							,							index_name='''custom'''							,							)
  								SCREAMING_SNAKE_CASE_	      =       ray.remote(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       [remote_cls.remote() for _ in range(1					)]
  								if from_disk:
  													SCREAMING_SNAKE_CASE_	      =       os.path.join(self.tmpdirname							,							'''dataset'''					)
  													SCREAMING_SNAKE_CASE_	      =       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
  													SCREAMING_SNAKE_CASE_	      =       RagRayDistributedRetriever(
  													    lowerCAmelCase_							,							question_encoder_tokenizer=self.get_dpr_tokenizer()							,							generator_tokenizer=self.get_bart_tokenizer()							,							retrieval_workers=lowerCAmelCase_							,							index=CustomHFIndex.load_from_disk(
  													        vector_size=config.retrieval_vector_size							,							dataset_path=config.passages_path							,							index_path=config.index_path							,							)							,							)
  								else:
  													SCREAMING_SNAKE_CASE_	      =       RagRayDistributedRetriever(
  													    lowerCAmelCase_							,							question_encoder_tokenizer=self.get_dpr_tokenizer()							,							generator_tokenizer=self.get_bart_tokenizer()							,							retrieval_workers=lowerCAmelCase_							,							index=CustomHFIndex(config.retrieval_vector_size							,							lowerCAmelCase_					)							,							)
  								if init_retrieval:
  													retriever.init_retrieval()
  								return retriever
  
  			def _lowercase (	self     :     Optional[Any]							,							lowerCAmelCase_     :     RagRetriever							,							lowerCAmelCase_     :     np.array							,							lowerCAmelCase_     :     int					)					->					None:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       retriever.retrieve(lowerCAmelCase_							,							n_docs=lowerCAmelCase_					)
  								self.assertEqual(retrieved_doc_embeds.shape							,							(2, n_docs, self.retrieval_vector_size)					)
  								self.assertEqual(len(lowerCAmelCase_					)							,							2					)
  								self.assertEqual(sorted(doc_dicts[0]					)							,							['''embeddings''', '''id''', '''text''', '''title''']					)
  								self.assertEqual(len(doc_dicts[0]['''id''']					)							,							lowerCAmelCase_					)
  								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     :     Optional[int]					)					->					str:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       1
  								SCREAMING_SNAKE_CASE_	      =       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=lowerCAmelCase_					)							,							lowerCAmelCase_							,							lowerCAmelCase_					)
  
  			def _lowercase (	self     :     List[str]					)					->					str:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       1
  								SCREAMING_SNAKE_CASE_	      =       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=lowerCAmelCase_							,							from_disk=lowerCAmelCase_					)							,							lowerCAmelCase_							,							lowerCAmelCase_							,							)
  
  			def _lowercase (	self     :     Union[str, Any]					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       1
  								SCREAMING_SNAKE_CASE_	      =       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=lowerCAmelCase_							,							from_disk=lowerCAmelCase_					)							,							lowerCAmelCase_							,							lowerCAmelCase_							,							)
  
  			@require_ray
  			def _lowercase (	self     :     Dict					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       1
  								SCREAMING_SNAKE_CASE_	      =       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=lowerCAmelCase_					)							,							lowerCAmelCase_							,							lowerCAmelCase_					)
  								ray.shutdown()
  
  			@require_ray
  			def _lowercase (	self     :     Optional[Any]					)					->					List[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       1
  								SCREAMING_SNAKE_CASE_	      =       np.array(
  								    [np.ones(self.retrieval_vector_size					), -np.ones(self.retrieval_vector_size					)]							,							dtype=np.floataa					)
  								with self.assertRaises(lowerCAmelCase_					):
  													self.distributed_retriever_check(
  													    self.get_dummy_custom_hf_index_ray_retriever(init_retrieval=lowerCAmelCase_							,							from_disk=lowerCAmelCase_					)							,							lowerCAmelCase_							,							lowerCAmelCase_							,							)
  								ray.shutdown()
  
  
  
  
  			@require_ray
  			def _lowercase (	self     :     str					)					->					Optional[int]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       1
  								SCREAMING_SNAKE_CASE_	      =       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=lowerCAmelCase_							,							from_disk=lowerCAmelCase_					)							,							lowerCAmelCase_							,							lowerCAmelCase_					)
  								ray.shutdown()
  
  
  
style_context: 
  
  
  import os
  from argparse import ArgumentParser
  from pathlib import Path
  from shutil import copyfile
  from typing import List
  
  from datasets import config
  from datasets.builder import DatasetBuilder
  from datasets.commands import BaseDatasetsCLICommand
  from datasets.download.download_config import DownloadConfig
  from datasets.download.download_manager import DownloadMode
  from datasets.load import dataset_module_factory, import_main_class
  from datasets.utils.info_utils import VerificationMode
  
  
  
  
  
  
  
  def 							UpperCAmelCase				(     UpperCAmelCase				,**UpperCAmelCase      )->		Tuple:
  
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					return RunBeamCommand(
  					    args.dataset				,args.name				,args.cache_dir				,args.beam_pipeline_options				,args.data_dir				,args.all_configs				,args.save_info or args.save_infos				,args.ignore_verifications				,args.force_redownload				,**UpperCAmelCase				,)
  
  
  
  
  
  
  class 						snake_case			(       lowerCAmelCase__	):
  			'''simple docstring'''
  
  			@staticmethod
  			def _lowercase (	lowerCAmelCase_     :     ArgumentParser					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       parser.add_parser('''run_beam'''							,							help='''Run a Beam dataset processing pipeline'''					)
  								run_beam_parser.add_argument('''dataset'''							,							type=lowerCAmelCase_							,							help='''Name of the dataset to download'''					)
  								run_beam_parser.add_argument('''--name'''							,							type=lowerCAmelCase_							,							default=lowerCAmelCase_							,							help='''Dataset config name'''					)
  								run_beam_parser.add_argument(
  								    '''--cache_dir'''							,							type=lowerCAmelCase_							,							default=lowerCAmelCase_							,							help='''Cache directory where the datasets are stored'''							,							)
  								run_beam_parser.add_argument(
  								    '''--beam_pipeline_options'''							,							type=lowerCAmelCase_							,							default=''''''							,							help='''Beam pipeline options, separated by commas. Example:: `--beam_pipeline_options=job_name=my-job,project=my-project`'''							,							)
  								run_beam_parser.add_argument(
  								    '''--data_dir'''							,							type=lowerCAmelCase_							,							default=lowerCAmelCase_							,							help='''Can be used to specify a manual directory to get the files from'''							,							)
  								run_beam_parser.add_argument('''--all_configs'''							,							action='''store_true'''							,							help='''Test all dataset configurations'''					)
  								run_beam_parser.add_argument('''--save_info'''							,							action='''store_true'''							,							help='''Save the dataset infos file'''					)
  								run_beam_parser.add_argument(
  								    '''--ignore_verifications'''							,							action='''store_true'''							,							help='''Run the test without checksums and splits checks'''					)
  								run_beam_parser.add_argument('''--force_redownload'''							,							action='''store_true'''							,							help='''Force dataset redownload'''					)
  								# aliases
  								run_beam_parser.add_argument('''--save_infos'''							,							action='''store_true'''							,							help='''alias for save_info'''					)
  								run_beam_parser.set_defaults(func=lowerCAmelCase_					)
  
  			def __init__(	self     :     Any							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     str							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     bool							,							lowerCAmelCase_     :     bool							,							**lowerCAmelCase_     :     Any							,							)					->					Tuple:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       dataset
  								SCREAMING_SNAKE_CASE_	      =       name
  								SCREAMING_SNAKE_CASE_	      =       cache_dir
  								SCREAMING_SNAKE_CASE_	      =       beam_pipeline_options
  								SCREAMING_SNAKE_CASE_	      =       data_dir
  								SCREAMING_SNAKE_CASE_	      =       all_configs
  								SCREAMING_SNAKE_CASE_	      =       save_infos
  								SCREAMING_SNAKE_CASE_	      =       ignore_verifications
  								SCREAMING_SNAKE_CASE_	      =       force_redownload
  								SCREAMING_SNAKE_CASE_	      =       config_kwargs
  
  
  
  
  			def _lowercase (	self     :     List[str]					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								import apache_beam as beam
  
  								if self._name is not None and self._all_configs:
  													print('''Both parameters `name` and `all_configs` can\'t be used at once.'''					)
  													exit(1					)
  								SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_	      =       self._dataset, self._name
  								SCREAMING_SNAKE_CASE_	      =       dataset_module_factory(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       import_main_class(dataset_module.module_path					)
  								SCREAMING_SNAKE_CASE_	      =       []
  								if self._beam_pipeline_options:
  													SCREAMING_SNAKE_CASE_	      =       beam.options.pipeline_options.PipelineOptions(
  													    flags=[F'''--{opt.strip()}''' for opt in self._beam_pipeline_options.split(''','''					) if opt]					)
  								else:
  													SCREAMING_SNAKE_CASE_	      =       None
  								if self._all_configs and len(builder_cls.BUILDER_CONFIGS					) > 0:
  													for builder_config in builder_cls.BUILDER_CONFIGS:
  																		builders.append(
  																		    builder_cls(
  																		        config_name=builder_config.name							,							data_dir=self._data_dir							,							hash=dataset_module.hash							,							beam_options=lowerCAmelCase_							,							cache_dir=self._cache_dir							,							base_path=dataset_module.builder_kwargs.get('''base_path'''					)							,							)					)
  								else:
  													builders.append(
  													    builder_cls(
  													        config_name=lowerCAmelCase_							,							data_dir=self._data_dir							,							beam_options=lowerCAmelCase_							,							cache_dir=self._cache_dir							,							base_path=dataset_module.builder_kwargs.get('''base_path'''					)							,							**self._config_kwargs							,							)					)
  
  								for builder in builders:
  													builder.download_and_prepare(
  													    download_mode=DownloadMode.REUSE_CACHE_IF_EXISTS
  													    if not self._force_redownload
  													    else DownloadMode.FORCE_REDOWNLOAD							,							download_config=DownloadConfig(cache_dir=config.DOWNLOADED_DATASETS_PATH					)							,							verification_mode=VerificationMode.NO_CHECKS
  													    if self._ignore_verifications
  													    else VerificationMode.ALL_CHECKS							,							try_from_hf_gcs=lowerCAmelCase_							,							)
  													if self._save_infos:
  																		builder._save_infos()
  
  								print('''Apache beam run successful.'''					)
  
  								# If save_infos=True, the dataset infos file is created next to the loaded module file.
  								# Let's move it to the original directory of the dataset script, to allow the user to
  								# upload them on S3 at the same time afterwards.
  								if self._save_infos:
  													SCREAMING_SNAKE_CASE_	      =       os.path.join(builder_cls.get_imported_module_dir()							,							config.DATASETDICT_INFOS_FILENAME					)
  
  													SCREAMING_SNAKE_CASE_	      =       Path(lowerCAmelCase_					).name + '''.py'''
  
  													SCREAMING_SNAKE_CASE_	      =       os.path.join(lowerCAmelCase_							,							lowerCAmelCase_					)
  													if os.path.isfile(lowerCAmelCase_					):
  																		SCREAMING_SNAKE_CASE_	      =       os.path.dirname(lowerCAmelCase_					)
  													elif os.path.isfile(lowerCAmelCase_					):
  																		SCREAMING_SNAKE_CASE_	      =       path
  													else:  # in case of a remote dataset
  																		print(F'''Dataset Infos file saved at {dataset_infos_path}'''					)
  																		exit(1					)
  
  													# Move datasetinfo back to the user
  													SCREAMING_SNAKE_CASE_	      =       os.path.join(lowerCAmelCase_							,							config.DATASETDICT_INFOS_FILENAME					)
  													copyfile(lowerCAmelCase_							,							lowerCAmelCase_					)
  													print(F'''Dataset Infos file saved at {user_dataset_infos_path}'''					)
  
  
  