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))
- if back:
+ if reverse:
v = u.new(u.size())
v.scatter_(1, order, u)
else:
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)
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)
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)
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)
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)
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)
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)