I’m unfortunately still rather unsure about how the whole autograd infrastructure links together in C++, I’ve spent the day trying to understand the DelayedError and Gather functions, but seem to be missing the bigger picture.
Looking at the python tutorial 5, one finds the MulConstant example (repeated below):
class MulConstant(Function):
    @staticmethod
    def forward(ctx, tensor, constant):
        ctx.constant = constant
        return tensor * constant

    @staticmethod
    def backward(ctx, grad_output):
        return grad_output * ctx.constant, None

As an example, how would one implement this using the C++ frontend?
Thank you very much for your help.

Edit:
I compiled PyTorch from source and reverse-engineered the inbuilt operations. Take a look at this minimum working example of the pow( ) function.

  
      gist.github.com
  
  
    https://gist.github.com/mikehamer/df0af5ec7ff98d3cae487975d0c921df 42
pytorch_custom_backward.cpp
// An example of using the PyTorch C++ API to implement a custom forward and backward function

#include <iostream>
#include <vector>

#include <torch/torch.h>
#include <torch/csrc/autograd/variable.h>
#include <torch/csrc/autograd/function.h>
#include <torch/csrc/autograd/VariableTypeUtils.h>
#include <torch/csrc/autograd/functions/utils.h>
This file has been truncated. show original