Skip to content

Commit

Permalink
Detach fval only once in torch_minimize
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkelbue committed Sep 12, 2024
1 parent d974542 commit 5e64cb9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions botorch/optim/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ def torch_minimize(
else {name: limits for name, limits in bounds.items() if name in parameters}
)
for step in range(1, step_limit + 1):
fval, _ = closure()
fval = closure()[0].detach()
runtime = monotonic() - start_time
result = OptimizationResult(
step=step,
fval=fval.detach().cpu().item(),
fval=fval.cpu().item(),
status=OptimizationStatus.RUNNING,
runtime=runtime,
)

# TODO: Update stopping_criterion API to return a message.
if stopping_criterion and stopping_criterion(fval.detach()):
if stopping_criterion and stopping_criterion(fval):
result.status = OptimizationStatus.STOPPED
result.message = "`torch_minimize` stopped due to `stopping_criterion`."

Expand Down

0 comments on commit 5e64cb9

Please sign in to comment.