| 48 | } |
| 49 | |
| 50 | void GradKeyWrapper::backward(GradKeyWrapper* self, py::list tensors, py::list grads) { |
| 51 | std::vector<ValueRef> args; |
| 52 | mgb_assert(tensors.size() == grads.size()); |
| 53 | for (auto&& tensor : tensors) { |
| 54 | auto* tw = TensorWrapper::try_cast(tensor.ptr()); |
| 55 | mgb_assert(tw, "expect Tensor"); |
| 56 | args.push_back(tw->m_tensor->data()); |
| 57 | } |
| 58 | for (auto&& grad : grads) { |
| 59 | auto* tw = TensorWrapper::try_cast(grad.ptr()); |
| 60 | mgb_assert(tw, "expect Tensor"); |
| 61 | args.push_back(tw->m_tensor->data()); |
| 62 | } |
| 63 | imperative::apply(GradBackward(self->m_key), {args.data(), args.size()}); |
| 64 | } |
| 65 | |
| 66 | pybind11::function GradKeyWrapper::get_backward_closure( |
| 67 | GradKeyWrapper* self, py::list tensors) { |
no test coverage detected