-
Notifications
You must be signed in to change notification settings - Fork 213
Add memory-aware num_proc limiting in standardize_data_formats #418
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,18 @@ 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() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if num_proc is None or type(num_proc) is not int: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Use memory-aware default to avoid OOM crashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| num_proc = min(max(psutil.cpu_count()+4, 2), 64) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| memory = psutil.virtual_memory() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| memory_gb_left = memory.available / (1024 ** 3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if memory_gb_left < 10: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
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. I'm not sure if 10 is the correct threshold either. Would need to be tested, and I think on the T4 would likely force just 1 process. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| num_proc = 1 # Too risky with low memory | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| num_proc = min(num_proc, int(memory_gb_left)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| except: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+487
to
+498
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. This block has a few areas for improvement:
I've provided a single suggestion below that addresses all these points.
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.
When
num_procis left asNone(the default) and the dataset is not anIterableDataset, this new path callspsutil.cpu_count()andpsutil.virtual_memory()without importingpsutilinstandardize_data_formats(). Unlike the earlier helper, there is no localimport psutilin this function and no module-level import, so this will raiseNameError: name 'psutil' is not definedand crash the mapping call on the default path.Useful? React with 👍 / 👎.
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.
Yes you'll need to explicitly import psutil. and we can use
isinstanceinstead oftype(num_proc). It's also possiblepsutil.cpu_count()return None so this could might error.