I need to implement my own function, and I’m struggling to understand the documentation. Coming from a mathematical point of view, I think of the setup as follows: I’m implementing a function f. For autograd to work, it needs to know how to compute the derivative of g∘f when g is a function whose doman matches the codomain of f, assuming it already knows how to compute the derivative of g. By the chain rule, it suffices to provide the derivative of f. How do I fit this into the language of the PyTorch documentation? To me, the derivative of a function from R^m to R^n at some given point is a linear map, not simply a vector. I’d compute the matrix of this linear map, and multiply it with that for g.
The documentation for backward says:

It must accept a context ctx as the first argument, followed by as many outputs did forward() return, and it should return as many tensors, as there were inputs to forward(). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input.

What, precisely, does “each argument is the gradient w.r.t the given output” mean? The gradient of the full composition, possibly with some projection onto some of the first map’s variables, I assume? But then that’s a linear map. In this example 1 the values returned from backward seem to be vectors, not matrices (represeting linear maps). Can someone help me clear up my confusion, perhaps by expressing in more mathematical terms what backward is supposed to do?