Skip to content

Commit

Permalink
Specify a budget limit in term number of leaves found. The limit equa…
Browse files Browse the repository at this point in the history
…ls the beam size.
  • Loading branch information
wiseodd committed Nov 15, 2024
1 parent c0f958b commit d701b59
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ults/ults.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def __init__(
)
self.betaparameters = torch.from_numpy(self.init_prior()).to(self.device)

self._leaves_found = 0

def init_prior(self) -> np.ndarray:
"""Build the approximate prior over Delta or load if already exists.
Expand Down Expand Up @@ -268,7 +270,10 @@ def budget_left(self) -> bool:
Returns:
is_budge_left: `True` if there is budget left, otherwise `False`.
"""
return self.max_beam_size >= self.used_max_beam_size[-1]
return (
self.max_beam_size >= self.used_max_beam_size[-1]
and self._leaves_found < self.buffer_size
)

def log_diversity(self, tokens) -> float:
"""Diversity measure of a token sequence (Also see: https://arxiv.org/pdf/2202.06417)"""
Expand Down Expand Up @@ -471,6 +476,8 @@ def search(self) -> tuple[torch.Tensor, float, int]:
if self.use_full_budget:
best_observed_loglike /= child_tokens.size(-1)

self._leaves_found += 1

# Update optimal value distribution of parents
self.backup(new_node_name)

Expand Down

0 comments on commit d701b59

Please sign in to comment.