argv_idx = task_id * 5 + 1 dir_in = sys.argv[argv_idx] dir_out = sys.argv[argv_idx + 1] fn = sys.argv[argv_idx + 2] nruns_f = int(sys.argv[argv_idx + 3]) nruns_J = int(sys.argv[argv_idx + 4]) fn_in = dir_in + fn fn_out = dir_out + fn alphas, means, icf, x, wishart_gamma, wishart_m = gmm_io.read_gmm_instance( fn_in + ".txt", replicate_point) tf, err = utils.timer(f, (alphas, means, icf, x, wishart_gamma, wishart_m), nruns=nruns_f, limit=time_limit, ret_val=True) print("err:") print(err) name = "Theano" if nruns_J > 0: tJ, J = utils.timer(fgrad, (alphas, means, icf, x, wishart_gamma, wishart_m), nruns=nruns_J, limit=time_limit, ret_val=True) tJ += tf # !!!!!!!!! adding this because no function value is returned by fgrad gmm_io.write_J(fn_out + "_J_" + name + ".txt", J)
model_dir = dir_in + "model/" fn_in = dir_in + fn fn_out = dir_out + fn params, us, data = hand_io.read_hand_instance(model_dir, fn_in + ".txt", True) all_params = np.append(us.flatten(), params) if data.model.is_mirrored: mirror_factor = -1. else: mirror_factor = 1. tf, err = utils.timer( f, (all_params, data.model.nbones, data.model.base_relatives, data.model.parents, data.model.inverse_base_absolutes, data.model.base_positions, data.model.weights, mirror_factor, data.points, data.correspondences, data.model.triangles), nruns=nruns_f, limit=time_limit, ret_val=True) print("err:") # print(err) name = "Theano" ntheta = params.shape[0] npts = us.shape[0] seed = np.zeros((2 + ntheta, all_params.shape[0]), dtype=all_params.dtype) for i in range(npts): seed[0][2 * i] = 1. seed[1][2 * i + 1] = 1. for i in range(ntheta):
fn_in = dir_in + fn fn_out = dir_out + fn params, us, data = hand_io.read_hand_instance(model_dir, fn_in + ".txt", True) all_params = np.append(us.flatten(), params) if data.model.is_mirrored: mirror_factor = -1. else: mirror_factor = 1. tf, err = utils.timer( torch_wrapper.torch_func, (hand_objective_complicated, (all_params, ), (data.model.nbones, data.model.base_relatives, data.model.parents, data.model.inverse_base_absolutes, data.model.base_positions, data.model.weights, mirror_factor, data.points, data.correspondences, data.model.triangles), False), nruns=nruns_f, limit=time_limit, ret_val=True) # print("err:") # print(err) name = "PyTorch" ntheta = params.shape[0] npts = us.shape[0] seed = torch.zeros((2 + ntheta, all_params.shape[0]), dtype=torch.float64) for i in range(npts): seed[0][2 * i] = 1. seed[1][2 * i + 1] = 1.
nruns_f = int(sys.argv[argv_idx + 3]) nruns_J = int(sys.argv[argv_idx + 4]) model_dir = dir_in + "model/" fn_in = dir_in + fn fn_out = dir_out + fn params, data = hand_io.read_hand_instance(model_dir, fn_in + ".txt", False) if data.model.is_mirrored: mirror_factor = -1. else: mirror_factor = 1. tf, err = utils.timer(f, ( params, data.model.nbones, data.model.base_relatives, data.model.parents, data.model.inverse_base_absolutes, data.model.base_positions, data.model.weights, mirror_factor, data.points, data.correspondences ), nruns=nruns_f, limit=time_limit, ret_val=True) print("err:") # print(err) name = "Theano" if nruns_J > 0: tJ, J = utils.timer(fjac, ( params, data.model.nbones, data.model.base_relatives, data.model.parents, data.model.inverse_base_absolutes, data.model.base_positions, data.model.weights, mirror_factor, data.points, data.correspondences ), nruns=nruns_J, limit=time_limit, ret_val=True) tJ += tf # !!!!!!!!! adding this because no function value is returned by fjac
return (reproj_err_d, w_err_d) dir_in = sys.argv[1] dir_out = sys.argv[2] fn = sys.argv[3] nruns_f = int(sys.argv[4]) nruns_J = int(sys.argv[5]) time_limit = int(sys.argv[6]) if len(sys.argv) >= 7 else float("inf") fn_in = dir_in + fn fn_out = dir_out + fn cams, X, w, obs, feats = ba_io.read_ba_instance(fn_in + ".txt") tf = utils.timer(ba_objective, (cams, X, w, obs, feats), nruns=nruns_f, limit=time_limit) name = "Autograd" if nruns_J > 0: tJ = utils.timer(compute_ba_J, (cams, X, w, obs, feats), nruns=nruns_J, limit=time_limit) # gmm.write_J(fn_out + "_J_" + name + ".txt",grad[1]) else: tJ = 0 utils.write_times(fn_out + "_times_" + name + ".txt", tf, tJ)
replicate_point = (len(sys.argv) >= 8 and sys.argv[7] == "-rep") fn_in = dir_in + fn fn_out = dir_out + fn def gmm_objective_wrapper(params, x, wishart_gamma, wishart_m): return gmm.gmm_objective(params[0], params[1], params[2], x, wishart_gamma, wishart_m) alphas, means, icf, x, wishart_gamma, wishart_m = gmm_io.read_gmm_instance( fn_in + ".txt", replicate_point) tf = utils.timer(gmm.gmm_objective, (alphas, means, icf, x, wishart_gamma, wishart_m), nruns=nruns_f, limit=time_limit) name = "Autograd" if nruns_J > 0: # k = alphas.size grad_gmm_objective_wrapper = value_and_grad(gmm_objective_wrapper) tJ, grad = utils.timer(grad_gmm_objective_wrapper, ((alphas, means, icf), x, wishart_gamma, wishart_m), nruns=nruns_J, limit=time_limit, ret_val=True) gmm_io.write_J(fn_out + "_J_" + name + ".txt", grad[1]) else: tJ = 0
import ba_objective as ba dir_in = sys.argv[1] dir_out = sys.argv[2] fn = sys.argv[3] nruns_f = int(sys.argv[4]) nruns_J = int(sys.argv[5]) time_limit = int(sys.argv[6]) if len(sys.argv) >= 7 else float("inf") fn_in = dir_in + fn fn_out = dir_out + fn cams, X, w, obs, feats = ba_io.read_ba_instance(fn_in + ".txt") tf = utils.timer(torch_wrapper.torch_func, (ba.ba_objective, (cams, X, w), (obs, feats), False), nruns=nruns_f, limit=time_limit) name = "PyTorch" if nruns_J > 0: tJ, res = utils.timer(torch_wrapper.torch_func, (ba.ba_objective, (cams, X, w), (obs, feats), True), nruns=nruns_J, limit=time_limit) J = res[1] # TODO write J to file for comparison testing # gmm.write_J(fn_out + "_J_" + name + ".txt",grad[1]) else: tJ = 0 utils.write_times(fn_out + "_times_" + name + ".txt", tf, tJ)
print("task_id: %i" % task_id) argv_idx = task_id * 5 + 1 dir_in = sys.argv[argv_idx] dir_out = sys.argv[argv_idx + 1] fn = sys.argv[argv_idx + 2] nruns_f = int(sys.argv[argv_idx + 3]) nruns_J = int(sys.argv[argv_idx + 4]) fn_in = dir_in + fn fn_out = dir_out + fn cams, X, w, obs, feats = ba_io.read_ba_instance(fn_in + ".txt") tf, err = utils.timer(f, (cams, X, w, obs, feats), nruns=nruns_f, limit=time_limit, ret_val=True) # print("err:") # print(err) name = "Theano" if nruns_J > 0: tJ, J = utils.timer(f_compute_ba_J, (cams, X, w, obs, feats), nruns=nruns_J, limit=time_limit, ret_val=True) tJ += tf # !!!!!!!!! adding this because no function value is returned by fJ # ba_io.write_J(fn_out + "_J_" + name + ".txt",J) else: tJ = 0
model_dir = dir_in + "model/" fn_in = dir_in + fn fn_out = dir_out + fn params, data = hand_io.read_hand_instance(model_dir, fn_in + ".txt", False) if data.model.is_mirrored: mirror_factor = -1. else: mirror_factor = 1. tf, err = utils.timer( torch_wrapper.torch_func, (hand_objective, (params, ), (data.model.nbones, data.model.base_relatives, data.model.parents, data.model.inverse_base_absolutes, data.model.base_positions, data.model.weights, mirror_factor, data.points, data.correspondences), False), nruns=nruns_f, limit=time_limit, ret_val=True) # print("err:") # print(err) name = "PyTorch" if nruns_J > 0: tJ, res = utils.timer( torch_wrapper.torch_func, (hand_objective, (params, ), (data.model.nbones, data.model.base_relatives, data.model.parents, data.model.inverse_base_absolutes, data.model.base_positions,
dir_in = sys.argv[1] dir_out = sys.argv[2] fn = sys.argv[3] nruns_f = int(sys.argv[4]) nruns_J = int(sys.argv[5]) time_limit = int(sys.argv[6]) if len(sys.argv) >= 7 else float("inf") fn_in = dir_in + fn fn_out = dir_out + fn main_params, extra_params, state, text_data = lstm_io.read_lstm_instance( fn_in + ".txt") tf = utils.timer(torch_wrapper.torch_func, (lstm.loss, (main_params, extra_params), (state, text_data), False, True), nruns=nruns_f, limit=time_limit) name = "PyTorch" if nruns_J > 0: # k = alphas.size tJ, res = utils.timer(torch_wrapper.torch_func, (lstm.loss, (main_params, extra_params), (state, text_data), True, True), nruns=nruns_J, limit=time_limit, ret_val=True) lstm_io.write_J(fn_out + "_J_" + name + ".txt", res[1]) else: tJ = 0
from python_common import gmm_io import torch_wrapper import gmm_objective as gmm dir_in = sys.argv[1] dir_out = sys.argv[2] fn = sys.argv[3] nruns_f = int(sys.argv[4]) nruns_J = int(sys.argv[5]) time_limit = int(sys.argv[6]) if len(sys.argv) >= 7 else float("inf") replicate_point = (len(sys.argv) >= 8 and sys.argv[7] == "-rep") fn_in = dir_in + fn fn_out = dir_out + fn alphas, means, icf, x, wishart_gamma, wishart_m = gmm_io.read_gmm_instance(fn_in + ".txt", replicate_point) tf = utils.timer(torch_wrapper.torch_func, (gmm.gmm_objective, (alphas, means, icf), (x, wishart_gamma, wishart_m), False), nruns=nruns_f, limit=time_limit) name = "PyTorch" if nruns_J > 0: # k = alphas.size tJ, res = utils.timer(torch_wrapper.torch_func, (gmm.gmm_objective, (alphas, means, icf), (x, wishart_gamma, wishart_m), True), nruns=nruns_J, limit=time_limit, ret_val=True) gmm_io.write_J(fn_out + "_J_" + name + ".txt", res[1]) else: tJ = 0 utils.write_times(fn_out + "_times_" + name + ".txt", tf, tJ)