-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
ax_complete_trials_component.yaml
63 lines (56 loc) · 2.17 KB
/
ax_complete_trials_component.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) Facebook, Inc. and its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: AX Complete Trails
description: |
Complete Trials for Training.
inputs:
- {name: Client}
- {name: Training Results}
outputs:
- {name: Best Parameters, description: 'Best Model Parameters'}
implementation:
container:
image: python:3.8
command:
- sh
- -ec
- |
# This is how additional packages can be installed dynamically
python3 -m pip install --user --no-warn-script-location ax-platform SQLAlchemy
# Run the rest of the command after installing the packages.
"$0" "$@"
- python3
- -u # Auto-flush. We want the logs to appear in the console immediately.
- -c # Inline scripts are easy, but have size limitaions and the error traces do not show source lines.
- |
import os
import sys
import json
from ax.service.ax_client import AxClient
client_json_path = sys.argv[1]
results = sys.argv[2]
best_parameters_path = sys.argv[3]
ax_client = AxClient()
client_json = client_json_path+'/client.json'
ax_client = ax_client.load_from_json_file(client_json)
with open(results, 'r') as fp:
data = json.load(fp)
for trial_index in data:
ax_client.complete_trial(int(trial_index), data[trial_index])
best_parameters, metrics = ax_client.get_best_parameters()
os.makedirs(os.path.dirname(best_parameters_path), exist_ok=True)
with open(best_parameters_path, 'w') as writer:
writer.write(json.dumps(best_parameters))
- {inputPath: Client}
- {inputValue: Training Results}
- {outputPath: Best Parameters}