| 103 | } // namespace |
| 104 | |
| 105 | Maybe<one::TensorTuple> Backward(const one::TensorTuple& outputs, const one::TensorTuple& out_grads, |
| 106 | bool retain_graph, bool create_graph) { |
| 107 | PythonFrameGuard pf; |
| 108 | BackwardPassScopeGuard backward_guard; |
| 109 | if (create_graph) { retain_graph = true; } |
| 110 | std::shared_ptr<one::TensorTuple> gradients = |
| 111 | JUST(CheckAndInitOutGrads(outputs, out_grads, /*is_grads_batched=*/false)); |
| 112 | JUST(one::GetThreadLocalAutogradEngine()->RunBackwardAndSaveGrads4LeafTensorIf( |
| 113 | outputs, *gradients, retain_graph, create_graph)); |
| 114 | return std::make_shared<one::TensorTuple>(0); |
| 115 | } |
| 116 | |
| 117 | Maybe<one::TensorTuple> Grad(const one::TensorTuple& outputs, const one::TensorTuple& inputs, |
| 118 | const one::TensorTuple& out_grads, bool retain_graph, |
no test coverage detected