Hi,
To clear up the notations when working with Jacobian, it is simpler to see your function as working with only one 1D input and one 1D output. This way the jacobian will be a 2D matrix of [nb_out, nb_in].
If your case, you can consider g that takes an input of size 2*n + 2 and returns an output of size 2.
The Jacobian for that function will have size [2, 2*n + 2].
So to be able to do a vector jacobian product, you need to provide a vector v of size 2.
Note that in pytorch, we relax this constraint when allowing multiple input/output and allowed them to be of higher dimension.
But the root idea remains: v should be the same size as the output.
In your code sample, because you set reduction = 'none' for the criterion, then no reduction happens and so your loss (as mentionned in the error message) is of size 100 (the batch size). I think you should double check the definition of the BCELoss: reduction happens over the batch size. But you never get a score for each class. So you cannot get an output of size 2 from it.