seq_logproba,
temperature=1.0,
deterministic_synthesis=False,
- forbidden_tokens=None,
- forced_biases=None,
):
to_generate = (ar_mask.sum(0) > 0).nonzero()
logits = (logits / temperature).log_softmax(dim=-1)
- if forbidden_tokens is not None:
- logits = logits.masked_fill(forbidden_tokens, float("-inf"))
-
- if forced_biases is not None:
- logits = logits + forced_biases[None, :]
-
if deterministic_synthesis:
t_next = logits.argmax(-1)
else:
seq_logproba=seq_logproba,
temperature=temperature,
deterministic_synthesis=deterministic_synthesis,
- forbidden_tokens=forbidden_tokens,
- forced_biases=logit_biases,
)
model.train(t)
)
def save_quizzes(self, result_dir, filename_prefix, quizzes, prediction=False):
- print(f"DEBUG {quizzes.size()=}")
l = (quizzes.size(1) - 1) // 2
forward = (quizzes[:, 0] == self.token_forward).long()
backward = (quizzes[:, 0] == self.token_backward).long()
)
def compute_correctness(
- self, c_quizzes, models_for_validation, both_directions=True
+ self, c_quizzes, models_for_validation, both_directions=False
):
reversed_c_quizzes = self.reverse_time(c_quizzes)
ar_mask = self.make_ar_mask(c_quizzes)
- seq_logproba = torch.empty(ar_mask.size(0), device=self.device)
+ seq_logproba = torch.zeros(
+ c_quizzes.size(0),
+ max([m.id for m in models_for_validation]) + 1,
+ device=self.device,
+ )
# Check how many of models can solve the quizzes in both directions
for model in models_for_validation:
result = c_quizzes.clone()
+ seq_logproba[...] = 0.0
+
masked_inplace_autoregression(
model=model,
batch_size=self.batch_size,
input=result,
ar_mask=ar_mask,
- seq_logproba=seq_logproba,
+ seq_logproba=seq_logproba[:, model.id],
temperature=1.0,
deterministic_synthesis=True,
# progress_bar_desc="solving c_quizzes",
batch_size=self.batch_size,
input=reversed_result,
ar_mask=ar_mask,
- seq_logproba=seq_logproba,
+ seq_logproba=seq_logproba[:, model.id],
temperature=1.0,
deterministic_synthesis=True,
# progress_bar_desc="solving reversed c_quizzes",
nb_correct += correct
- return nb_correct
+ return nb_correct, seq_logproba
###############################################################
- def generate_quizzes(self, nb, model_for_generation, reverse_cleanup=False):
+ def generate_quizzes(self, nb, model_for_generation):
c_quizzes = torch.empty(
nb, self.train_w_quizzes.size(1), device=self.device, dtype=torch.int64
)
ar_mask_first[:, 0] = 0
ar_mask_second[:, 0] = 0
- seq_logproba = torch.empty(ar_mask_first.size(0), device=self.device)
+ seq_logproba = torch.zeros(ar_mask_first.size(0), device=self.device)
- if reverse_cleanup:
- temperature = 10.0
- else:
- temperature = 1.0
+ temperature = 10.0
# First, we generate the answer at high temperature
device=self.device,
)
- ave_seq_logproba = seq_logproba.mean()
-
# Then, we generate the prompt deterministically
masked_inplace_autoregression(
input=c_quizzes,
ar_mask=ar_mask_second,
seq_logproba=seq_logproba,
- temperature=temperature,
+ temperature=1.0,
deterministic_synthesis=True,
device=self.device,
)
device=self.device,
)
- return c_quizzes, seq_logproba.mean()
+ return c_quizzes