Commit 5bad1c18 authored by LongChan's avatar LongChan
Browse files

added ga and hyper-parameter

parent d5d06703
......@@ -35,16 +35,16 @@ The instruction below will do a sweep run on each of the following networks:
To obtain individual optimization result for a specific network and a specfic number of partition, please refer to the section below.
To get optimization result with
1. CMA-es
1. Covariance Matrix Adaptation Evolution Strategy (CMA-es)
```bash
# cd optimization_algo/scripts
# ./sweep_nets_cma.sh
```
1. GA
1. Genetic Algorithm (GA)
```bash
# cd optimization_algo/scripts
# ./sweep_nets_cma.sh
# ./sweep_nets_ga.sh
```
1. CMA
......
......@@ -3,6 +3,7 @@ import csv
import sys
import random
import operator
import path_constant as pc
from multiprocessing import Pool
from os import cpu_count
......@@ -69,7 +70,7 @@ class ga_approach(object):
def parse_topology_file(self):
layers = []
with open(self.topology_file, 'r') as f:
with open(pc.TOPOLOGIES_PATH+self.topology_file, 'r') as f:
next(f)
for line in f:
elems = line.strip().split(',')
......@@ -82,7 +83,7 @@ class ga_approach(object):
def parse_data_set_file(self, path_to_data_csv):
first = True
target_idx = 2
with open(path_to_data_csv, 'r') as f:
with open(pc.DATA_SOURCE_PATH+path_to_data_csv, 'r') as f:
for line in f:
elems = line.strip().split(',')
# #print(elems)
......@@ -296,7 +297,7 @@ class ga_approach(object):
# print("Throughtput Ratio:", (1/max_latency)/(1/full_latency[full_max_idx]))
# print("Latency increase:", (max_latency*self.k)/full_latency[full_max_idx])
with open('ga.csv', 'a') as csvFile:
with open(pc.RESULT_CSV_PATH+'ga.csv', 'a') as csvFile:
writer = csv.writer(csvFile, delimiter=',', lineterminator="\n")
writer.writerow([self.target_col, self.gen,self.k,self.topology_file, 1,
(1/max_latency), max_latency*self.k,
......
import sys
import time
import csv
import path_constant as pc
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials, pyll
class hyper_parameter(object):
......@@ -42,7 +44,7 @@ class hyper_parameter(object):
def parse_topology_file(self):
layers = []
with open(self.topology_file, 'r') as f:
with open(pc.TOPOLOGIES_PATH+self.topology_file, 'r') as f:
next(f)
for line in f:
elems = line.strip().split(',')
......@@ -63,7 +65,7 @@ class hyper_parameter(object):
def parse_data_set_file(self, path_to_data_csv):
first = True
target_idx = 2
with open(path_to_data_csv, 'r') as f:
with open(pc.DATA_SOURCE_PATH+path_to_data_csv, 'r') as f:
for line in f:
elems = line.strip().split(',')
# #print(elems)
......@@ -164,7 +166,7 @@ class hyper_parameter(object):
full_latency, full_max_idx = self.find_max_latency([self.layers], [self.max_res_unit]*len(self.layers))
feasable = 0
max_latency = 100000000
with open('hyperopt.csv', 'a') as csvFile:
with open(pc.RESULT_CSV_PATH+'hyperopt.csv', 'a') as csvFile:
for stuff in self.trials.trials:
self.i = stuff.get("tid")
self.end = stuff.get("result").get("eval_time")
......
This diff is collapsed.
......@@ -12,14 +12,14 @@ do
for res_unit in 960;
do
for target in DRAM_cycle;
do
do
echo $net $partitions $target
python3 ../approaches/brute_force_approach.py \
${net} \
${partitions} \
${res_unit} \
${target}
done
done
done
done
done
......@@ -10,7 +10,7 @@ declare -a max_partitions=(23 14 9 29 8 8 8 27 13)
#tp_gain, latency_penalty, \
#best_layer_partition, best_resource_partition, \
#time_taken, sigma, seed, valid_sampling_percentage, \
#trial, popsize, res_unit, seeding_type" > cma.csv
#trial, popsize, res_unit, seeding_type" > ../resulting_csv/cma.csv
for i in 8;
do
......@@ -25,14 +25,14 @@ do
do
for target in DRAM_cycle Cycles;
do
echo $net $partitions $strategy
python3 ../approaches/cma_approach.py \
${net} \
${partitions} \
${popsize} \
${res_unit} \
${strategy} \
${target}
echo $net $partitions $strategy
python3 ../approaches/cma_approach.py \
${net} \
${partitions} \
${popsize} \
${res_unit} \
${strategy} \
${target}
done
done
done
......
......@@ -4,13 +4,13 @@ declare -a nets=(FasterRCNN mobilenet yolo_tiny googlenet alexnet AlphaGoZero nc
declare -a layers=(46 27 10 58 8 8 8 53)
declare -a max_partitions=(23 14 9 29 8 8 8 27)
echo "target, evo_counter,partitions,topology, feasable, \
tp_partition, latency_partition, \
tp_fullmap, latency_fm, \
tp_gain, latency_penalty, \
best_layer_partition, best_resource_partition, \
time_taken, sigma, seed, valid_sampling_percentage, \
trial, popsize, res_unit, seeding_type" > ga.csv
# echo "target, evo_counter,partitions,topology, feasable, \
# tp_partition, latency_partition, \
# tp_fullmap, latency_fm, \
# tp_gain, latency_penalty, \
# best_layer_partition, best_resource_partition, \
# time_taken, sigma, seed, valid_sampling_percentage, \
# trial, popsize, res_unit, seeding_type" > ../resulting_csv/ga.csv
for i in 0 1 2 3 4 5 6 7;
do
......@@ -24,16 +24,16 @@ do
for res_unit in 960;
do
for target in DRAM_cycle Cycles;
do
do
echo $net $partitions $target
python3 ga_approach.py \
python3 ../approaches/ga_approach.py \
${net} \
${partitions} \
${elite_popsize} \
${popsize} \
${res_unit} \
${target}
done
${target}
done
done
done
done
......
......@@ -4,13 +4,13 @@ declare -a nets=(FasterRCNN mobilenet yolo_tiny googlenet alexnet AlphaGoZero nc
declare -a layers=(46 27 10 58 8 8 8 53)
declare -a max_partitions=(23 14 9 29 8 8 8 27)
echo "target, evo_counter,partitions,topology, feasable, \
tp_partition, latency_partition, \
tp_fullmap, latency_fm, \
tp_gain, latency_penalty, \
best_layer_partition, best_resource_partition, \
time_taken, sigma, seed, valid_sampling_percentage, \
trial, popsize, res_unit, seeding_type" > hyperopt.csv
# echo "target, evo_counter,partitions,topology, feasable, \
# tp_partition, latency_partition, \
# tp_fullmap, latency_fm, \
# tp_gain, latency_penalty, \
# best_layer_partition, best_resource_partition, \
# time_taken, sigma, seed, valid_sampling_percentage, \
# trial, popsize, res_unit, seeding_type" > ../resulting_csv/hyperopt.csv
for i in 0 1 2 3 4 5 6 7;
do
......@@ -20,15 +20,15 @@ do
for res_unit in 960;
do
for target in DRAM_cycle Cycles;
do
do
echo $net $partitions $target
python3 hyper_parameter_ga.py \
python3 ../approaches/hyper_parameter_ga.py \
${net} \
${partitions} \
${res_unit} \
${target} \
2500
done
done
done
done
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment