Repository navigation
Model fitting speed ups - #140
Conversation
- With help from Claude's Opus 5.5, did some extensive benchmarking trying to figure out why tinyVAST was slower than sdmTMB for relatively large SPDE models. Here's what we came up with. - Overall, ~25-30% faster - Somewhat reduced memory too Changes: - Vectorize apply() over A-matrix on R side (easy win) - Put tau in GMRF densities - Make DATA_UPDATE(weights_i) optional; it's slower - Change nll lines from -1 * d() to -d(); trivial but strangely seems to interact with DATA_UPDATE speed-up - Models also seem to often take more nlminb iterations to converge; Could be due to parameterization of marginal SD as leading parameter rather than 'tau', but that's a more major structural change that may not be worth it.
Future Rho/Gamma and Q_ss were built from the fitted parameters rather than the sampled draw, so parameter uncertainty didn't propagate into projected process errors
Faster again
|
I added some major speedups to
which works out to a ~118x speedup! This additional work is Claude assisted (so do check carefully), but it looks right to me and in my tests the returned values were the same where comparable and the overall distributions are the same. I should set up some long project comparisons between sdmTMB and tinyVAST as a final check. @Arnaud-Gruss tagging you here since we were discussing it in another thread. |
|
I'll admit that I don't fully follow the all of the changes in ´project´. @Arnaud-Gruss, could you please carefully check the output of project? @seananderson besides the changes in the linear algebra being used in ´project´, the other changes all make sense (even if I don't necessarily understand why they speed it up). Thanks for doing the digging! I should have been more cautious about adding the DATA_UPDATE option ... its there to allow testing for stochastic gradient descent for large data sets, but prolly should have stayed as an exploration. |
|
Here's Claude's summary for future reference: 1. 3a1235e: Add
|
|
Hi @seananderson and @James-Thorson, My apologies for testing this only now. For my workflows to work, when I re-install tinyVAST on my laptop, I also need to re-install it on my HPC system, which takes some time. Therefore, I was waiting for Jim to confirm he was happy with the dev-speedups version of tinyVAST before re-installing the dev version of tinyVAST. Cheers, |
I had Claude's Opus help with some pretty extensive benchmarking and profiling, trying to figure out why tinyVAST was slower than sdmTMB on SPDE models once data and mesh were both reasonably sized. Overall, these small changes result in the fitting being about ~25-30% faster than the current dev/main branches with somewhat reduced memory footprint too. It's now much closer to sdmTMB, but still a bit slower. The
fn()andgr()call timings at least basically match now. More notes below.Here's what this pull request does:
apply()over the A-matrix on the R side (easy win)DATA_UPDATE(weights_i)optional; turns out it's slower and I assume it's not usually needednllobservation error lines from-1 * densityto-density. This looks completely trivial but strangely seems to interact withDATA_UPDATEfor an additional speed up?? I don't know. Maybe it didn't do anything, but it doesn't hurt at least.If you want me to revert the
DATA_UPDATEchange, we can pull that out of this PR. The others are more benign.Compared to sdmTMB on some spatial/spatiotemporal models, it still seems to often take more
nlminbiterations to converge, even with equivalent starting values. It could be due to the parameterization of marginal SD as leading parameter rather than 'tau', but that's a more major structural change that may not be worth it. I haven't touched that.I also fixed two unit tests that were already erroring on my machine.