Thank you for your reply! I am not sure exactly what do you mean by flags here. However, in my problem I actually want the output to be “as linear as possible” in the inputs. I actually want to enforce (for the actual code, not this simplified version) the partial derivatives of the Jacobian to be as close to zero as possible. But coming back to the example I gave, the function is indeed linear (it is just a linear layer), but my goal for this example is for the variable jac_d to be a matrix containing only zeros i.e. taking the derivative of a constant matrix (jac) should gives only zeros. Basically I just want to get here that the second derivative of a linear function with respect to the given variable is zero. Can I do that? And if not, how can I check (enforce) if the jacobian depends on a given variable? Thank you!