projects
/
beaver.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
beb6cae
)
Update
author
François Fleuret
<francois@fleuret.org>
Thu, 23 Mar 2023 16:01:35 +0000
(17:01 +0100)
committer
François Fleuret
<francois@fleuret.org>
Thu, 23 Mar 2023 16:01:35 +0000
(17:01 +0100)
beaver.py
patch
|
blob
|
history
diff --git
a/beaver.py
b/beaver.py
index
f5f092b
..
86008f6
100755
(executable)
--- a/
beaver.py
+++ b/
beaver.py
@@
-143,10
+143,10
@@
def generation_order(x, fixed_len):
return order
return order
-def reorder(x, order,
back
=False): # x is NxTxD1x...xDk, order is NxT'
+def reorder(x, order,
reverse
=False): # x is NxTxD1x...xDk, order is NxT'
u = x.reshape(x.size()[:2] + (-1,))
order = order.unsqueeze(-1).expand(-1, -1, u.size(-1))
u = x.reshape(x.size()[:2] + (-1,))
order = order.unsqueeze(-1).expand(-1, -1, u.size(-1))
- if
back
:
+ if
reverse
:
v = u.new(u.size())
v.scatter_(1, order, u)
else:
v = u.new(u.size())
v.scatter_(1, order, u)
else:
@@
-199,7
+199,7
@@
def compute_perplexity(model, task, fixed_len, split="train"):
input = input.to(device)
x, order = shuffle(input, fixed_len)
x = model(mygpt.BracketedSequence(x), order=order).x
input = input.to(device)
x, order = shuffle(input, fixed_len)
x = model(mygpt.BracketedSequence(x), order=order).x
- output = reorder(x, order,
back
=True)
+ output = reorder(x, order,
reverse
=True)
loss = F.cross_entropy(output.transpose(1, 2), input)
acc_loss += loss.item() * input.size(0)
nb_samples += input.size(0)
loss = F.cross_entropy(output.transpose(1, 2), input)
acc_loss += loss.item() * input.size(0)
nb_samples += input.size(0)
@@
-265,7
+265,7
@@
def oneshot(gpt, task):
for mazes, policies in task.policy_batches(split="train"):
x, order = shuffle(mazes, task.height * task.width)
x = gpt(mygpt.BracketedSequence(x), mode=args.oneshot_input, order=order).x
for mazes, policies in task.policy_batches(split="train"):
x, order = shuffle(mazes, task.height * task.width)
x = gpt(mygpt.BracketedSequence(x), mode=args.oneshot_input, order=order).x
- output_gpt = reorder(x, order,
back
=True)
+ output_gpt = reorder(x, order,
reverse
=True)
output = model(output_gpt)
loss = compute_loss(mazes, output, policies, task.height, task.width)
output = model(output_gpt)
loss = compute_loss(mazes, output, policies, task.height, task.width)
@@
-280,7
+280,7
@@
def oneshot(gpt, task):
for mazes, policies in task.policy_batches(split="test"):
x, order = shuffle(mazes, task.height * task.width)
x = gpt(mygpt.BracketedSequence(x), mode=args.oneshot_input, order=order).x
for mazes, policies in task.policy_batches(split="test"):
x, order = shuffle(mazes, task.height * task.width)
x = gpt(mygpt.BracketedSequence(x), mode=args.oneshot_input, order=order).x
- output_gpt = reorder(x, order,
back
=True)
+ output_gpt = reorder(x, order,
reverse
=True)
output = model(output_gpt)
loss = compute_loss(mazes, output, policies, task.height, task.width)
acc_test_loss += loss.item() * mazes.size(0)
output = model(output_gpt)
loss = compute_loss(mazes, output, policies, task.height, task.width)
acc_test_loss += loss.item() * mazes.size(0)
@@
-295,7
+295,7
@@
def oneshot(gpt, task):
policies = task.test_policies[:32]
x, order = shuffle(mazes, task.height * task.width)
x = gpt(mygpt.BracketedSequence(x), mode=args.oneshot_input, order=order).x
policies = task.test_policies[:32]
x, order = shuffle(mazes, task.height * task.width)
x = gpt(mygpt.BracketedSequence(x), mode=args.oneshot_input, order=order).x
- output_gpt = reorder(x, order,
back
=True)
+ output_gpt = reorder(x, order,
reverse
=True)
output = model(output_gpt)
if args.oneshot_output == "policy":
targets = policies.permute(0, 2, 1)
output = model(output_gpt)
if args.oneshot_output == "policy":
targets = policies.permute(0, 2, 1)
@@
-440,7
+440,7
@@
class TaskMaze(Task):
masked_inplace_autoregression(
model, self.batch_size, x, ar_mask, order=order
)
masked_inplace_autoregression(
model, self.batch_size, x, ar_mask, order=order
)
- result = reorder(x, order,
back
=True)
+ result = reorder(x, order,
reverse
=True)
mazes, paths = self.seq2map(result)
nb_correct += maze.path_correctness(mazes, paths).long().sum()
nb_total += mazes.size(0)
mazes, paths = self.seq2map(result)
nb_correct += maze.path_correctness(mazes, paths).long().sum()
nb_total += mazes.size(0)
@@
-475,7
+475,7
@@
class TaskMaze(Task):
masked_inplace_autoregression(
model, self.batch_size, x, ar_mask, order=order
)
masked_inplace_autoregression(
model, self.batch_size, x, ar_mask, order=order
)
- result = reorder(x, order,
back
=True)
+ result = reorder(x, order,
reverse
=True)
mazes, paths = self.seq2map(input)
_, predicted_paths = self.seq2map(result)
mazes, paths = self.seq2map(input)
_, predicted_paths = self.seq2map(result)
@@
-630,7
+630,7
@@
for n_epoch in range(nb_epochs_finished, args.nb_epochs):
input = input.to(device)
x, order = shuffle(input, task.height * task.width)
x = model(mygpt.BracketedSequence(x), order=order).x
input = input.to(device)
x, order = shuffle(input, task.height * task.width)
x = model(mygpt.BracketedSequence(x), order=order).x
- output = reorder(x, order,
back
=True)
+ output = reorder(x, order,
reverse
=True)
loss = F.cross_entropy(output.transpose(1, 2), input)
acc_train_loss += loss.item() * input.size(0)
nb_train_samples += input.size(0)
loss = F.cross_entropy(output.transpose(1, 2), input)
acc_train_loss += loss.item() * input.size(0)
nb_train_samples += input.size(0)