Skip to content

limit num_proc when saving datasets to disk#2948

Merged
winglian merged 4 commits into
mainfrom
ds-save-num-procs
Jul 21, 2025
Merged

limit num_proc when saving datasets to disk#2948
winglian merged 4 commits into
mainfrom
ds-save-num-procs

Conversation

@winglian
Copy link
Copy Markdown
Collaborator

@winglian winglian commented Jul 19, 2025

Description

#2918 has an edge case when the number of rows is smaller than the number of processes for saving, that it fails to save due to an indexing error:

  File "/workspace/axolotl/src/axolotl/utils/data/sft.py", line 348, in _load_raw_datasets
    save_preprocessed_dataset(cfg, dataset, dataset_hash, split)
  File "/workspace/axolotl/src/axolotl/utils/data/shared.py", line 433, in save_preprocessed_dataset
    dataset.save_to_disk(
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 1613, in save_to_disk
    for job_id, done, content in iflatmap_unordered(
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/utils/py_utils.py", line 606, in iflatmap_unordered
    async_results = [
                    ^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/utils/py_utils.py", line 606, in <listcomp>
    async_results = [
                    ^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 1602, in <genexpr>
    "shard": self.shard(num_shards=num_shards, index=shard_idx, contiguous=True),
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 4957, in shard
    return self.select(
           ^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 560, in wrapper
    out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/fingerprint.py", line 442, in wrapper
    out = func(dataset, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 4075, in select
    return self._select_contiguous(start, length, new_fingerprint=new_fingerprint)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 560, in wrapper
    out: Union["Dataset", "DatasetDict"] = func(self, *args, **kwargs)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/fingerprint.py", line 442, in wrapper
    out = func(dataset, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 4135, in _select_contiguous
    _check_valid_indices_value(start, len(self))
  File "/root/miniconda3/envs/py3.11/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 622, in _check_valid_indices_value
    raise IndexError(f"Index {index} out of range for dataset of size {size}.")
IndexError: Index 60 out of range for dataset of size 60.

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Optimized dataset saving by adjusting the number of parallel processes based on dataset size, improving performance and resource usage.
    • Centralized the logic for determining default dataset processing workers using environment variables or CPU count.
  • Tests
    • Updated test configurations to include a new parameter controlling dataset processing parallelism, ensuring consistent behavior across dataset-related tests.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 19, 2025

📝 Walkthrough

"""

Walkthrough

The change updates the logic for determining the number of parallel processes used when saving a preprocessed dataset. Instead of always using the configured number of workers, the number of processes is now capped at one eighth of the dataset size or the number of workers, whichever is smaller, with a minimum of one process. A new utility function was introduced to centralize default process count determination from environment variables. Additionally, multiple test configurations across various test files were updated to include a new "dataset_processes": 4 parameter.

Changes

File Change Summary
src/axolotl/utils/data/shared.py Modified process count logic in save_preprocessed_dataset to use the minimum of configured workers and one eighth of dataset size, ensuring at least one process.
src/axolotl/utils/datasets.py Added get_default_process_count() utility function to determine default dataset process count from environment variables or CPU count.
src/axolotl/utils/schemas/config.py Updated default_dataset_processes method to use get_default_process_count() instead of manual environment variable checks.
tests/core/test_builders.py, tests/test_datasets.py, tests/test_exact_deduplication.py, tests/test_packed_dataset.py Added "dataset_processes": 4 key to multiple test configuration dictionaries to specify dataset processing parallelism in tests.

Possibly related PRs

Suggested labels

ready to merge

Suggested reviewers

  • NanoCode012
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9df3e78 and 36e95ba.

📒 Files selected for processing (3)
  • src/axolotl/utils/data/shared.py (3 hunks)
  • src/axolotl/utils/datasets.py (1 hunks)
  • src/axolotl/utils/schemas/config.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/axolotl/utils/datasets.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/axolotl/utils/data/shared.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/axolotl/utils/schemas/config.py (1)
src/axolotl/utils/datasets.py (1)
  • get_default_process_count (6-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.0)
  • GitHub Check: PyTest from Source Dist (3.11, 2.6.0)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.1)
  • GitHub Check: PyTest (3.11, 2.6.0)
  • GitHub Check: PyTest (3.11, 2.7.0)
  • GitHub Check: PyTest (3.11, 2.7.1)
  • GitHub Check: preview
🔇 Additional comments (2)
src/axolotl/utils/schemas/config.py (2)

17-17: LGTM: Clean refactoring to centralize logic.

The import of get_default_process_count appropriately centralizes the environment variable checking logic that was previously duplicated in this method.


1214-1214: LGTM: Simplified method maintains equivalent functionality.

The method correctly delegates to get_default_process_count() which implements the same environment variable checking logic (AXOLOTL_DATASET_PROCESSES → RUNPOD_CPU_COUNT → os.cpu_count()). This refactoring improves maintainability by centralizing the logic.

Note: This change handles the default process count determination, but the core PR issue of limiting processes based on dataset size appears to be addressed elsewhere in the codebase.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 170322a and a2cbceb.

📒 Files selected for processing (1)
  • src/axolotl/utils/data/shared.py (1 hunks)

Comment thread src/axolotl/utils/data/shared.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 19, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/axolotl/utils/datasets.py 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Copy Markdown
Contributor

📖 Documentation Preview: https://687d9823e8193750b14d9c3a--resonant-treacle-0fd729.netlify.app

Deployed on Netlify from commit 36e95ba

@winglian winglian merged commit db5f6f4 into main Jul 21, 2025
27 of 28 checks passed
@winglian winglian deleted the ds-save-num-procs branch July 21, 2025 15:39
@coderabbitai coderabbitai Bot mentioned this pull request Jul 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant