stanfordnlp/CoreNLP · error · java.lang.RuntimeException
Attempt to use ExternalFiniteDifference without passing…
Error message
Attempt to use ExternalFiniteDifference without passing currentDerivative
What it means
AbstractStochasticCachingDiffFunction.HdotVAt computes the product of the Hessian approximation and a vector. For the ExternalFiniteDifference calculation method, this overload without a currentDerivative argument cannot operate (the finite-difference variant needs the current derivative), so it throws this RuntimeException unconditionally.
Solutions
- Use the HdotVAt overload that takes currentDerivative, e.g. HdotVAt(x, v, batchSize, derivative)
- Change the calculation method away from ExternalFiniteDifference (e.g. InlineFiniteDifference) before calling this overload
- Compute the derivative first via derivativeAt(x, v, batchSize) and use the finite-difference helper directly
Example fix
// before double[] hv = f.HdotVAt(x, v, 100); // method is ExternalFiniteDifference // after double[] hv = f.HdotVAt(x, v, 100, f.derivativeAt(x, v, 100));
Defensive patterns
Strategy: validation
Validate before calling
if (func.getMethod() == StochasticCalculateMethods.ExternalFiniteDifference) hv = func.HdotVAt(x, v, batchSize, currentDerivative); else hv = func.HdotVAt(x, v, batchSize);
Try / catch
try { hv = func.HdotVAt(x, v, batchSize); } catch (RuntimeException e) { if (e.getMessage().contains("ExternalFiniteDifference")) { hv = func.HdotVAt(x, v, batchSize, func.derivativeAt(x, v, batchSize)); } else throw e; } Prevention
- Pair the HdotVAt overload with the configured StochasticCalculateMethods value
- Write a small wrapper that hides the method-dependent dispatch
- Keep the calculate method and Hessian-vector call sites in sync in one config place
When it happens
Trigger: Calling HdotVAt(x, v, batchSize) while method == StochasticCalculateMethods.ExternalFiniteDifference; typically from stochastic Hessian-vector or test code configured for external finite differences.
Common situations: Switching the stochastic calculate method to ExternalFiniteDifference without switching to the HdotVAt overload that accepts a derivative vector; copy-pasted optimizer setup from examples using a different method.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Doesn't support floats yet
- If you want to ask for the probability, you must train a…
- NO SAMPLING METHOD SELECTED
- Vector of incorrect size passed to applyInitialHessian in…
- prior is specified to be ae-lasso or g-lasso, but function…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/59312e7182313d5e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/optimization/AbstractStochasticCachingDiffFunction.java:495
}
/**
*
* HdotVAt will return the hessian vector product H.v at the point x for a batchSize subset of the data
*
* There are several ways to perform this calculation, as of now Finite Difference, and Algorithmic Differentiation
* are the methods that have been used. To use this function calculateStochastic must also fill the array
* Hv with the hessian vector product.
*
* Alternative: use the function getHdotVFiniteDifference which will simply make two calls to the function and
* come up with an approximation to this value.
*
*/
public double[] HdotVAt(double[] x, double[] v, int batchSize){
if (method == StochasticCalculateMethods.ExternalFiniteDifference){
throw new RuntimeException("Attempt to use ExternalFiniteDifference without passing currentDerivative");
/*
if( extFiniteDiffDerivative == null )
extFiniteDiffDerivative = new double[x.length];
System.arraycopy(derivativeAt(x,x,batchSize),0,extFiniteDiffDerivative,0,extFiniteDiffDerivative.length);
getHdotVFiniteDifference(x,v,extFiniteDiffDerivative,batchSize);
*/
} else {
//Call the objective Function
stochasticEnsure(x,v,batchSize);
}
return HdotV;
}
public double[] HdotVAt(double[] x, double[] v, double[] curDerivative, int batchSize){
if (method == StochasticCalculateMethods.ExternalFiniteDifference){View on GitHub (pinned to 1b7edd19c4)