add GPFLOW to website
This commit is contained in:
parent
dceee6e0ba
commit
b149684d77
|
@ -16,6 +16,15 @@ from analysis.util import get_analysis_logger
|
||||||
LOG = get_analysis_logger(__name__)
|
LOG = get_analysis_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class GPRGDResult():
|
||||||
|
|
||||||
|
def __init__(self, ypreds=None, sigmas=None, minl=None, minl_conf=None):
|
||||||
|
self.ypreds = ypreds
|
||||||
|
self.sigmas = sigmas
|
||||||
|
self.minl = minl
|
||||||
|
self.minl_conf = minl_conf
|
||||||
|
|
||||||
|
|
||||||
def tf_optimize(model, Xnew_arr, learning_rate=0.01, maxiter=100, ucb_beta=3.,
|
def tf_optimize(model, Xnew_arr, learning_rate=0.01, maxiter=100, ucb_beta=3.,
|
||||||
active_dims=None, bounds=None):
|
active_dims=None, bounds=None):
|
||||||
Xnew_arr = check_array(Xnew_arr, copy=False, warn_on_dtype=True, dtype=FLOAT_DTYPES)
|
Xnew_arr = check_array(Xnew_arr, copy=False, warn_on_dtype=True, dtype=FLOAT_DTYPES)
|
||||||
|
@ -61,4 +70,4 @@ def tf_optimize(model, Xnew_arr, learning_rate=0.01, maxiter=100, ucb_beta=3.,
|
||||||
assert_all_finite(y_mean_value)
|
assert_all_finite(y_mean_value)
|
||||||
assert_all_finite(y_var_value)
|
assert_all_finite(y_var_value)
|
||||||
assert_all_finite(loss_value)
|
assert_all_finite(loss_value)
|
||||||
return Xnew_value, y_mean_value, y_var_value, loss_value
|
return GPRGDResult(y_mean_value, y_var_value, loss_value, Xnew_value)
|
||||||
|
|
|
@ -25,6 +25,8 @@ INIT_FLIP_PROB = 0.3
|
||||||
FLIP_PROB_DECAY = 0.5
|
FLIP_PROB_DECAY = 0.5
|
||||||
|
|
||||||
# ---GPR CONSTANTS---
|
# ---GPR CONSTANTS---
|
||||||
|
USE_GPFLOW = True
|
||||||
|
|
||||||
DEFAULT_LENGTH_SCALE = 1.0
|
DEFAULT_LENGTH_SCALE = 1.0
|
||||||
|
|
||||||
DEFAULT_MAGNITUDE = 1.0
|
DEFAULT_MAGNITUDE = 1.0
|
||||||
|
@ -56,6 +58,13 @@ DEFAULT_SIGMA_MULTIPLIER = 3.0
|
||||||
|
|
||||||
DEFAULT_MU_MULTIPLIER = 1.0
|
DEFAULT_MU_MULTIPLIER = 1.0
|
||||||
|
|
||||||
|
DEFAULT_UCB_SCALE = 0.2
|
||||||
|
|
||||||
|
# ---HYPERPARAMETER TUNING FOR GPR---
|
||||||
|
HP_MAX_ITER = 5000
|
||||||
|
|
||||||
|
HP_DEFAULT_LEARNING_RATE = 0.001
|
||||||
|
|
||||||
# ---GRADIENT DESCENT FOR DNN---
|
# ---GRADIENT DESCENT FOR DNN---
|
||||||
DNN_TRAIN_ITER = 500
|
DNN_TRAIN_ITER = 500
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
import random
|
import random
|
||||||
import queue
|
import queue
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import tensorflow as tf
|
||||||
|
import gpflow
|
||||||
from pyDOE import lhs
|
from pyDOE import lhs
|
||||||
from scipy.stats import uniform
|
from scipy.stats import uniform
|
||||||
|
|
||||||
|
@ -18,6 +20,9 @@ from analysis.ddpg.ddpg import DDPG
|
||||||
from analysis.gp import GPRNP
|
from analysis.gp import GPRNP
|
||||||
from analysis.gp_tf import GPRGD
|
from analysis.gp_tf import GPRGD
|
||||||
from analysis.nn_tf import NeuralNet
|
from analysis.nn_tf import NeuralNet
|
||||||
|
from analysis.gpr import gpr_models
|
||||||
|
from analysis.gpr import ucb
|
||||||
|
from analysis.gpr.optimize import tf_optimize
|
||||||
from analysis.preprocessing import Bin, DummyEncoder
|
from analysis.preprocessing import Bin, DummyEncoder
|
||||||
from analysis.constraints import ParamConstraintHelper
|
from analysis.constraints import ParamConstraintHelper
|
||||||
from website.models import PipelineData, PipelineRun, Result, Workload, KnobCatalog, SessionKnob
|
from website.models import PipelineData, PipelineRun, Result, Workload, KnobCatalog, SessionKnob
|
||||||
|
@ -25,11 +30,12 @@ from website import db
|
||||||
from website.types import PipelineTaskType, AlgorithmType
|
from website.types import PipelineTaskType, AlgorithmType
|
||||||
from website.utils import DataUtil, JSONUtil
|
from website.utils import DataUtil, JSONUtil
|
||||||
from website.settings import IMPORTANT_KNOB_NUMBER, NUM_SAMPLES, TOP_NUM_CONFIG # pylint: disable=no-name-in-module
|
from website.settings import IMPORTANT_KNOB_NUMBER, NUM_SAMPLES, TOP_NUM_CONFIG # pylint: disable=no-name-in-module
|
||||||
from website.settings import (DEFAULT_LENGTH_SCALE, DEFAULT_MAGNITUDE,
|
from website.settings import (USE_GPFLOW, DEFAULT_LENGTH_SCALE, DEFAULT_MAGNITUDE,
|
||||||
MAX_TRAIN_SIZE, BATCH_SIZE, NUM_THREADS,
|
MAX_TRAIN_SIZE, BATCH_SIZE, NUM_THREADS,
|
||||||
DEFAULT_RIDGE, DEFAULT_LEARNING_RATE,
|
DEFAULT_RIDGE, DEFAULT_LEARNING_RATE,
|
||||||
DEFAULT_EPSILON, MAX_ITER, GPR_EPS,
|
DEFAULT_EPSILON, MAX_ITER, GPR_EPS,
|
||||||
DEFAULT_SIGMA_MULTIPLIER, DEFAULT_MU_MULTIPLIER,
|
DEFAULT_SIGMA_MULTIPLIER, DEFAULT_MU_MULTIPLIER,
|
||||||
|
DEFAULT_UCB_SCALE, HP_LEARNING_RATE, HP_MAX_ITER,
|
||||||
DDPG_BATCH_SIZE, ACTOR_LEARNING_RATE,
|
DDPG_BATCH_SIZE, ACTOR_LEARNING_RATE,
|
||||||
CRITIC_LEARNING_RATE, UPDATE_EPOCHS,
|
CRITIC_LEARNING_RATE, UPDATE_EPOCHS,
|
||||||
ACTOR_HIDDEN_SIZES, CRITIC_HIDDEN_SIZES,
|
ACTOR_HIDDEN_SIZES, CRITIC_HIDDEN_SIZES,
|
||||||
|
@ -613,18 +619,35 @@ def configuration_recommendation(recommendation_input):
|
||||||
|
|
||||||
elif algorithm == AlgorithmType.GPR:
|
elif algorithm == AlgorithmType.GPR:
|
||||||
# default gpr model
|
# default gpr model
|
||||||
model = GPRGD(length_scale=DEFAULT_LENGTH_SCALE,
|
if USE_GPFLOW:
|
||||||
magnitude=DEFAULT_MAGNITUDE,
|
model_kwargs = {}
|
||||||
max_train_size=MAX_TRAIN_SIZE,
|
model_kwargs['model_learning_rate'] = HP_LEARNING_RATE
|
||||||
batch_size=BATCH_SIZE,
|
model_kwargs['model_maxiter'] = HP_MAX_ITER
|
||||||
num_threads=NUM_THREADS,
|
opt_kwargs = {}
|
||||||
learning_rate=DEFAULT_LEARNING_RATE,
|
opt_kwargs['learning_rate'] = DEFAULT_LEARNING_RATE
|
||||||
epsilon=DEFAULT_EPSILON,
|
opt_kwargs['maxiter'] = MAX_ITER
|
||||||
max_iter=MAX_ITER,
|
opt_kwargs['bounds'] = [X_min, X_max]
|
||||||
sigma_multiplier=DEFAULT_SIGMA_MULTIPLIER,
|
ucb_beta = 'get_beta_td'
|
||||||
mu_multiplier=DEFAULT_MU_MULTIPLIER)
|
opt_kwargs['ucb_beta'] = ucb.get_ucb_beta(ucb_beta, scale=DEFAULT_UCB_SCALE,
|
||||||
model.fit(X_scaled, y_scaled, X_min, X_max, ridge=DEFAULT_RIDGE)
|
t=i + 1., ndim=X_scaled.shape[1])
|
||||||
res = model.predict(X_samples, constraint_helper=constraint_helper)
|
tf.reset_default_graph()
|
||||||
|
graph = tf.get_default_graph()
|
||||||
|
gpflow.reset_default_session(graph=graph)
|
||||||
|
m = gpr_models.create_model('BasicGP', X=X_scaled, y=y_scaled, **model_kwargs)
|
||||||
|
res = tf_optimize(m.model, X_samples, **opt_kwargs)
|
||||||
|
else:
|
||||||
|
model = GPRGD(length_scale=DEFAULT_LENGTH_SCALE,
|
||||||
|
magnitude=DEFAULT_MAGNITUDE,
|
||||||
|
max_train_size=MAX_TRAIN_SIZE,
|
||||||
|
batch_size=BATCH_SIZE,
|
||||||
|
num_threads=NUM_THREADS,
|
||||||
|
learning_rate=DEFAULT_LEARNING_RATE,
|
||||||
|
epsilon=DEFAULT_EPSILON,
|
||||||
|
max_iter=MAX_ITER,
|
||||||
|
sigma_multiplier=DEFAULT_SIGMA_MULTIPLIER,
|
||||||
|
mu_multiplier=DEFAULT_MU_MULTIPLIER)
|
||||||
|
model.fit(X_scaled, y_scaled, X_min, X_max, ridge=DEFAULT_RIDGE)
|
||||||
|
res = model.predict(X_samples, constraint_helper=constraint_helper)
|
||||||
|
|
||||||
best_config_idx = np.argmin(res.minl.ravel())
|
best_config_idx = np.argmin(res.minl.ravel())
|
||||||
best_config = res.minl_conf[best_config_idx, :]
|
best_config = res.minl_conf[best_config_idx, :]
|
||||||
|
|
Loading…
Reference in New Issue