Open woct0rdho opened 5 years ago
Yes, this is on a TODO for now. https://github.com/rtqichen/torchdiffeq/blob/master/torchdiffeq/_impl/adjoint.py#L31 I'd need to get a bit finicky with pytorch's Function.
For now, I think the non-adjoint version should support higher-order autodiffs.
Hi @rtqichen, thank you for your work! So how can we currently take high order gradients of the integration outputs with respect to the inputs (e.g. initial conditions or else)?
Hello @rtqichen. Was there a progress in higher order autodiff feature using the adjoint method?
No sorry, zero progress has been made since 2019. If anyone wants to submit a PR for this, I can approve it.
Thanks for your comment, Ricky. Are there any action items that should be taken? Eyal
@rtqichen Thanks for your work. But The GPU memory is lost when I use import torch.autograd as ag. My code is as follows:
for itr in range(1, 5):
print('iteration: ',itr)
print("start_memory_allcoated(MB) {}".format(torch.cuda.memory_allocated()/1048576))
optimizer.zero_grad()
batch_y0, batch_t, batch_y = get_batch()
batch_y0.requires_grad = True
print('batch_y0.shape: ',batch_y0.shape)
pred_y = odeint(func, batch_y0, batch_t).to(device)
My results are as follows:
iteration: 1
start_memory_allcoated(MB) 0.0146484375
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0244140625
iteration: 2
start_memory_allcoated(MB) 0.0244140625
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.025390625
iteration: 3
start_memory_allcoated(MB) 0.025390625
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0263671875
iteration: 4
start_memory_allcoated(MB) 0.0263671875
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.02734375
(base) [s2608314@node3c01(eddie) networks]$ python test.py
iteration: 1
start_memory_allcoated(MB) 0.0146484375
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0244140625
iteration: 2
start_memory_allcoated(MB) 0.0244140625
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.025390625
iteration: 3
start_memory_allcoated(MB) 0.025390625
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0263671875
iteration: 4
start_memory_allcoated(MB) 0.0263671875
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.02734375
iteration: 5
start_memory_allcoated(MB) 0.02734375
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0283203125
iteration: 6
start_memory_allcoated(MB) 0.0283203125
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.029296875
iteration: 7
start_memory_allcoated(MB) 0.029296875
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0302734375
iteration: 8
start_memory_allcoated(MB) 0.0302734375
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.03125
iteration: 9
start_memory_allcoated(MB) 0.03125
batch_y0.shape: torch.Size([20, 1, 2])
end_memory_allcoated(MB) 0.0322265625
And it really causes out of memory! Hope to get your reply as soon as possible.
Thanks a lot for your work! However, it seems that
backward
aftergrad
is not supported yet. Here is a minimal example:Both
dy1_da
anddy1_dy0
do not havegrad_fn
, thendy1_da.backward
anddy1_dy0.backward
throw errors. It would be nice if you could support these operations, then we could build more complex applications on your package.