| 115 | } |
| 116 | |
| 117 | Maybe<one::TensorTuple> Grad(const one::TensorTuple& outputs, const one::TensorTuple& inputs, |
| 118 | const one::TensorTuple& out_grads, bool retain_graph, |
| 119 | bool create_graph, bool allow_unused, bool is_grads_batched) { |
| 120 | PythonFrameGuard pf; |
| 121 | BackwardPassScopeGuard backward_guard; |
| 122 | if (create_graph) { retain_graph = true; } |
| 123 | if (inputs.empty()) { return Backward(outputs, out_grads, retain_graph, create_graph); } |
| 124 | CHECK_OR_RETURN(std::all_of( |
| 125 | inputs.begin(), inputs.end(), |
| 126 | [](const std::shared_ptr<one::Tensor>& tensor) { return tensor->requires_grad(); })) |
| 127 | << "All input tensors `.requires_grad` should be true"; |
| 128 | std::shared_ptr<one::TensorTuple> gradients = |
| 129 | JUST(CheckAndInitOutGrads(outputs, out_grads, is_grads_batched)); |
| 130 | return one::GetThreadLocalAutogradEngine()->RunBackwardAndReturnInputsTensorGradIf( |
| 131 | outputs, inputs, *gradients, retain_graph, create_graph, allow_unused); |
| 132 | } |
| 133 | |
| 134 | namespace py = pybind11; |
| 135 |
nothing calls this directly
no test coverage detected