def load_trainer(base_params, train_params, model, data): # type: (BaseParameters, TrainParameters, md.AbstractGraphModule, dt.DataCost) -> tr.Train return tr.Train( model, data, tr.PredictionType.REGRESSION, ls.mse_loss, 1, batch_size=train_params.batch_size, clip=None, opt=train_params.optimizer, lr=train_params.initial_lr, weight_decay=train_params.weight_decay, predict_log=base_params.predict_log, momentum=train_params.momentum, nesterov=train_params.nesterov, )
def graph_model_validate(base_params, model_file, iaca_only): # type: (BaseParameters, str, bool) -> None data = load_data(base_params) if iaca_only: cnx = ut.create_connection() legal_code_ids = set( pd.read_sql('SELECT time_id, code_id FROM times WHERE kind="iaca"', cnx) .set_index('time_id') .code_id ) data.test = [datum for datum in data.test if datum.code_id in legal_code_ids] model = load_model(base_params, data) train = tr.Train( model, data, tr.PredictionType.REGRESSION, ls.mse_loss, 1, batch_size=1000, clip=None, predict_log=base_params.predict_log, ) resultfile = os.environ['ITHEMAL_HOME'] + '/learning/pytorch/results/realtime_results.txt' (actual, predicted) = train.validate(resultfile=resultfile, loadfile=model_file)
def graph_model_benchmark(base_params, benchmark_params): # type: (BaseParameters, BenchmarkParameters) -> None data = load_data(base_params) model = load_model(base_params, data) train = tr.Train( model, data, tr.PredictionType.REGRESSION, ls.mse_loss, 1, batch_size=benchmark_params.batch_size, clip=None, opt=tr.OptimizerType.ADAM_PRIVATE, lr=0.01, ) model.share_memory() mp_config = MPConfig(benchmark_params.threads) partition_size = benchmark_params.examples // benchmark_params.trainers processes = [] start_time = time.time() with mp_config: for rank in range(benchmark_params.trainers): mp_config.set_env(rank) partition = (rank * partition_size, (rank + 1) * partition_size) p = mp.Process(target=train, args=(rank, partition)) p.daemon = True p.start() processes.append(p) for p in processes: p.join() end_time = time.time() print('Time to process {} examples: {} seconds'.format( benchmark_params.examples, end_time - start_time, ))
from models import train if __name__ == '__main__': train = train.Train() train.main()