Learning Optimal Flows for Non-Equilibrium Importance Sampling