Welcome to advisor’s documentation!

Advisor

简介

Advisor is the hyper parameters tuning system for black box optimization.

It is the open-source implementation of Google Vizier with these features.

  • Easy to use with API, SDK, WEB and CLI
  • Support abstractions of Study and Trial
  • Included search and early stop algorithms
  • Recommend parameters with trained model
  • Same programming interfaces as Google Vizier
  • Command-line tool just like Microsoft NNI.

算法

  • [x] Grid Search
  • [x] Random Search
  • [x] Bayesian Optimization
  • [x] TPE(Hyperopt)
  • [x] Random Search(Hyperopt)
  • [x] Simulate Anneal(Hyperopt)
  • [x] Quasi Random(Chocolate)
  • [x] Grid Search(Chocolate)
  • [x] Random Search(Chocolate)
  • [x] Bayes(Chocolate)
  • [x] CMAES(Chocolate)
  • [x] MOCMAES(Chocolate)
  • [ ] SMAC Algorithm
  • [x] Early Stop First Trial Algorithm
  • [x] Early Stop Descending Algorithm
  • [ ] Performance Curve Stop Algorithm

安装

Pip

pip install advisor

From Source

git clone git@github.com:tobegit3hub/advisor.git

cd ./advisor/advisor_client/

python ./setup.py install

Docker

docker run -d -p 8000:8000 tobegit3hub/advisor

Docker Compose

wget https://raw.githubusercontent.com/tobegit3hub/advisor/master/docker-compose.yml

docker-compose up -d

Kubernetes

wget https://raw.githubusercontent.com/tobegit3hub/advisor/master/kubernetes_advisor.yaml

kubectl create -f ./kubernetes_advisor.yaml

快速使用

使用pip安装。

pip install advisor

启动服务器。

advisor_admin server start

在浏览器打开http://127.0.0.1:8000

提交调优任务。

git clone --depth 1 https://github.com/tobegit3hub/advisor.git && cd ./advisor/

advisor run -f ./advisor_client/examples/python_function/config.json

获取任务结果。

advisor study describe -s demo

服务器

命令行

advisor_admin server start

Docker

docker run -d -p 8000:8000 tobegit3hub/advisor

Docker Compose

wget https://raw.githubusercontent.com/tobegit3hub/advisor/master/docker-compose.yml

docker-compose up -d

Kubernetes

wget https://raw.githubusercontent.com/tobegit3hub/advisor/master/kubernetes_advisor.yaml

kubectl create -f ./kubernetes_advisor.yaml

源码启动

git clone --depth 1 https://github.com/tobegit3hub/advisor.git && cd ./advisor/

pip install -r ./requirements.txt

./manage.py migrate

./manage.py runserver 0.0.0.0:8000

命令行

启动服务

advisor_admin server start

停止服务

advisor_admin server stop

提交任务

advisor run -f ./advisor_client/examples/python_function/config.json

列举Study

advisor study list

查看Study

advisor study describe -s demo

列举Trial

advisor trials list

SDK

创建客户端对象

client = AdvisorClient()

创建Study

study_configuration = {
  "goal":
  "MINIMIZE",
  "randomInitTrials":
  1,
  "maxTrials":
  5,
  "maxParallelTrials":
  1,
  "params": [
      {
          "parameterName": "gamma",
          "type": "DOUBLE",
          "minValue": 0.001,
          "maxValue": 0.01,
          "feasiblePoints": "",
          "scalingType": "LINEAR"
      },
      {
          "parameterName": "C",
          "type": "DOUBLE",
          "minValue": 0.5,
          "maxValue": 1.0,
          "feasiblePoints": "",
          "scalingType": "LINEAR"
      },
      {
          "parameterName": "kernel",
          "type": "CATEGORICAL",
          "minValue": 0,
          "maxValue": 0,
          "feasiblePoints": "linear, poly, rbf, sigmoid, precomputed",
          "scalingType": "LINEAR"
      },
      {
          "parameterName": "coef0",
          "type": "DOUBLE",
          "minValue": 0.0,
          "maxValue": 0.5,
          "feasiblePoints": "",
          "scalingType": "LINEAR"
      },
  ]
}
study = client.create_study("Study", study_configuration,
                          "BayesianOptimization")

获取Study

study = client.get_study_by_id(6)

获取Trial

trials = client.get_suggestions(study.id, 3)

生成参数

parameter_value_dicts = []
for trial in trials:
  parameter_value_dict = json.loads(trial.parameter_values)
  print("The suggested parameters: {}".format(parameter_value_dict))
  parameter_value_dicts.append(parameter_value_dict)

运行训练

metrics = []
for i in range(len(trials)):
  metric = train_function(**parameter_value_dicts[i])
  metrics.append(metric)

完成Trial

for i in range(len(trials)):
  trial = trials[i]
  client.complete_trial_with_one_metric(trial, metrics[i])
is_done = client.is_study_done(study.id)
best_trial = client.get_best_trial(study.id)
print("The study: {}, best trial: {}".format(study, best_trial))

配置文件

YAML示例

name: "demo"
algorithm: "BayesianOptimization"
trialNumber: 10
path: "./advisor_client/examples/python_function/"
command: "./min_function.py"
search_space:
  goal: "MINIMIZE"
  randomInitTrials: 3
  params:
    - parameterName: "x"
      type: "DOUBLE"
      minValue: -10.0
      maxValue: 10.0

JSON示例

{
  "name": "demo",
  "algorithm": "BayesianOptimization",
  "trialNumber": 10,
  "concurrency": 1,
  "path": "./advisor_client/examples/python_function/",
  "command": "./min_function.py",
  "search_space": {
      "goal": "MINIMIZE",
      "randomInitTrials": 3,
      "params": [
          {
              "parameterName": "x",
              "type": "DOUBLE",
              "minValue": -10.0,
              "maxValue": 10.0,
              "scalingType": "LINEAR"
          }
      ]
  }
}