Skip to content

Conversation

@GOavi101
Copy link
Contributor

@GOavi101 GOavi101 commented Dec 22, 2025

Summary

Adds dataloader_num_workers parameter to enable parallel data loading during cache preparation, speeding up the "Preparing cache" phase for large datasets.

EDIT: Fixes #1857

Changes

  • Added dataloader_num_workers parameter to DatasetArguments
  • Implemented parallel data loading in format_calibration_data()
  • Optimized device transfers in IntermediatesCache._offload_value()
  • Added safety checks to disable multiprocessing for small datasets and custom collators

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @GOavi101, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the efficiency of the cache preparation phase by introducing support for parallel data loading via the dataloader_num_workers parameter. This allows users to leverage multiple worker processes to load data concurrently, drastically reducing preparation time for large datasets. Additionally, it includes a minor optimization to prevent redundant device transfers, further streamlining the process. Safety checks are also in place to intelligently disable multiprocessing when it might be counterproductive or problematic, such as with small datasets or custom collators.

Highlights

  • New dataloader_num_workers parameter: Introduced dataloader_num_workers in DatasetArguments to control parallel data loading, defaulting to 0 (disabled).
  • Parallel Data Loading Implementation: Enabled the use of num_workers in format_calibration_data() for DataLoader to speed up cache preparation.
  • Device Transfer Optimization: Optimized _offload_value() in IntermediatesCache to prevent unnecessary device transfers for torch.Tensor objects already on the target device.
  • Multiprocessing Safety Checks: Added conditional logic to automatically disable multiprocessing (num_workers = 0) for small datasets or when custom callable data collators are used, to avoid overhead and potential issues.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

…ation- Add dataloader_num_workers parameter to DatasetArguments- Implement parallel data loading in format_calibration_data()- Optimize device transfers in cache preparation- Add safety checks for small datasets and custom collatorsFixes

Signed-off-by: GOavi101 <[email protected]>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for parallel data loading using num_workers in the DataLoader to accelerate cache preparation. The changes include adding a dataloader_num_workers argument, implementing the logic to use it in format_calibration_data with appropriate safety checks, and optimizing device transfers in IntermediatesCache. The implementation is solid, and I have one suggestion to improve code clarity.

@GOavi101 GOavi101 force-pushed the fix/cache-preparation-speedup branch from 35f70ea to f126d8a Compare December 22, 2025 09:46
Combine if/elif conditions into single if statement with or operator for better readability

Signed-off-by: GOavi101 <[email protected]>
@github-actions
Copy link

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

GOavi101 and others added 2 commits December 23, 2025 19:56
…er num_workers choice

- Use args.dataloader_num_workers directly instead of getattr
- Remove logic that silently ignores user-specified num_workers
- Add dataloader_num_workers parameter to oneshot() function
- Remove redundant device check in cache.py (torch.Tensor.to handles this)

Signed-off-by: GOavi101 <[email protected]>
@GOavi101 GOavi101 requested a review from kylesayrs December 23, 2025 14:44
Copy link
Collaborator

@kylesayrs kylesayrs left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the awesome work!

case torch.Tensor():
return IntermediateValue(
value=value.to(device=offload_device),
value=value.to(device=offload_device) if offload_device is not None else value,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this addition necessary?

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.

[Bug]: Preparing cache phase is extremely slow

2 participants