I think the way to do this with ForwardDiff would be to use PreallocationTools.jl
However, you could also just use AutoEnzyme() (and Enzyme.jl) and the solve should work fine without any changes and would almost certainly be faster than if you used ForwardDiff