From 40d0010b6b76304e340ae734cb9814e714b691cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Fleuret?= Date: Sun, 23 Jul 2023 11:41:34 +0200 Subject: [PATCH] Update. --- tasks.py | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/tasks.py b/tasks.py index a27b836..234e780 100755 --- a/tasks.py +++ b/tasks.py @@ -1283,31 +1283,20 @@ class RPL(Task): ) if save_attention_image is not None: - input = self.test_input[:1] - result = input.clone() - s = (result == self.t_prog).long() - ar_mask = (s.cumsum(dim=1) - s).clamp(min=0, max=1) - result = (1 - ar_mask) * result + ar_mask * self.t_nul - - masked_inplace_autoregression( - model, - self.batch_size, - result, - ar_mask, - deterministic_synthesis, - device=self.device, - ) + input = self.test_input[:1].clone() + last = (input != self.t_nul).max(0).values.nonzero().max() + 3 + input = input[:, :last] with torch.autograd.no_grad(): t = model.training model.eval() model.record_attention(True) - model(BracketedSequence(result)) + model(BracketedSequence(input)) model.train(t) ram = model.retrieve_attention() model.record_attention(False) - tokens_output = [self.id2token[i.item()] for i in result[0]] + tokens_output = [self.id2token[i.item()] for i in input[0]] tokens_input = ["n/a"] + tokens_output[:-1] for n_head in range(ram[0].size(1)): filename = os.path.join( -- 2.39.5