So, https://turing.ml/dev/docs/using-turing/autodiff says:
However, note that the use of caching in certain types of models can lead to incorrect results and/or errors. Models for which the compiled tape can be safely cached are models with fixed size loops and no run-time if statements. Compile-time if statements are fine.
I’m not clear what the difference is between “runtime if statements” and “compile-time if statements” is.
Suppose I’m looping through some of the data
for i in 1:10
if data[i] > 1.0
pred[i] = myfun(data[i])
else
pred[i] = myotherfun(data[i])
end
end
Is this “compile-time” or “runtime”? I’d assume it’s runtime because when I “run” the model it makes decisions, but maybe not, because every time it goes through this loop it’ll make the same decision because the data is fixed?
It’s clear to me that if I make decisions based on the value of parameters then a cached copy of the “tape” would be wrong for some parameter values. In the absence of any branches on parameter values it’s not clear what would go wrong.