-
Notifications
You must be signed in to change notification settings - Fork 210
fix: add memory-aware num_proc default in standardize_data_formats #404
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -484,10 +484,20 @@ def _standardize_dataset(examples): | |||||||||
| } | ||||||||||
|
|
||||||||||
| if not isinstance(dataset, IterableDataset): | ||||||||||
| from multiprocessing import cpu_count | ||||||||||
|
|
||||||||||
| if num_proc is None or type(num_proc) is not int: | ||||||||||
| num_proc = cpu_count() | ||||||||||
| import psutil | ||||||||||
|
|
||||||||||
| if num_proc is None or type(num_proc) is not int: | ||||||||||
| # Use a memory-aware default to prevent OOM with large datasets | ||||||||||
| num_proc = min(max(psutil.cpu_count()+4, 2), 64) | ||||||||||
| try: | ||||||||||
| memory_gb_left = psutil.virtual_memory().available / 1024 / 1024 / 1024 | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with other parts of the codebase (e.g., the
Suggested change
|
||||||||||
| if memory_gb_left < 4: | ||||||||||
| num_proc = 1 # Too risky, so set to 1 | ||||||||||
| else: | ||||||||||
| # Limit based on available memory (assume ~1GB per worker) | ||||||||||
| num_proc = min(num_proc, max(1, int(memory_gb_left))) | ||||||||||
| except: | ||||||||||
| pass | ||||||||||
|
Comment on lines
+499
to
+500
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a bare
Suggested change
|
||||||||||
|
|
||||||||||
| dataset_map_kwargs['num_proc'] = num_proc | ||||||||||
| dataset_map_kwargs['desc'] = "Unsloth: Standardizing formats" | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more Pythonic to use
isinstance()for type checking rather than comparing types directly withtype(). This is more robust as it correctly handles subclasses.