Skip to content

Commit 37ddc04

Browse files
authored
Merge pull request #232 from sunya-ch/spec-trainer
update curvefit (log func) and generate_spec
2 parents fe75985 + ed4e4a2 commit 37ddc04

File tree

7 files changed

+42
-17
lines changed

7 files changed

+42
-17
lines changed

.github/workflows/push-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
echo "change=true" >> "$GITHUB_OUTPUT"
154154
155155
tekton-test:
156-
needs: [check-secret, check-branch, base-image]
156+
needs: [check-secret, check-branch, check-change, base-image]
157157
if: always()
158158
uses: ./.github/workflows/tekton-test.yml
159159
with:
@@ -164,7 +164,7 @@ jobs:
164164
pipeline_name: std_v0.7
165165

166166
integration-test:
167-
needs: [check-secret, check-branch, base-image]
167+
needs: [check-secret, check-branch, check-change, base-image]
168168
if: always()
169169
uses: ./.github/workflows/integration-test.yml
170170
with:

dockerfiles/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ xgboost==2.0.1
1212
scikit-learn==1.1.2
1313
py-cpuinfo==9.0.0
1414
seaborn==0.12.2
15-
psutil==5.9.8
15+
psutil==5.9.8
16+
pyudev==0.24.1

src/train/profiler/node_type_index.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,44 @@ def rename(name):
3333
return name
3434

3535
def format_processor(processor):
36-
return "_".join(re.sub(r'\(.*\)', '', rename(processor)).split()).replace("-", "_").replace("V", "v").replace("_v", "v")
36+
return "_".join(re.sub(r'\(.*\)', '', rename(processor)).split()).replace("-", "_").lower().replace("_v", "v")
37+
38+
def format_vendor(vendor):
39+
return vendor.split()[0].replace("-","_").replace(",","").replace("'","").lower()
3740

3841
GB = 1024*1024*1024
3942
import psutil
4043
import cpuinfo
44+
import subprocess
45+
46+
import pyudev
47+
4148
def generate_spec(data_path, machine_id):
42-
processor = "unknown"
49+
processor = ""
50+
vendor = ""
4351
cpu_info = cpuinfo.get_cpu_info()
4452
if "brand_raw" in cpu_info:
4553
processor = format_processor(cpu_info["brand_raw"])
54+
context = pyudev.Context()
55+
for device in context.list_devices(subsystem="dmi"):
56+
if device.get('ID_VENDOR') is not None:
57+
vendor = format_vendor(device.get('ID_VENDOR'))
58+
break
4659
cores = psutil.cpu_count(logical=True)
47-
chips = int(cores/psutil.cpu_count(logical=False))
60+
chips = max(1, int(subprocess.check_output('cat /proc/cpuinfo | grep "physical id" | sort -u | wc -l', shell=True)))
61+
threads_per_core = max(1, cores//psutil.cpu_count(logical=False))
4862
memory = psutil.virtual_memory().total
4963
memory_gb = int(memory/GB)
50-
cpu_freq_mhz = round(psutil.cpu_freq(percpu=False).max/100)*100 # round to one decimal of GHz
64+
freq = psutil.cpu_freq(percpu=False)
65+
cpu_freq_mhz = round(max(freq.max, freq.current)/100)*100 # round to one decimal of GHz
5166
spec_values = {
67+
"vendor": vendor,
5268
"processor": processor,
5369
"cores": cores,
5470
"chips": chips,
5571
"memory_gb": memory_gb,
56-
"cpu_freq_mhz": cpu_freq_mhz
72+
"cpu_freq_mhz": cpu_freq_mhz,
73+
"threads_per_core": threads_per_core
5774
}
5875
spec = NodeTypeSpec(**spec_values)
5976
print("Save machine spec ({}): ".format(data_path))

src/train/trainer/ExponentialRegressionTrainer/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from trainer.curvefit import CurveFitTrainer, CurveFitModel
77

88
import numpy as np
9+
import math
10+
11+
def p0_func(x, y):
12+
a = (y.max()-y.min())//math.e # scale value
13+
b = 1 # start from linear
14+
c = y.min() - a # initial offset
15+
return [a,b,c]
916

1017
def expo_func(x, a, b, c):
1118
y = a*np.exp(b*x) + c
@@ -18,4 +25,4 @@ def __init__(self, energy_components, feature_group, energy_source, node_level,
1825
self.fe_files = []
1926

2027
def init_model(self):
21-
return CurveFitModel(expo_func)
28+
return CurveFitModel(expo_func, p0_func=p0_func)

src/train/trainer/LogarithmicRegressionTrainer/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import numpy as np
99

1010
def p0_func(x, y):
11-
print(y.max(), y.min())
1211
a = y.max()-y.min()
13-
b = y.min()
14-
return [a, b]
12+
b = 1
13+
c = y.min()
14+
return [a, b, c]
1515

16-
def log_func(x, a, b):
17-
y = [a * np.log(xi) + b if xi > 0 else 0 for xi in x]
16+
def log_func(x, a, b, c):
17+
y = a*np.log(b*x+1) + c
1818
return y
1919

2020
class LogarithmicRegressionTrainer(CurveFitTrainer):

src/train/trainer/LogisticRegressionTrainer/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def p0_func(x, y):
1111
A = y.max() - y.min() # value range
1212
x0 = 0.5 # sigmoid mid point (as normalized value is in 0 to 1, start mid point = 0.5)
13-
k = A/np.std(y) # growth rate (larger std, lower growth)
13+
k = A//np.std(y) # growth rate (larger std, lower growth)
1414
off = y.min() # initial offset
1515
return [A,x0,k,off]
1616

src/train/trainer/curvefit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def fit(self, X_values, y_values):
3636
flatten_x = self._x_values(X_values)
3737
flatten_y = np.array(y_values).flatten()
3838
if self.p0_func is not None:
39-
self.popt, self.pcov = curve_fit(self.fit_func, flatten_x, flatten_y, p0=self.p0_func(flatten_x, flatten_y), maxfev=20000)
39+
self.popt, self.pcov = curve_fit(self.fit_func, flatten_x, flatten_y, p0=self.p0_func(flatten_x, flatten_y), maxfev=30000)
4040
else:
41-
self.popt, self.pcov = curve_fit(self.fit_func, flatten_x, flatten_y, maxfev=20000)
41+
self.popt, self.pcov = curve_fit(self.fit_func, flatten_x, flatten_y, maxfev=30000)
4242

4343
def predict(self, X_values):
4444
if self.popt is None:

0 commit comments

Comments
 (0)