Ok! Thanks!
Would you give us some pointer on how to implement the node by hand?
Would it just work If I implement a subclass of Node and implement it’s methods like:

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/csrc/autograd/custom_function.h#L141-L157 2

// CppNode<T> is the Node in the autograd graph that represents the user defined
// backward function for Function<T>. Calls to CppNode::apply are forward to
// T::backward().
template <class T>
struct CppNode : public Node {


  variable_list apply(variable_list&& inputs) override;
  AutogradContext ctx_;
  std::vector<bool> is_variable_input_;
  std::vector<VariableInfo> input_info_;
  std::vector<VariableInfo> output_info_;


  void release_variables() override;


  void set_ctx_grad_fn(const std::shared_ptr<Node> &node);
  void save_variables_to_ctx();
};



  
  
    
    
  
  


and

  
      github.com
  
  
    pytorch/pytorch/blob/master/torch/csrc/autograd/python_function.h#L22-L25 1

// A Function which is implemented by a Python object (i.e., a THPFunction).
// Calls to 'apply' are forwarded to the Python method implementation.
struct PyNode : public Node {
  PyNode(THPObjectPtr obj) : obj(obj.release()) {}