Fermat's principle is an outcome of constructive interference of waves. It works both for classical and quantummechanical descriptions. E.g. check https://phys.libretexts.org/Bookshelves/University_Physics/U...
> a ray of light has to know where it will ultimately end up before it can choose the direction to begin moving in
A ray of light doesn't know or choose because it has no agency, just like an apple doesn't know or decide to fall because of gravity. It's an anthropomorphization.
True, so the interference is the "computation"(heavy emphasis on quotes) which gives rise to the principle.