Skip to content

Commit

Permalink
Avoid inefficiently sorting throughputs over and again (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasvasilache committed Feb 18, 2022
1 parent fc2e797 commit a2c696a
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions python/examples/core/nevergrad_parallel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def tell_joined_process(ng_mp_evaluations: tp.Sequence[NGMPEvaluation], \

if not ipc_state.success:
scheduler.optimizer.tell(ng_mp_evaluation.proposal, 1)
return
return 0

process_throughputs = ipc_state.throughputs[parsed_args.metric_to_measure]
# Calculate the relative distance to peak: invert the throughput @90%
Expand All @@ -176,6 +176,7 @@ def tell_joined_process(ng_mp_evaluations: tp.Sequence[NGMPEvaluation], \
(parsed_args.machine_peak - throughput) / parsed_args.machine_peak
scheduler.optimizer.tell(ng_mp_evaluation.proposal, relative_error)
throughputs.append(throughput)
return throughput


def finalize_parallel_search(scheduler: NGSchedulerInterface, \
Expand Down Expand Up @@ -303,15 +304,9 @@ def signal_handler(sig, frame):

signal.signal(signal.SIGINT, signal_handler)

best = 0
while len(interrupted) == 0 and search_number < parsed_args.search_budget:
if search_number % 10 == 1:
# TODO: extract information from saved and draw some graphs
# TODO: extract info from final recommendation instead of an auxiliary
# `throughputs` list
best = 0
if len(throughputs) > 0:
throughputs.sort()
best = int(throughputs[-1])
sys.stdout.write(f'*******\t' +
f'{parsed_args.search_strategy} optimization iter ' +
f'{search_number} / {parsed_args.search_budget}\t' +
Expand All @@ -324,16 +319,17 @@ def signal_handler(sig, frame):
processes_joined = join_at_least_one_process(ng_mp_evaluations)
assert len(processes_joined) > 0, "no processes were joined"
for process_idx in processes_joined:
tell_joined_process(ng_mp_evaluations, process_idx, scheduler,
throughputs, parsed_args)
throughput = tell_joined_process(ng_mp_evaluations, process_idx,
scheduler, throughputs, parsed_args)
throughput = int(throughput)
best = throughput if throughput > best else best
ng_mp_evaluations[process_idx] = None

# We are sure there is at least one empty slot.
compilation_number = ng_mp_evaluations.index(None)

# Fill that empty slot.
ask_and_fork_process(mp_manager,
problem_definition, [np.float32] * 3,
ask_and_fork_process(mp_manager, problem_definition, [np.float32] * 3,
ng_mp_evaluations, compilation_number, scheduler,
parsed_args)

Expand All @@ -351,8 +347,10 @@ def signal_handler(sig, frame):
processes_joined = join_at_least_one_process(ng_mp_evaluations)
assert len(processes_joined) > 0, "no processes were joined"
for process_idx in processes_joined:
tell_joined_process(ng_mp_evaluations, process_idx, scheduler,
throughputs, parsed_args)
throughput = tell_joined_process(ng_mp_evaluations, process_idx,
scheduler, throughputs, parsed_args)
throughput = int(throughput)
best = throughput if throughput > best else best
ng_mp_evaluations[process_idx] = None

finalize_parallel_search(scheduler, throughputs, parsed_args)

0 comments on commit a2c696a

Please sign in to comment.