-
Notifications
You must be signed in to change notification settings - Fork 354
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
The user can modify NG_CPUS_PER_TASK #1336
base: main
Are you sure you want to change the base?
Conversation
The environment variable NG_CPUS_PER_TASK modifies the number of CPUs to be used per task.
nevergrad/benchmark/xpbase.py
Outdated
@@ -57,7 +59,11 @@ def __init__( | |||
self.optimizer = optimizer | |||
self.budget = budget | |||
self.num_workers = num_workers | |||
self.executor = execution.MockedTimedExecutor(batch_mode) | |||
ng_cpus_per_task = int(os.getenv("NG_CPUS_PER_TASK", "1")) | |||
if ng_cpus_per_task > 0: |
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.
if ng_cpus_per_task > 0: | |
if ng_cpus_per_task > 1: |
@@ -57,15 +59,20 @@ def __init__( | |||
self.optimizer = optimizer | |||
self.budget = budget | |||
self.num_workers = num_workers | |||
self.executor = execution.MockedTimedExecutor(batch_mode) | |||
ng_cpus_per_task = int(os.getenv("NG_CPUS_PER_TASK", "1")) |
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.
This is only for benchmark so let's make it clear
ng_cpus_per_task = int(os.getenv("NG_CPUS_PER_TASK", "1")) | |
ng_cpus_per_task = int(os.getenv("NG_BENCHMARK_CPUS_PER_TASK", "1")) |
self.executor = execution.MockedTimedExecutor(batch_mode) | ||
ng_cpus_per_task = int(os.getenv("NG_CPUS_PER_TASK", "1")) | ||
if ng_cpus_per_task > 1: | ||
self.executor: tp.Any = futures.ThreadPoolExecutor(max_workers=ng_cpus_per_task) |
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.
I'm still very much against this since it
- prevents reproducibility
- adds complexity which may create a lot of issues (eg: not sure that it will checkpoint correctly if preempted)
- assumes the benchmarks are threadsafe, which is not always true on our side and possibly on the dependency side
Can you quantify the speed gain?
Python executes one thread at a time for most operations, so it may just waste time for creating threads without going faster (depending on what is happening in the underlying code)
Moving to a ProcessPoolExecutor could help for parallelization, but I would expect a big overhead so that it could be unhelpful most of the time
|
||
@property | ||
def name(self) -> str: | ||
return self.optimizer if isinstance(self.optimizer, str) else repr(self.optimizer) | ||
|
||
@property | ||
def batch_mode(self) -> bool: | ||
return self.executor.batch_mode | ||
return hasattr(self.executor, "batch_mode") and self.executor.batch_mode |
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.
return hasattr(self.executor, "batch_mode") and self.executor.batch_mode | |
return isinstance(self.executor, execution.MockedTimedExecutor) and self.executor.batch_mode |
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.
checking hasattr is not safe, if we update the code that could break without notice, it's much safer to test against a class
@@ -207,7 +214,9 @@ def run(self) -> tp.Dict[str, tp.Any]: | |||
def _log_results(self, pfunc: fbase.ExperimentFunction, t0: float, num_calls: int) -> None: | |||
"""Internal method for logging results before handling the error""" | |||
self.result["elapsed_time"] = time.time() - t0 | |||
self.result["pseudotime"] = self.optimsettings.executor.time | |||
self.result["pseudotime"] = ( | |||
self.optimsettings.executor.time if hasattr(self.optimsettings.executor, "time") else float("nan") |
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.
self.optimsettings.executor.time if hasattr(self.optimsettings.executor, "time") else float("nan") | |
self.optimsettings.executor.time if isinstance(self.executor, execution.MockedTimedExecutor) else float("nan") |
The environment variable NG_CPUS_PER_TASK modifies the number of CPUs to be used per task.
Types of changes
Motivation and Context / Related issue
Possibility to parallelize inside each run in benchmarks.
How Has This Been Tested (if it applies)
Checklist