README.md 14.8 KB
Newer Older
Liu, Frank's avatar
Dev    
Liu, Frank committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Deffe: Data-Efficient Framework for Exploration
This repository has the sources for Deffe framework, which is intended
for design space exploration with exploration and machine learning
based prediction capabilities. The technical details of Deffe is explained in the [reference, see below][1]. The state of the art design space
exploration tools evaluate the design points (samples) and identify
the optimal design points based on the cost metrics. However, the
evaluation of design points are time consuming and may require heavy
computation for some problems. Deffe will help for such problems.

Deffe's machine learning model tries to learn from the evaluated
design points. Once after learning for some time, Deffe's machine
learning model inference can predict the cost metrics with ~98%
accuracy, which can be used for fast design space exploration. It
needs less than 5% of the samples to get the near-accurate machine
learning prediction model and can save huge time in the design space
exploration.

Deffe framework is implemented fully in python and it is configured
through json file. The json file has configuration of problem with
parameters, cost metrics, evaluate procedure, prediction method,
sampling technique and exploration algorithm. It provides great
flexibility to users to add their custom python modules for the above
tasks.

## Reference
[1]: Frank Liu, Narasinga Rao Miniskar, Dwaipayan Chakraborty and Jeffrey S. Vetter, "Deffe: a data-efficient framework for performance characterization in domain-specific computing", ACM International Conference on Computing Frontiers (CF 2020), May 2020, Catania, Italy, https://doi.org/10.1145/3387902.3392633

## Deffe framework component diagram
<img src="docs/deffe-block-diagram.svg" alt="Diagram"
	title="Block Diagram" width="500" />

The above figures shows the main blocks and their corresponding python files in the Deffe framework.

## Hardware Dependencies 
1. GPU to train the machine learning model
2. SLURM environment if to run evaluate (RISCV-GEM5) simulations
37
    - Installation of GEM5 is given in http://learning.gem5.org/book/part1/building.html
Liu, Frank's avatar
Dev    
Liu, Frank committed
38
39

## Software Dependencies
Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
40
1. Python-3
Liu, Frank's avatar
Dev    
Liu, Frank committed
41
2. Graphviz 
42
3. Python packages
Liu, Frank's avatar
Dev    
Liu, Frank committed
43
44
45
    - keras 
    - tensorflow 
    - tensorflow-gpu 
46
    - torch
47
    - doepy
Liu, Frank's avatar
Dev    
Liu, Frank committed
48
49
50
51
    - scikit-learn 
    - xlsxwriter 
    - matplotlib 
    - pandas 
52
    - pathlib
Liu, Frank's avatar
Dev    
Liu, Frank committed
53
54
    - pydot 
    - tqdm 
Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
55
    - multiprocess
Liu, Frank's avatar
Dev    
Liu, Frank committed
56
    - torchsummary
57
    - commentjson
Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
58
    - jsoncomment
59
60
61
    ```bash
    Install all required packages from requirements.txt file in the repository.
    $ pip3 install -r requirements.txt
Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
62
63
64

    Or

Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
65
    $ python3 -m pip install keras tensorflow torch doepy scikit-learn xlsxwriter matplotlib pandas pathlib pydot tqdm torchsummary jsoncomment commentjson multiprocess
66
    ```
Liu, Frank's avatar
Dev    
Liu, Frank committed
67

68
## Docker support
Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
69
Docker support is provided for Deffe. Set proxy settings in Docker file and also in apt.conf file appropriately.
70
71
72
73
```bash
$ make -f Makefile.docker build ; 
$ make -f Makefile.docker run ;
```
Liu, Frank's avatar
Dev    
Liu, Frank committed
74
75
76
77
78
79
80
81
82

## How to run Deffe?
An example Deffe configuration for RISCV design space exploration along with their associated files are placed in <b>example</b> directory. 
```bash
$ source setup.source
$ cd example ; 
$ python3 ../framework/run_deffe.py -config config_small.json
$ cd .. ;
```
Narasinga Rao Miniskar's avatar
Narasinga Rao Miniskar committed
83
84
85
86
87
88
89
A bare minimal simple two parameters and one application test case is available in test directory. 
```bash
$ source setup.source
$ cd test; 
$ sh run_deffe.sh
$ cd .. ;
```
Liu, Frank's avatar
Dev    
Liu, Frank committed
90

91
92
93
94
95
96
97
98
An example Deffe configuration for RISCV design space exploration (without slurm) along with their associated files are placed in <b>example</b> directory. 
```bash
$ source setup.source
$ cd example ; 
$ python3 ../framework/run_deffe.py -config config_small.json -no-slurm
$ cd .. ;
```

Liu, Frank's avatar
Dev    
Liu, Frank committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
The run_deffe.py file can show all command line options with the below command.
```bash
$ cd example ;
$ python3 ../framework/run_deffe.py -h
$ cd .. ;
```

To run the exploration on the preloaded data
```bash
$ cd example ;
$ python3 ../framework/run_deffe.py -config config_small.json \
   -only-preloaded-data-exploration -step-start 0 -step-end 1 \
   -epochs 100 -batch-size 256 
$ cd .. ;
```

To run full exploration (all samples at once training, means no transfer learning across samples) on the pre-evaluated/pre-loaded data
```bash
$ cd example ;
$ python3 ../framework/run_deffe.py -config config_small.json \
  -only-preloaded-data-exploration -full-exploration -train-test-split 0.7 \
  -validation-split 0.23 -step-start 0 -step-end 1 -epochs 100 -batch-size 256 
$ cd .. ;
```

## How to run experiments?
### Run Deffe with K-means with pre-evaluated complete dataset given to model train
```bash
* Dataset: examples/output_kmeans_deffe.csv
* Config file: examples/config_kmeans.json
* Loss functions: custom_mean_abs_log_loss (default) or custom_mean_abs_exp_loss 
*  (exponential loss function)
* Run directory: example/experiments/full_explore/log/kmeans   (For log loss function)
                 example/experiments/full_explore/exp/kmeans   (For exponential loss function)
* Command to run: 
    $ source setup.source
    $ cd example/experiments/full_explore/log/kmeans 
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
    -config $DEFFE_DIR/example/config_kmeans.json \
    -only-preloaded-data-exploration -epochs 20000 -batch-size 4096 \
    -full-exploration \
    -train-test-split 0.7 -validation-split 0.23 -loss custom_mean_abs_log_loss

* Command to generate stats. It will load the same training and testing indices used for ML model 
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
    -model-extract-dir checkpoints -config $DEFFE_DIR/example/config_kmeans.json \
    -only-preloaded-data-exploration -train-test-split 0.7 \
    -validation-split 0.23 -load-train-test -loss custom_mean_abs_exp_loss \
    -model-stats-output test-output-exploss.csv

* Output files: 
    ** Intermediate checkpoint files directory: example/experiments/full_explore/log/kmeans/checkpoints
    ** Training and Test indexes used: step<int>-train-indices.npy, step<int>-val-indices.npy, 
    ** which have training and validation indexes used for training for that step
    ** Output statistics in file: test-output-exploss.csv in the format (Epoch, TrainLoss, 
    ** ValLoss, TestLoss, Step, TrainCount, ValCount)
* Try sample parameters:
    ** Input test-input.csv
    ** Command given below
       $ python3 $DEFFE_DIR/framework/run_deffe.py \
       -config $DEFFE_DIR/example/config_kmeans.json \
       -input test-model.csv -icp kmeans.hdf5 -output output-prediction.csv -inference-only
    ** Output test-output.csv
    ** Input ../../../../output_kmeans_deffe.csv 
    ** Command given below
       $ python3 $DEFFE_DIR/framework/run_deffe.py \
       -config $DEFFE_DIR/example/config_kmeans.json \
       -icp kmeans.hdf5  -input ../../../../output_kmeans_deffe.csv  \
       -output test-output-full.csv \ -inference-only
    ** Output test-output-full.csv
```

### Run Deffe with K-means with pre-evaluated data set but passed as set of samples and enabled transfer learning across samples
```bash
* Dataset: examples/output_kmeans_deffe.csv
* Config file: examples/config_kmeans_tl_samples.json
* Loss functions: custom_mean_abs_log_loss (default) or custom_mean_abs_exp_loss 
* (exponential loss function)
* Run directory: example/experiments/transfer_learning_samples/log/kmeans   (For log loss function)
                 example/experiments/transfer_learning_samples/exp/kmeans   (For exponential loss function)
* Command to run: 
    $ source setup.source
    $ cd example/experiments/transfer_learning_samples/log/kmeans 
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
183
    -config $DEFFE_DIR/example/config_kmeans_tl_samples.json \
Liu, Frank's avatar
Dev    
Liu, Frank committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
    -only-preloaded-data-exploration -epochs 1000 -batch-size 256 \
    -train-test-split 1.0 -validation-split 0.23 

* Command to generate stats. It will load the same training and testing indices used for ML model 
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
    -model-extract-dir checkpoints \
    -config $DEFFE_DIR/example/config_kmeans.json  \
    -only-preloaded-data-exploration \
    -train-test-split 1.0 -validation-split 0.23 \
    -load-train-test -loss custom_mean_abs_exp_loss \
    -model-stats-output test-output-exploss.csv
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
    -model-extract-dir checkpoints \
    -config $DEFFE_DIR/example/config_kmeans.json  \
    -only-preloaded-data-exploration \
    -train-test-split 1.0 -validation-split 0.23 \
    -load-train-test -loss custom_mean_abs_log_loss \
    -model-stats-output test-output-logloss.csv

* Output files: 
    ** Intermediate checkpoint files directory: 
    **    example/experiments/transfer_learning_samples/log/kmeans/checkpoints
    ** Training and Test indexes used: step<int>-train-indices.npy, step<int>-val-indices.npy, 
    ** which have training and validation indexes used for training for that step
    ** Output statistics in file: test-output.csv in the format (Epoch, TrainLoss, ValLoss, 
    ** TestLoss, Step, TrainCount, ValCount)
* Try sample parameters:
    ** Input test-input.csv
    ** Command given below
       $ python3 $DEFFE_DIR/framework/run_deffe.py \
       -config $DEFFE_DIR/example/config_kmeans_tl_samples.json \
       -input test-model.csv \
       -icp kmeans.hdf5 -output output-prediction.csv -inference-only
    ** Output test-output.csv
    ** Input ../../../../output_kmeans_deffe.csv 
    ** Command given below
       $ python3 $DEFFE_DIR/framework/run_deffe.py \
       -config $DEFFE_DIR/example/config_kmeans_tl_samples.json -icp kmeans.hdf5  \
       -input ../../../../output_kmeans_deffe.csv  -output test-output-full.csv \
       -inference-only
    ** Output test-output-full.csv
```

### Run Deffe with Matmul with pre-evaluated data set but passed as set of samples and enabled transfer learning across samples and also enabled transfer learning from kmeans. 
```bash
* Dataset: examples/output_matmul_deffe.csv
* Frozen layers: 2 convolution layers
* Config file: examples/config_matmul_tl_samples.json
* Loss functions: custom_mean_abs_log_loss (default) or custom_mean_abs_exp_loss 
* (exponential loss function)
* Run directory: example/experiments/transfer_learning_samples_across_kernels/log/matmul 
*                               (For log loss function)
*                example/experiments/transfer_learning_samples_across_kernels/exp/matmul  
*                               (For exponential loss function)
* Command to run: 
    $ source setup.source
    $ cd example/experiments/transfer_learning_samples_across_kernels/log/matmul 
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
    -config $DEFFE_DIR/example/config_matmul_tl_samples.json -icp ../../kmeans.hdf5 \
    -only-preloaded-data-exploration -epochs 1000 -batch-size 256 -train-test-split 1.0 \
    -validation-split 0.23 

* Command to generate stats. It will load the same training and testing indices used for ML model 
    $ python3 $DEFFE_DIR/framework/run_deffe.py \
    -model-extract-dir checkpoints \
    -config $DEFFE_DIR/example/config_matmul.json  \
    -only-preloaded-data-exploration \
    -train-test-split 1.0 -validation-split 0.23 -load-train-test \
    -loss custom_mean_abs_exp_loss -model-stats-output test-output-exploss.csv

    $ python3 $DEFFE_DIR/framework/run_deffe.py -model-extract-dir checkpoints \
    -config $DEFFE_DIR/example/config_matmul.json  -only-preloaded-data-exploration \
    -train-test-split 1.0 -validation-split 0.23 -load-train-test \
    -loss custom_mean_abs_log_loss -model-stats-output test-output-logloss.csv

* Output files: 
    ** Intermediate checkpoint files directory: 
    **     example/experiments/transfer_learning_samples_across_kernels/log/matmul/checkpoints
    ** Training and Test indexes used: step<int>-train-indices.npy, step<int>-val-indices.npy, 
    ** which have training and validation indexes used for training for that step
    ** Output statistics in file: test-output.csv in the format (Epoch, TrainLoss, ValLoss,
    ** TestLoss, Step, TrainCount, ValCount)
* Try sample parameters:
    ** Input test-input.csv
    ** Command given below
       $ python3 $DEFFE_DIR/framework/run_deffe.py \
       -config $DEFFE_DIR/example/config_matmul_tl_samples.json -icp matmul.hdf5 \
       -input test-input.csv -output test-output.csv -inference-only
    ** Output test-output.csv
    ** Input ../../../../output_matmul_deffe.csv 
    ** Command given below
       $ python3 $DEFFE_DIR/framework/run_deffe.py \
       -config $DEFFE_DIR/example/config_matmul_tl_samples.json -icp matmul.hdf5  \
       -input ../../../../output_matmul_deffe.csv  -output test-output-full.csv \
       -inference-only
    ** Output test-output-full.csv

```

### Bash scripts in the below directories to run above configurations
```bash
example/experiments/transfer_learning_samples/exp/kmeans/run.sh
example/experiments/transfer_learning_samples/log/kmeans/run.sh
example/experiments/transfer_learning_samples_across_kernels/exp/matmul/run.sh
example/experiments/transfer_learning_samples_across_kernels/log/matmul/run.sh
example/experiments/full_explore/exp/kmeans/run.sh
example/experiments/full_explore/log/kmeans/run.sh
```

## How to extend Deffe?
All classes in Deffe have the below bare minimal methods.
```python
import os
import argparse
import shlex

class DeffeExploration:
    def __init__(self, framework):
        self.config = framework.config.GetExploration()
        self.framework = framework

    # Initialize the members
    def Initialize(self):
        None

    def Run(self):
        None

def GetObject(framework):
    obj = DeffeExploration(framework)
    return obj
```

The "GetObject" method returns the object of the class. It should take the Deffe framework object as an input to configure the class. The class will have "Initialize" and "Run" method. 


## How to configure JSON configuration?
An example JSON configuration file parameters are shown in short given below.
```
{
    "python_path" : ["."],
    "knobs" : 
        [
            ### Array of Knobs (Architecture / Application Knobs) ###
        ],
    "scenarios" : 
        [
            ### Array of Scenarios (Application scenarios) ###
        ],
    "costs" : 
        [ 
            ### Array of Cost metric names ###
        ],
    "model" : {
            ### ML-Model JSON key-value configuration parameters ###
    },
    "exploration" : {
            ### Exploration (DSE) module json key-value configuration parameters ###
    },
    "sampling" : {
            ### Intelligent sampling (Random) module JSON key-value configuration parameters ###
    },
    "evaluate" : {
            ### Evaluate (Sampling points evaluation) module json key-value configuration parameters ###
    },
    "extract" : {
            ### Extract (evaluation output extraction) module json key-value configuration parameters ###
    },
    "framework" : {
            ### Framework  module json key-value configuration parameters ###
    },
    "slurm" : {
            ### Slurm json key-value configuration parameters ###
    }
}
```

Miniskar, Narasinga Rao's avatar
Miniskar, Narasinga Rao committed
361