Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically split input dataset in ray mode #415

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix time cal
pan-x-c committed Sep 5, 2024
commit e85412715eecdaecf552e84c909145db90189284
5 changes: 3 additions & 2 deletions data_juicer/core/ray_data.py
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ def split_jsonl(file_path: str, max_size: int,

# Write the buffered lines to the current output file
if buffer:
with open(output_file_path, 'a', encoding='utf-8') as outfile:
with open(output_file_path, 'w', encoding='utf-8') as outfile:
outfile.writelines(buffer)
buffer = []
buffer_size = 0
@@ -197,7 +197,7 @@ def best_file_num(cpu: int, memory: int, file_size: int) -> int:
Returns:
int: best number of files in a single batch
"""
max_files_by_memory = memory // (2 * file_size)
max_files_by_memory = memory // (16 * file_size)

best_num_files = max(1, (max_files_by_memory // cpu)) * cpu
logger.info(f'Best number of files in a single batch: {best_num_files}')
@@ -250,6 +250,7 @@ def read_jsonl(cls,
DEFAULT_MAX_FILE_SIZE, cfg.work_dir)
cpu = ray.cluster_resources().get('CPU', 0)
memory = ray.cluster_resources().get('memory', 0) / 1024 / 1024
logger.info(f'CPU: {cpu}, Memory: {memory}')
batch_file_num = best_file_num(cpu, memory, DEFAULT_MAX_FILE_SIZE)
return RayDataset(datasets=load_splited_json_dataset(
files, batch_file_num),
3 changes: 1 addition & 2 deletions data_juicer/core/ray_executor.py
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ def run(self, load_data_np=None):
"""
# 1. load data
logger.info('Loading dataset with Ray...')

tstart = time.time()
if self.cfg.get('generated_dataset_config', None):
generated_dataset_config = self.cfg.generated_dataset_config
assert isinstance(generated_dataset_config,
@@ -63,7 +63,6 @@ def run(self, load_data_np=None):

# 3. data process
logger.info('Processing data...')
tstart = time.time()
dataset.process(ops)

# 4. data export