How to set retain_graph=true in C++?

Hi everyone,

Could someone tell me how to set loss.backward(retain_graph=True) in C++?

Thank you.

Should be similar, here the signature:

void backward(const Tensor &gradient = {}, c10::optional<bool> retain_graph = c10::nullopt, bool create_graph = false) const;
1 Like