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: ...@@ -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 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 To get optimization result with
1. CMA-es 1. Covariance Matrix Adaptation Evolution Strategy (CMA-es)
```bash ```bash
# cd optimization_algo/scripts # cd optimization_algo/scripts
# ./sweep_nets_cma.sh # ./sweep_nets_cma.sh
``` ```
1. GA 1. Genetic Algorithm (GA)
```bash ```bash
# cd optimization_algo/scripts # cd optimization_algo/scripts
# ./sweep_nets_cma.sh # ./sweep_nets_ga.sh
``` ```
1. CMA 1. CMA
......
...@@ -3,6 +3,7 @@ import csv ...@@ -3,6 +3,7 @@ import csv
import sys import sys
import random import random
import operator import operator
import path_constant as pc
from multiprocessing import Pool from multiprocessing import Pool
from os import cpu_count from os import cpu_count
...@@ -69,7 +70,7 @@ class ga_approach(object): ...@@ -69,7 +70,7 @@ class ga_approach(object):
def parse_topology_file(self): def parse_topology_file(self):
layers = [] layers = []
with open(self.topology_file, 'r') as f: with open(pc.TOPOLOGIES_PATH+self.topology_file, 'r') as f:
next(f) next(f)
for line in f: for line in f:
elems = line.strip().split(',') elems = line.strip().split(',')
...@@ -82,7 +83,7 @@ class ga_approach(object): ...@@ -82,7 +83,7 @@ class ga_approach(object):
def parse_data_set_file(self, path_to_data_csv): def parse_data_set_file(self, path_to_data_csv):
first = True first = True
target_idx = 2 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: for line in f:
elems = line.strip().split(',') elems = line.strip().split(',')
# #print(elems) # #print(elems)
...@@ -296,7 +297,7 @@ class ga_approach(object): ...@@ -296,7 +297,7 @@ class ga_approach(object):
# print("Throughtput Ratio:", (1/max_latency)/(1/full_latency[full_max_idx])) # print("Throughtput Ratio:", (1/max_latency)/(1/full_latency[full_max_idx]))
# print("Latency increase:", (max_latency*self.k)/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 = csv.writer(csvFile, delimiter=',', lineterminator="\n")
writer.writerow([self.target_col, self.gen,self.k,self.topology_file, 1, writer.writerow([self.target_col, self.gen,self.k,self.topology_file, 1,
(1/max_latency), max_latency*self.k, (1/max_latency), max_latency*self.k,
......
import sys import sys
import time import time
import csv import csv
import path_constant as pc
from hyperopt import fmin, tpe, hp, STATUS_OK, Trials, pyll from hyperopt import fmin, tpe, hp, STATUS_OK, Trials, pyll
class hyper_parameter(object): class hyper_parameter(object):
...@@ -42,7 +44,7 @@ class hyper_parameter(object): ...@@ -42,7 +44,7 @@ class hyper_parameter(object):
def parse_topology_file(self): def parse_topology_file(self):
layers = [] layers = []
with open(self.topology_file, 'r') as f: with open(pc.TOPOLOGIES_PATH+self.topology_file, 'r') as f:
next(f) next(f)
for line in f: for line in f:
elems = line.strip().split(',') elems = line.strip().split(',')
...@@ -63,7 +65,7 @@ class hyper_parameter(object): ...@@ -63,7 +65,7 @@ class hyper_parameter(object):
def parse_data_set_file(self, path_to_data_csv): def parse_data_set_file(self, path_to_data_csv):
first = True first = True
target_idx = 2 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: for line in f:
elems = line.strip().split(',') elems = line.strip().split(',')
# #print(elems) # #print(elems)
...@@ -164,7 +166,7 @@ class hyper_parameter(object): ...@@ -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)) full_latency, full_max_idx = self.find_max_latency([self.layers], [self.max_res_unit]*len(self.layers))
feasable = 0 feasable = 0
max_latency = 100000000 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: for stuff in self.trials.trials:
self.i = stuff.get("tid") self.i = stuff.get("tid")
self.end = stuff.get("result").get("eval_time") self.end = stuff.get("result").get("eval_time")
......
This diff is collapsed.
...@@ -12,14 +12,14 @@ do ...@@ -12,14 +12,14 @@ do
for res_unit in 960; for res_unit in 960;
do do
for target in DRAM_cycle; for target in DRAM_cycle;
do do
echo $net $partitions $target echo $net $partitions $target
python3 ../approaches/brute_force_approach.py \ python3 ../approaches/brute_force_approach.py \
${net} \ ${net} \
${partitions} \ ${partitions} \
${res_unit} \ ${res_unit} \
${target} ${target}
done done
done done
done done
done done
...@@ -10,7 +10,7 @@ declare -a max_partitions=(23 14 9 29 8 8 8 27 13) ...@@ -10,7 +10,7 @@ declare -a max_partitions=(23 14 9 29 8 8 8 27 13)
#tp_gain, latency_penalty, \ #tp_gain, latency_penalty, \
#best_layer_partition, best_resource_partition, \ #best_layer_partition, best_resource_partition, \
#time_taken, sigma, seed, valid_sampling_percentage, \ #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; for i in 8;
do do
...@@ -25,14 +25,14 @@ do ...@@ -25,14 +25,14 @@ do
do do
for target in DRAM_cycle Cycles; for target in DRAM_cycle Cycles;
do do
echo $net $partitions $strategy echo $net $partitions $strategy
python3 ../approaches/cma_approach.py \ python3 ../approaches/cma_approach.py \
${net} \ ${net} \
${partitions} \ ${partitions} \
${popsize} \ ${popsize} \
${res_unit} \ ${res_unit} \
${strategy} \ ${strategy} \
${target} ${target}
done done
done done
done done
......
...@@ -4,13 +4,13 @@ declare -a nets=(FasterRCNN mobilenet yolo_tiny googlenet alexnet AlphaGoZero nc ...@@ -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 layers=(46 27 10 58 8 8 8 53)
declare -a max_partitions=(23 14 9 29 8 8 8 27) declare -a max_partitions=(23 14 9 29 8 8 8 27)
echo "target, evo_counter,partitions,topology, feasable, \ # echo "target, evo_counter,partitions,topology, feasable, \
tp_partition, latency_partition, \ # tp_partition, latency_partition, \
tp_fullmap, latency_fm, \ # tp_fullmap, latency_fm, \
tp_gain, latency_penalty, \ # tp_gain, latency_penalty, \
best_layer_partition, best_resource_partition, \ # best_layer_partition, best_resource_partition, \
time_taken, sigma, seed, valid_sampling_percentage, \ # time_taken, sigma, seed, valid_sampling_percentage, \
trial, popsize, res_unit, seeding_type" > ga.csv # trial, popsize, res_unit, seeding_type" > ../resulting_csv/ga.csv
for i in 0 1 2 3 4 5 6 7; for i in 0 1 2 3 4 5 6 7;
do do
...@@ -24,16 +24,16 @@ do ...@@ -24,16 +24,16 @@ do
for res_unit in 960; for res_unit in 960;
do do
for target in DRAM_cycle Cycles; for target in DRAM_cycle Cycles;
do do
echo $net $partitions $target echo $net $partitions $target
python3 ga_approach.py \ python3 ../approaches/ga_approach.py \
${net} \ ${net} \
${partitions} \ ${partitions} \
${elite_popsize} \ ${elite_popsize} \
${popsize} \ ${popsize} \
${res_unit} \ ${res_unit} \
${target} ${target}
done done
done done
done done
done done
......
...@@ -4,13 +4,13 @@ declare -a nets=(FasterRCNN mobilenet yolo_tiny googlenet alexnet AlphaGoZero nc ...@@ -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 layers=(46 27 10 58 8 8 8 53)
declare -a max_partitions=(23 14 9 29 8 8 8 27) declare -a max_partitions=(23 14 9 29 8 8 8 27)
echo "target, evo_counter,partitions,topology, feasable, \ # echo "target, evo_counter,partitions,topology, feasable, \
tp_partition, latency_partition, \ # tp_partition, latency_partition, \
tp_fullmap, latency_fm, \ # tp_fullmap, latency_fm, \
tp_gain, latency_penalty, \ # tp_gain, latency_penalty, \
best_layer_partition, best_resource_partition, \ # best_layer_partition, best_resource_partition, \
time_taken, sigma, seed, valid_sampling_percentage, \ # time_taken, sigma, seed, valid_sampling_percentage, \
trial, popsize, res_unit, seeding_type" > hyperopt.csv # trial, popsize, res_unit, seeding_type" > ../resulting_csv/hyperopt.csv
for i in 0 1 2 3 4 5 6 7; for i in 0 1 2 3 4 5 6 7;
do do
...@@ -20,15 +20,15 @@ do ...@@ -20,15 +20,15 @@ do
for res_unit in 960; for res_unit in 960;
do do
for target in DRAM_cycle Cycles; for target in DRAM_cycle Cycles;
do do
echo $net $partitions $target echo $net $partitions $target
python3 hyper_parameter_ga.py \ python3 ../approaches/hyper_parameter_ga.py \
${net} \ ${net} \
${partitions} \ ${partitions} \
${res_unit} \ ${res_unit} \
${target} \ ${target} \
2500 2500
done done
done 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