Fix severe speed issue in LBFGS trainer