In [1]:
from os import environ

environ['optimizer'] = 'Adam'
environ['num_workers']= '2'
environ['batch_size']= str(2048)
environ['n_epochs']= '1000'
environ['batch_norm']= 'True'
environ['loss_func']='MAPE'
environ['layers'] = '500 300 120 80 30'
environ['dropouts'] = '0.2'+' 0.3'*4
environ['log'] = 'False'
environ['weight_decay'] = '0.01'
environ['cuda_device'] ='cuda:1'
environ['dataset'] = 'data/blur2d.pkl'

%run utils.ipynb

In [2]:
ds = DatasetFromPkl(dataset, maxsize=None, log=log)

dl = DataLoader(ds, batch_size=batch_size,
                        sampler=SubsetRandomSampler(range(len(ds))),
                         num_workers=num_workers)

db = fai.basic_data.DataBunch(dl, dl, device=device)

train_dl = dl

In [13]:
input_size = train_dl.dataset.X.shape[1]
output_size = train_dl.dataset.Y.shape[1]


model = None 

if batch_norm:
    model = Model_BN(input_size, output_size, hidden_sizes=layers_sizes, drops=drops)
else:
    model = Model(input_size, output_size)
    
if loss_func == 'MSE':
    criterion = nn.MSELoss()
else:
    criterion = mape_criterion

l = fai.Learner(db, model, loss_func=criterion, metrics=[mape_criterion, rmse_criterion],
               callback_fns=[partial(EarlyStoppingCallback, mode='min', 
                                        monitor='mape_criterion', min_delta=0.1, patience=500)])

if optimizer == 'SGD':
    l.opt_func = optim.SGD

In [14]:
lr = 1e-03

In [15]:
l.fit_one_cycle(50, lr)


Total time: 00:08

epoch train_loss valid_loss mape_criterion rmse_criterion
1 81.774200 99.998917 99.998917 1.069233
2 80.609177 99.998917 99.998917 1.069233
3 84.338165 99.998917 99.998917 1.069233
4 84.551628 99.998917 99.998917 1.069233
5 84.502579 99.998917 99.998917 1.069233
6 84.959251 99.998917 99.998917 1.069233
7 84.514809 99.998917 99.998917 1.069233
8 84.885635 99.998940 99.998940 1.069233
9 84.326820 99.998917 99.998917 1.069233
10 84.278908 99.998917 99.998917 1.069233
11 84.439842 99.998917 99.998917 1.069233
12 84.623825 99.998917 99.998917 1.069233
13 84.763496 99.998917 99.998917 1.069233
14 84.769005 99.998917 99.998917 1.069233
15 84.753754 99.998917 99.998917 1.069233
16 84.137764 99.998917 99.998917 1.069233
17 84.201263 99.998917 99.998917 1.069233
18 83.934814 99.998917 99.998917 1.069233
19 83.504936 99.998917 99.998917 1.069233
20 82.834656 99.998917 99.998917 1.069233
21 82.225311 99.998917 99.998917 1.069233
22 81.832970 99.998917 99.998917 1.069233
23 81.262405 99.998940 99.998940 1.069233
24 80.543411 99.998917 99.998917 1.069233
25 80.168739 99.219673 99.219673 1.065822
26 80.009186 98.234497 98.234497 1.059440
27 79.485764 95.821098 95.821098 1.042082
28 78.510071 92.362839 92.362839 1.018881
29 78.085899 90.032173 90.032173 1.000932
30 77.550369 86.234123 86.234123 0.969505
31 76.953125 82.520279 82.520279 0.937292
32 76.403603 78.278152 78.278152 0.896733
33 76.281609 76.480095 76.480095 0.884657
34 75.773987 75.541817 75.541817 0.871996
35 75.155045 73.223518 73.223518 0.846324
36 74.698502 72.377197 72.377197 0.834779
37 74.367722 71.632156 71.632156 0.823166
38 73.796227 70.760429 70.760429 0.811612
39 73.070282 69.290535 69.290535 0.796289
40 72.693672 68.014565 68.014565 0.784375
41 72.441399 67.303375 67.303375 0.778648
42 71.939041 65.648262 65.648262 0.760492
43 71.402191 63.877033 63.877033 0.740310
44 71.021111 63.100010 63.100010 0.733862
45 70.798500 62.339348 62.339348 0.725423
46 70.517052 61.076633 61.076633 0.712368
47 70.353775 60.507076 60.507076 0.704447
48 69.824593 59.329056 59.329056 0.694354
49 69.565475 57.664925 57.664925 0.681160
50 69.237411 56.694458 56.694458 0.672978


In [16]:
l.recorder.plot_losses()



In [17]:
l.recorder.plot_lr()



In [19]:
l = l.load(f"training_tuning")

In [22]:
train_df = get_results_df(train_dl, l.model)
df = train_df

In [28]:
df.head()


Out[28]:
index name sched_name prediction target abs_diff APE SMAPE interchange tile unroll
0 0 function1024 function1024_no_schedule 0.928750 1.000000 0.071250 7.124996 7.388201 0 0 0
1 1 function1024 function1024_schedule_11 0.706367 1.305714 0.599347 45.901878 59.574875 0 1 0
2 2 function1024 function1024_schedule_15 0.666024 1.197540 0.531516 44.383999 57.042976 0 1 0
3 3 function1024 function1024_schedule_18 0.665433 1.637509 0.972076 59.363113 84.420403 0 1 1
4 4 function1024 function1024_schedule_19 0.648244 1.183270 0.535026 45.215916 58.424503 0 1 0

In [32]:


In [53]:
ds.schedules[3].schedule_list


Out[53]:
[{'type': 'interchange', 'params': [-1, -1], 'factors': None},
 {'type': 'tiling', 'params': [100, 101], 'factors': [64, 32]},
 {'type': 'unrolling', 'params': None, 'factors': [16]}]

In [27]:



Out[27]:
achieved_speedup max_speedup performance ranking schedules_count
0 1.29469 1.731218 0.747849 5 26

In [ ]: