pytorch/test/cpp_extensions/identity.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
531 B
C++
Raw Normal View History

#include <torch/extension.h>
#include <torch/torch.h>
using namespace torch::autograd;
class Identity : public Function<Identity> {
public:
static torch::Tensor forward(AutogradContext* ctx, torch::Tensor input) {
return input;
}
static tensor_list backward(AutogradContext* ctx, tensor_list grad_outputs) {
return {grad_outputs[0]};
}
};
torch::Tensor identity(torch::Tensor input) {
return Identity::apply(input);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("identity", &identity, "identity");
}