Skip to content

Commit

Permalink
Merge pull request #195 from sunya-ch/tekton-prerequisite
Browse files Browse the repository at this point in the history
add isolate_from_data and train_from_data, with refactor entrypoint (tekton prerequisite)
  • Loading branch information
rootfs authored Nov 29, 2023
2 parents fb24110 + 5d2591d commit e2a3b1b
Show file tree
Hide file tree
Showing 8 changed files with 729 additions and 478 deletions.
57 changes: 0 additions & 57 deletions cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,6 @@

Use kepler model server function as a standalone docker container.

```
usage: main.py [-h] [-i INPUT] [-o OUTPUT] [-s SERVER] [--interval INTERVAL] [--step STEP] [--metric-prefix METRIC_PREFIX] [-p PIPELINE_NAME] [--extractor EXTRACTOR] [--isolator ISOLATOR] [--profile PROFILE] [--target-hints TARGET_HINTS] [--bg-hints BG_HINTS]
[-e ENERGY_SOURCE] [--abs-trainers ABS_TRAINERS] [--dyn-trainers DYN_TRAINERS] [--benchmark BENCHMARK] [-ot OUTPUT_TYPE] [-fg FEATURE_GROUP] [--model-name MODEL_NAME] [--target-data TARGET_DATA] [--scenario SCENARIO] [--id ID] [--version VERSION]
[--publisher PUBLISHER] [--include-raw INCLUDE_RAW]
command
Kepler model server entrypoint
positional arguments:
command The command to execute.
optional arguments:
-h, --help show this help message and exit
-i INPUT, --input INPUT
Specify input file/folder name.
-o OUTPUT, --output OUTPUT
Specify output file/folder name
-s SERVER, --server SERVER
Specify prometheus server.
--interval INTERVAL Specify query interval.
--step STEP Specify query step.
--metric-prefix METRIC_PREFIX
Specify metrix prefix to filter.
-p PIPELINE_NAME, --pipeline-name PIPELINE_NAME
Specify pipeline name.
--extractor EXTRACTOR
Specify extractor name (default, smooth).
--isolator ISOLATOR Specify isolator name (none, min, profile, trainer).
--profile PROFILE Specify profile input (required for trainer and profile isolator).
--target-hints TARGET_HINTS
Specify dynamic workload container name hints (used by TrainIsolator)
--bg-hints BG_HINTS Specify background workload container name hints (used by TrainIsolator)
-e ENERGY_SOURCE, --energy-source ENERGY_SOURCE
Specify energy source.
--abs-trainers ABS_TRAINERS
Specify trainer names (use comma(,) as delimiter).
--dyn-trainers DYN_TRAINERS
Specify trainer names (use comma(,) as delimiter).
--benchmark BENCHMARK
Specify benchmark file name.
-ot OUTPUT_TYPE, --output-type OUTPUT_TYPE
Specify output type (AbsPower or DynPower) for energy estimation.
-fg FEATURE_GROUP, --feature-group FEATURE_GROUP
Specify target feature group for energy estimation.
--model-name MODEL_NAME
Specify target model name for energy estimation.
--target-data TARGET_DATA
Speficy target plot data (preprocess, estimate)
--scenario SCENARIO Speficy scenario
--id ID specify machine id
--version VERSION Specify model server version.
--publisher PUBLISHER
Specify github account of model publisher
--include-raw INCLUDE_RAW
Include raw query data
```

## Get started

1. Deploy Kepler with Prometheus in the cluster exporting prometheus to port `:9090`
Expand Down
113 changes: 113 additions & 0 deletions cmd/cmd_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os
import sys

cur_path = os.path.join(os.path.dirname(__file__), '.')
sys.path.append(cur_path)
src_path = os.path.join(os.path.dirname(__file__), '..', 'src')
sys.path.append(src_path)

from util.prom_types import TIMESTAMP_COL
from util import PowerSourceMap


def ts_plot(data, cols, title, output_folder, name, labels=None, subtitles=None, ylabel=None):
plot_height = 3
plot_width = 10
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font_scale=1.2)
fig, axes = plt.subplots(len(cols), 1, figsize=(plot_width, len(cols)*plot_height))
for i in range(0, len(cols)):
if len(cols) == 1:
ax = axes
else:
ax = axes[i]
if isinstance(cols[i], list):
# multiple lines
for j in range(0, len(cols[i])):
sns.lineplot(data=data, x=TIMESTAMP_COL, y=cols[i][j], ax=ax, label=labels[j])
ax.set_title(subtitles[i])
else:
sns.lineplot(data=data, x=TIMESTAMP_COL, y=cols[i], ax=ax)
ax.set_title(cols[i])
if ylabel is not None:
ax.set_ylabel(ylabel)
plt.suptitle(title, x=0.5, y=0.99)
plt.tight_layout()
filename = os.path.join(output_folder, name + ".png")
fig.savefig(filename)
plt.close()

def feature_power_plot(data, model_id, output_type, energy_source, feature_cols, actual_power_cols, predicted_power_cols, output_folder, name):
plot_height = 5
plot_width = 5

import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font_scale=1.2)
row_num = len(feature_cols)
col_num = len(actual_power_cols)
width = max(10, col_num*plot_width)
fig, axes = plt.subplots(row_num, col_num, figsize=(width, row_num*plot_height))
for xi in range(0, row_num):
feature_col = feature_cols[xi]
for yi in range(0, col_num):
if row_num == 1:
if col_num == 1:
ax = axes
else:
ax = axes[yi]
else:
if col_num == 1:
ax = axes[xi]
else:
ax = axes[xi][yi]
sorted_data = data.sort_values(by=[feature_col])
sns.scatterplot(data=sorted_data, x=feature_col, y=actual_power_cols[yi], ax=ax, label="actual")
sns.lineplot(data=sorted_data, x=feature_col, y=predicted_power_cols[yi], ax=ax, label="predicted", color='C1')
if xi == 0:
ax.set_title(actual_power_cols[yi])
if yi == 0:
ax.set_ylabel("Power (W)")
title = "{} {} prediction correlation \n by {}".format(energy_source, output_type, model_id)
plt.suptitle(title, x=0.5, y=0.99)
plt.tight_layout()
filename = os.path.join(output_folder, name + ".png")
fig.savefig(filename)
plt.close()

def summary_plot(args, energy_source, summary_df, output_folder, name):
if len(summary_df) == 0:
print("no summary data to plot")
return

plot_height = 3
plot_width = 20

import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font_scale=1.2)

energy_components = PowerSourceMap[energy_source]
col_num = len(energy_components)
fig, axes = plt.subplots(col_num, 1, figsize=(plot_width, plot_height*col_num))
for i in range(0, col_num):
component = energy_components[i]
data = summary_df[(summary_df["energy_source"]==energy_source) & (summary_df["energy_component"]==component)]
data = data.sort_values(by=["Feature Group", "MAE"])
if col_num == 1:
ax = axes
else:
ax = axes[i]
sns.barplot(data=data, x="Feature Group", y="MAE", hue="Model", ax=ax)
ax.set_title(component)
ax.set_ylabel("MAE (Watt)")
ax.set_ylim((0, 100))
if i < col_num-1:
ax.set_xlabel("")
ax.legend(bbox_to_anchor=(1.05, 1.05))
plt.suptitle("{} {} error".format(energy_source, args.output_type))
plt.tight_layout()
filename = os.path.join(output_folder, name + ".png")
fig.savefig(filename)
plt.close()
Loading

0 comments on commit e2a3b1b

Please sign in to comment.