def wrap(x): _sample, num_proc, use_deadline = x order = py_heu.get_DM_scores(_sample, num_proc, use_deadline=use_deadline) priority = scores_to_priority(order) return test_module(_sample, num_proc, priority, use_deadline, 0)
print("[before training][OPA generates %d]" % opares) model.train() optimizer = optim.Adam(model.parameters(), lr=0.5 * args.lr) loss_ = 0 avg_hit = [] updates = 0 prev_ = -1 require_pt = True if require_pt: for batch_idx, (_, sample_batch) in enumerate(train_data_loader): guide = [] as_np = sample_batch.numpy() for r in as_np: guide.append( np.argsort( py_heu.get_DM_scores(r, args.num_procs, use_deadline))) guide = torch.from_numpy(np.array(guide, dtype=np.int64)) if use_cuda: guide = guide.cuda() sample_batch = sample_batch.cuda() num_samples = sample_batch.shape[0] optimizer.zero_grad() rewards, log_probs, action = model(sample_batch, guide=guide) advantage = rewards loss = -torch.sum((advantage * log_probs), dim=-1).mean() loss.backward() loss_ += loss.cpu().detach().numpy() avg_hit.append((rewards.cpu().detach().mean())) torch.nn.utils.clip_grad_norm_(model.parameters(), args.grad_clip) optimizer.step() updates += 1
for x, y in train_dataset: if i == 10000: break opa_da_lc_res_ = cy_heu.OPA(y, num_proc, heu.test_DA_LC, use_deadline) #res['OPA_DA'] += opa_da_res res['OPA_DA_LC'] += opa_da_lc_res_ p = scores_to_priority( heu.get_DkC_scores(y, num_proc, use_deadline=use_deadline)) res['DkC_RTA_LC'] += (heu.test_RTA_LC(y, num_proc, p, use_deadline)) res['DkC_DA_LC'] += (heu.test_DA_LC(y, num_proc, p, use_deadline)) p = scores_to_priority( heu.get_DM_scores(y, num_proc, use_deadline=use_deadline)) res['DM_RTA_LC'] += (heu.test_RTA_LC(y, num_proc, p, use_deadline)) res['DM_DA_LC'] += (heu.test_DA_LC(y, num_proc, p, use_deadline)) p = scores_to_priority( heu.get_DM_DS_scores(y, num_proc, use_deadline=use_deadline)) res['DM_DS_RTA_LC'] += (heu.test_RTA_LC(y, num_proc, p, use_deadline)) res['DM_DS_DA_LC'] += (heu.test_DA_LC(y, num_proc, p, use_deadline)) p = scores_to_priority( heu.get_SM_DS_scores(y, num_proc, use_deadline=use_deadline)) res['SM_DS_RTA_LC'] += (heu.test_RTA_LC(y, num_proc, p, use_deadline)) res['SM_DS_DA_LC'] += (heu.test_DA_LC(y, num_proc, p,
rewards, _, _ = model(sample_batch) print(rewards) moving_avg[indices] = rewards.float() model.eval() ret = [] res_tkc = [] res_rm = [] res_opa = [] for i, sample in tqdm(test_dataset): scores = heu.get_DkC_scores(sample, args.num_procs) priority = scores_to_priority(scores) res_tkc.append( heu.test_DA(sample, args.num_procs, priority, use_deadline)) scores = heu.get_DM_scores(sample, args.num_procs) priority = scores_to_priority(scores) res_rm.append( heu.test_DA(sample, args.num_procs, priority, use_deadline)) ret, _ = heu.OPA(sample, args.num_procs, heu.test_DA, use_deadline) res_opa.append(ret) for i, batch in eval_loader: if args.use_cuda: batch = batch.cuda() R, _, _ = model(batch, argmax=True) print( "[before training][RL model generates %d][rm generates %d][DkC generates %d][OPA generates %d]" % ((R > 1.0).sum().detach().numpy(), np.sum(res_rm), np.sum(res_tkc),