These objects seem to work after fixing the shape mismatch:
all_loss = {'train': torch.tensor([0.], device='cuda:0'),
            'valid': torch.tensor([0.], device='cuda:0')}
print(all_loss)
> {'train': tensor([0.], device='cuda:0'), 'valid': tensor([0.], device='cuda:0')}

loss = torch.tensor([[0.5484]], device='cuda:0')
print(loss)
> tensor([[0.5484]], device='cuda:0')


phase = 'train'
all_loss[phase] = torch.cat((all_loss[phase], loss.detach().view(1, -1)))
> RuntimeError: Tensors must have same number of dimensions: got 2 and 1

all_loss[phase] = torch.cat((all_loss[phase], loss.detach().view(-1)))
print(all_loss)
> {'train': tensor([0.0000, 0.5484], device='cuda:0'), 'valid': tensor([0.], device='cuda:0')}