使用ml-engine进行的超参数调整返回状态:失败

时间:2019-10-07 11:38:35

标签: tensorflow google-cloud-ml hyperparameters

我正在尝试使用ml-engine调整模型的超参数,但是我不确定其是否正常工作。

我没有在algorithm中指定HyperparameterSpec标记,根据文档,该标记应默认为贝叶斯优化方法。我也没有设置maxFailedTrials,根据文档,如果第一个失败,则应终止所有路径。

这是我的配置

trainingInput:
  scaleTier: CUSTOM
  masterType: standard_gpu
  hyperparameters:
    goal: MAXIMIZE
    maxTrials: 8
    maxParallelTrials: 2
    hyperparameterMetricTag: test_accuracy
    params:
    - parameterName: dropout_rate
      type: DOUBLE
      minValue: 0.3
      maxValue: 0.7
      scaleType: UNIT_LINEAR_SCALE
    - parameterName: lr
      type: DOUBLE
      minValue: 0.0001
      maxValue: 0.0003
      scaleType: UNIT_LINEAR_SCALE

这是训练输出:

{
  "completedTrialCount": "8",
  "trials": [
    {
      "trialId": "1",
      "hyperparameters": {
        "lr": "0.00014959385395050048",
        "dropout_rate": "0.42217149734497067"
      },
      "startTime": "2019-10-07T09:40:02.143968039Z",
      "endTime": "2019-10-07T09:47:50Z",
      "state": "FAILED"
    },
    {
      "trialId": "2",
      "hyperparameters": {
        "dropout_rate": "0.62217149734497068",
        "lr": "0.00028292718728383382"
      },
      "startTime": "2019-10-07T09:40:02.144192681Z",
      "endTime": "2019-10-07T09:47:19Z",
      "state": "FAILED"
    },
    {
      "trialId": "3",
      "hyperparameters": {
        "lr": "0.00014846909046173097",
        "dropout_rate": "0.31717863082885739"
      },
      "startTime": "2019-10-07T09:48:09.266596472Z",
      "endTime": "2019-10-07T09:55:26Z",
      "state": "FAILED"
    },
    {
      "trialId": "4",
      "hyperparameters": {
        "lr": "0.00018741662502288819",
        "dropout_rate": "0.34178204536437984"
      },
      "startTime": "2019-10-07T09:48:10.761305330Z",
      "endTime": "2019-10-07T09:55:58Z",
      "state": "FAILED"
    },
    {
      "trialId": "5",
      "hyperparameters": {
        "dropout_rate": "0.6216828346252441",
        "lr": "0.00010192830562591553"
      },
      "startTime": "2019-10-07T09:56:15.904704865Z",
      "endTime": "2019-10-07T10:04:04Z",
      "state": "FAILED"
    },
    {
      "trialId": "6",
      "hyperparameters": {
        "dropout_rate": "0.42288427352905272",
        "lr": "0.000230206298828125"
      },
      "startTime": "2019-10-07T09:56:17.895067636Z",
      "endTime": "2019-10-07T10:04:05Z",
      "state": "FAILED"
    },
    {
      "trialId": "7",
      "hyperparameters": {
        "lr": "0.00019101441543291624",
        "dropout_rate": "0.36415641310447144"
      },
      "startTime": "2019-10-07T10:05:22.147233194Z",
      "endTime": "2019-10-07T10:13:09Z",
      "state": "FAILED"
    },
    {
      "trialId": "8",
      "hyperparameters": {
        "dropout_rate": "0.69955616224911532",
        "lr": "0.00029989311482522672"
      },
      "startTime": "2019-10-07T10:05:22.147396438Z",
      "endTime": "2019-10-07T10:13:30Z",
      "state": "FAILED"
    }
  ],
  "consumedMLUnits": 2.29,
  "isHyperparameterTuningJob": true,
  "hyperparameterMetricTag": "test_accuracy"
}

所有路径均已运行,因此我认为其搜索算法由于某种原因而失败。我还无法通过运行另一个详细信息来找到有关其为什么从搜索算法中返回此日志或任何日志的更多信息。

在我看来,它似乎无法在tensorflow事件文件中找到指标,但我不明白为什么,因为名称完全相同,所以使用tensorboard打开事件文件我能够看到数据。也许对我不知道的日志结构有一些要求?

用于记录指标的代码:

from tensorflow.contrib.summary import summary as summary_ops

# in __init__
self.tf_board_writer = summary_ops.create_file_writer(self.save_path)
....

# During training
with self.tf_board_writer.as_default(), summary_ops.always_record_summaries():
    summary_ops.scalar(name=name, tensor=value, step=step)

既然TF2稳定并已发布,ml-engine团队是否还有其他小问题出现在这里,您是否知道它何时可以在运行时环境中使用?

无论如何,希望有人能帮助我:)

1 个答案:

答案 0 :(得分:1)

可以通过使用带有以下代码的python软件包cloudml-hypertune来解决该问题:

self.hpt.report_hyperparameter_tuning_metric(
            hyperparameter_metric_tag=hypeparam_metric_name,
            metric_value=value,
            global_step=step)

然后将hyperparameterMetricTag中的HyperparameterSpec设置为hypeparam_metric_name