So, what is the best approach here? ForwardDiff is working, PolyesterForwardDiff gives a nice 10x speedup, but seem unsupported as an AD backend for SciML’s Optimization. And only ReverseDiff works in reverse-land.
Looks like Julia’s complex sqrt has a bit hack. We should just define a rule for it. That should fix it, but I don’t myself have time for roughly a week before I can work on it.
And that’s without considering PolyesterForwardDiff, which using parallelism on a high core computer definitely pushes that range up a bit. Though newer versions of Enzyme definitely push that range back down a bit, so 100 is still about where I would expect it to be.
All I mean to say from this is, our benchmarks continually tell us that no, I don’t know why you would expect miracles from reverse mode here. PolyesterForwardDiff is likely to be the fastest, I would not expect even compiled tape ReverseDiff to be faster, Enzyme is the only thing that has a chance but that’s dependent on many factors (and it’s battling uphill without a multithreaded form), and you’re likely to not see a real gain after doing a bunch of work to get reverse mode to work better. I would set the expectations there and consider this an academic exercise to reverify it. If you were talking about 1000 I’d say differently, but 100 is about where the cutoff is and the multithreaded versions really make that level not “big”.
Thanks for your input, Chris! What you say makes total sense.
Is there a reason you think reverse mode is more appropriate for this task?
Well, that’s why I benchmarked it .
And that’s without considering PolyesterForwardDiff, which using parallelism on a high core computer definitely pushes that range up a bit. Though newer versions of Enzyme definitely push that range back down a bit, so 100 is still about where I would expect it to be.
I’m excited to see how Enzyme will perfom once we fix that bug from above w.r.t complex sqrt, but otherwise I’m quite satisfied with the performance of PolyesterForwardDiff, however I haven’t quite gotten it to work in Optimization. Nothing in the docs mention PolyesterForwardDiff (OptimizationFunction · Optimization.jl), although AutoPolyesterForwardDiff seems to exist.
I’m not sure if this warrants opening an issue but as an example: