Something like this in the code:
def backward_batch(model, image):
    # Image is of shape 64x1x28x28


    output = model(image)
    output = softmax(output)

    Out = some_func(output)  #Out is of shape 64x1
    Out.backward()  # This does not work!

    return image.grad  # should be 64x1x28x28 as explained in the previous post