Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend Katib API for NAS jobs #327

Merged
merged 45 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
89e56a3
Add fields to studyjob structure
andreyvelich Dec 14, 2018
67ce5ee
Change nasjob yaml file
andreyvelich Dec 14, 2018
7fe9b7d
Change parameter type
andreyvelich Dec 18, 2018
9b8764d
Merge remote-tracking branch 'upstream/master' into 293-extend-sj-str…
andreyvelich Dec 18, 2018
f6eb5ce
Add Parameter Type=range
andreyvelich Dec 20, 2018
743265b
Change API
andreyvelich Jan 7, 2019
3e5a371
Change api.proto
andreyvelich Jan 7, 2019
abd564e
Change input size
andreyvelich Jan 7, 2019
4342a8b
Reset API structure
andreyvelich Jan 14, 2019
f673386
Change StudyJob API structure
andreyvelich Jan 14, 2019
fdb51d1
Remove Range parameter
andreyvelich Jan 15, 2019
6edb518
Fix api.proto
andreyvelich Jan 15, 2019
de9a6d7
Fix gopkg.toml
andreyvelich Jan 15, 2019
945d3fd
Remove old nasjob file
andreyvelich Jan 15, 2019
972cf30
Fix nasjob.yaml
andreyvelich Jan 15, 2019
ac63ac0
Add custom suggestion
andreyvelich Jan 15, 2019
1ff6840
Add blank NAS suggestion
andreyvelich Jan 17, 2019
e8c9636
Add correct YAML file for NAS example
andreyvelich Jan 17, 2019
f5498e4
Fix newline
andreyvelich Jan 17, 2019
7c15d64
Change StudyID to 1
andreyvelich Jan 17, 2019
2f8dc49
Add jobType parameter in Parsing
andreyvelich Jan 17, 2019
7ed6b0a
Remove changes in manager
andreyvelich Jan 17, 2019
9546fef
Add NasConfig inside Yaml file
andreyvelich Jan 18, 2019
a18466e
Fix name in nasConfig
andreyvelich Jan 18, 2019
3318467
Merge remote-tracking branch 'upstream/master' into 293-extend-sj-str…
andreyvelich Jan 18, 2019
04cdfbf
Fix get StudyConfig in NAS
andreyvelich Jan 18, 2019
f5a5d83
Add JobType in all services
andreyvelich Jan 18, 2019
a01710c
Add job_type in bayesian_service
andreyvelich Jan 18, 2019
f1dac5c
Add pointers in NasConfig structure
andreyvelich Jan 18, 2019
d653643
Fix Pointer in API
andreyvelich Jan 18, 2019
2802c6f
Add consts for jobType
andreyvelich Jan 18, 2019
794e7cc
Move const jobType to const file
andreyvelich Jan 19, 2019
4fa52ae
Remove Range parameter
andreyvelich Jan 22, 2019
7ca5f0c
Modify YAML file for NAS jobs
andreyvelich Jan 23, 2019
437b614
Add getStudyJobType function in GRPC server
andreyvelich Jan 24, 2019
9db4a81
Add blank GetStudyJobType func in manager
andreyvelich Jan 24, 2019
8f0d206
Merge remote-tracking branch 'upstream/master' into 293-extend-sj-str…
andreyvelich Jan 24, 2019
2324741
Fix metrics collector
andreyvelich Jan 24, 2019
8766eda
Remove jobType from getStudy
andreyvelich Jan 25, 2019
c362703
Remove getStudyJobType from manager
andreyvelich Jan 25, 2019
4df7151
Add NAS RL yaml deployment
andreyvelich Jan 25, 2019
b0fb3cd
Change worker to GPU
andreyvelich Jan 26, 2019
55c924e
Clean nasrl suggestion
andreyvelich Jan 26, 2019
ac2dd76
Add -u inside training-container
andreyvelich Jan 26, 2019
4263d1c
Fix namespace in worker template
andreyvelich Jan 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 49 additions & 18 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,59 @@ type server struct {
}

func (s *server) CreateStudy(ctx context.Context, in *api_pb.CreateStudyRequest) (*api_pb.CreateStudyReply, error) {
var studyID string
var err error
if in == nil || in.StudyConfig == nil {
return &api_pb.CreateStudyReply{}, errors.New("StudyConfig is missing.")
}
studyID, err := dbIf.CreateStudy(in.StudyConfig)
if err != nil {
return &api_pb.CreateStudyReply{}, err

if in.StudyConfig.JobType != "nas" {
//If it is a HP job
studyID, err = dbIf.CreateStudy(in.StudyConfig)
if err != nil {
return &api_pb.CreateStudyReply{}, err
}
s.SaveStudy(ctx, &api_pb.SaveStudyRequest{
StudyName: in.StudyConfig.Name,
Owner: in.StudyConfig.Owner,
Description: "StudyID: " + studyID,
})

} else {
//If it is a NAS job
studyID = "1"
gaocegege marked this conversation as resolved.
Show resolved Hide resolved
log.Printf("NAS job is created, id= %v", studyID)
}
s.SaveStudy(ctx, &api_pb.SaveStudyRequest{
StudyName: in.StudyConfig.Name,
Owner: in.StudyConfig.Owner,
Description: "StudyID: " + studyID,
})
return &api_pb.CreateStudyReply{StudyId: studyID}, nil
}

func (s *server) DeleteStudy(ctx context.Context, in *api_pb.DeleteStudyRequest) (*api_pb.DeleteStudyReply, error) {
if in == nil || in.StudyId == "" {
return &api_pb.DeleteStudyReply{}, errors.New("StudyId is missing.")
}
err := dbIf.DeleteStudy(in.StudyId)
if err != nil {
return &api_pb.DeleteStudyReply{}, err
if in.JobType != "nas" {
//If it is a HP job
err := dbIf.DeleteStudy(in.StudyId)
if err != nil {
return &api_pb.DeleteStudyReply{}, err
}
} else {
//If it is a NAS job
log.Printf("NAS job is deleted, id= %v", in.StudyId)
gaocegege marked this conversation as resolved.
Show resolved Hide resolved
}
return &api_pb.DeleteStudyReply{StudyId: in.StudyId}, nil
}

func (s *server) GetStudy(ctx context.Context, in *api_pb.GetStudyRequest) (*api_pb.GetStudyReply, error) {
sc, err := dbIf.GetStudyConfig(in.StudyId)
var sc *api_pb.StudyConfig
var err error
if in.JobType != "nas" {
//If it is a HP job
sc, err = dbIf.GetStudyConfig(in.StudyId)
} else {
//If it is a NAS job
log.Printf("Get NAS job, id = %v", in.StudyId)
}
return &api_pb.GetStudyReply{StudyConfig: sc}, err
}

Expand Down Expand Up @@ -91,8 +116,8 @@ func (s *server) GetTrials(ctx context.Context, in *api_pb.GetTrialsRequest) (*a
}

func (s *server) GetTrial(ctx context.Context, in *api_pb.GetTrialRequest) (*api_pb.GetTrialReply, error) {
t, err := dbIf.GetTrial(in.TrialId)
return &api_pb.GetTrialReply{Trial: t}, err
t, err := dbIf.GetTrial(in.TrialId)
return &api_pb.GetTrialReply{Trial: t}, err
}

func (s *server) GetSuggestions(ctx context.Context, in *api_pb.GetSuggestionsRequest) (*api_pb.GetSuggestionsReply, error) {
Expand Down Expand Up @@ -217,11 +242,17 @@ func (s *server) GetWorkerFullInfo(ctx context.Context, in *api_pb.GetWorkerFull
func (s *server) SetSuggestionParameters(ctx context.Context, in *api_pb.SetSuggestionParametersRequest) (*api_pb.SetSuggestionParametersReply, error) {
var err error
var id string
if in.ParamId == "" {
id, err = dbIf.SetSuggestionParam(in.SuggestionAlgorithm, in.StudyId, in.SuggestionParameters)
if in.JobType != "nas" {
//If it is a HP job
if in.ParamId == "" {
id, err = dbIf.SetSuggestionParam(in.SuggestionAlgorithm, in.StudyId, in.SuggestionParameters)
} else {
id = in.ParamId
err = dbIf.UpdateSuggestionParam(in.ParamId, in.SuggestionParameters)
}
} else {
id = in.ParamId
err = dbIf.UpdateSuggestionParam(in.ParamId, in.SuggestionParameters)
//If it is a NAS job
log.Printf("Set suggestion Params for NAS job id= %v", in.StudyId)
}
return &api_pb.SetSuggestionParametersReply{ParamId: id}, err
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/suggestion/nasrl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3

ADD . /usr/src/app/github.com/kubeflow/katib
WORKDIR /usr/src/app/github.com/kubeflow/katib/cmd/suggestion/nasrl
RUN pip install --no-cache-dir -r requirements.txt
ENV PYTHONPATH /usr/src/app/github.com/kubeflow/katib:/usr/src/app/github.com/kubeflow/katib/pkg/api/python

ENTRYPOINT ["python", "-u", "main.py"]
andreyvelich marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
29 changes: 29 additions & 0 deletions cmd/suggestion/nasrl/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import grpc
from concurrent import futures

import time

from pkg.api.python import api_pb2_grpc
from pkg.suggestion.nasrl_service import NasrlService
from pkg.suggestion.types import DEFAULT_PORT
from logging import getLogger, StreamHandler, INFO, DEBUG


_ONE_DAY_IN_SECONDS = 60 * 60 * 24


def serve():
print("NAS RL Suggestion Service")
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
api_pb2_grpc.add_SuggestionServicer_to_server(NasrlService(), server)
server.add_insecure_port(DEFAULT_PORT)
print("Listening...")
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)

if __name__ == "__main__":
serve()
andreyvelich marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions cmd/suggestion/nasrl/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
grpcio
duecredit
cloudpickle==0.5.6
numpy>=1.13.3
scikit-learn>=0.19.0
scipy>=0.19.1
forestci
protobuf
googleapis-common-protos
142 changes: 142 additions & 0 deletions examples/nasjob-example-RL.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
apiVersion: "kubeflow.org/v1alpha1"
kind: StudyJob
metadata:
namespace: kubeflow
labels:
controller-tools.k8s.io: "1.0"
name: nas-rl-example
spec:
studyName: nas-rl-example
owner: crd
optimizationtype: maximize
objectivevaluename: Validation-accuracy
optimizationgoal: 0.99
requestcount: 4
metricsnames:
- accuracy
jobType: nas
graphConfig:
numLayers: 8
inputSize:
- 32
- 32
- 3
outputSize:
- 10
operations:
- operationType: convolution
parameterconfigs:
- name: filter_size
parametertype: categorical
feasible:
list:
- "3"
- "5"
- "7"
- name: num_filter
parametertype: categorical
feasible:
list:
- "32"
- "48"
- "64"
- "96"
- "128"
- name: stride
parametertype: categorical
feasible:
list:
- "1"
- "2"
- name: activation
parametertype: categorical
feasible:
list:
- relu
- sigmoid
- tanh
- identity
- operationType: reduction
parameterconfigs:
- name: reduction_type
parametertype: categorical
feasible:
list:
- maxpooling
- avgpooling
- name: pool_size
parametertype: int
feasible:
min: "1"
max: "3"
- name: stride
parametertype: categorical
feasible:
list:
- "1"
- "2"
- operationType: dense
parameterconfigs:
- name: num_units
parametertype: categorical
feasible:
list:
- "128"
- "256"
- "512"
- "1024"
- name: activation
parametertype: categorical
feasible:
list:
- relu
- sigmoid
- tanh
- identity
- name: dropout_rate
parametertype: range
feasible:
min: "0.1"
max: "0.6"
step: "0.1"
workerSpec:
goTemplate:
rawTemplate: |-
apiVersion: batch/v1
kind: Job
metadata:
name: {{.WorkerID}}
namespace: kubeflow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/kubeflow/{{.NameSpace}}

spec:
template:
spec:
imagePullSecrets:
- name: gitlabregcred
containers:
- name: {{.WorkerID}}
image: katib/mxnet-mnist-example
command:
- "python"
- "/mxnet/example/image-classification/train_mnist.py"
- "--batch-size=32"
{{- with .HyperParameters}}
{{- range .}}
- "{{.Name}}={{.Value}}"
{{- end}}
{{- end}}
restartPolicy: Never
suggestionSpec:
suggestionAlgorithm: "nasrl"
suggestionParameters:
- name: "num_control_cells"
value: "32"
- name: "embedding_dim"
value: "20"
- name: "accuracy_beta"
value: "0.8"
- name: "clip_rewards"
value: "0"
- name: "embedding_dim"
value: "20"
- name: "discount_factor"
value: "0.95"
andreyvelich marked this conversation as resolved.
Show resolved Hide resolved
Loading