Skip to content

Commit

Permalink
Refactor NAS RL Suggestion (kubeflow#1134)
Browse files Browse the repository at this point in the history
* Refactor NAS RL

* Remove comments

* Change format
  • Loading branch information
andreyvelich authored and sperlingxx committed Apr 20, 2020
1 parent 7776ae8 commit 1bcd5a7
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 685 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

if num_gpus > 1:
test_model = multi_gpu_model(test_model, gpus=num_gpus)

test_model.summary()
test_model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.Adam(lr=1e-3, decay=1e-4),
Expand All @@ -61,7 +61,8 @@
width_shift_range=0.1,
height_shift_range=0.1,
horizontal_flip=True)


# TODO: Add batch size to args
aug_data_flow = augmentation.flow(x_train, y_train, batch_size=128)

print(">>> Data Loaded. Training starts.")
Expand Down
137 changes: 55 additions & 82 deletions examples/v1alpha3/nasjob-example-RL-cpu.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This CPU example aims to show all the possible operations
# is not very likely to get good result due to the extensive search space

# In practice, setting up a limited search space with more common operations is more likely to get better performance.
# In practice, setting up a limited search space with more common operations is more likely to get better performance.
# For example, Efficient Neural Architecture Search via Parameter Sharing (https://arxiv.org/abs/1802.03268)
# uses only 6 operations, 3x3/5x5 convolution, 3x3/5x5 separable_convolution and 3x3 max_pooling/avg_pooling.

Expand All @@ -23,58 +23,31 @@ spec:
objectiveMetricName: Validation-Accuracy
algorithm:
algorithmName: nasrl
algorithmSettings:
- name: "lstm_num_cells"
value: "64"
- name: "lstm_num_layers"
value: "1"
- name: "lstm_keep_prob"
value: "1.0"
- name: "optimizer"
value: "adam"
- name: "init_learning_rate"
value: "1e-3"
- name: "lr_decay_start"
value: "0"
- name: "lr_decay_every"
value: "1000"
- name: "lr_decay_rate"
value: "0.9"
- name: "skip-target"
value: "0.4"
- name: "skip-weight"
value: "0.8"
- name: "l2_reg"
value: "0"
- name: "entropy_weight"
value: "1e-4"
- name: "baseline_decay"
value: "0.9999"
trialTemplate:
goTemplate:
rawTemplate: |-
apiVersion: batch/v1
kind: Job
metadata:
name: {{.Trial}}
namespace: {{.NameSpace}}
spec:
template:
spec:
containers:
- name: {{.Trial}}
image: docker.io/kubeflowkatib/nasrl-cifar10-cpu
command:
- "python3.5"
- "-u"
- "RunTrial.py"
{{- with .HyperParameters}}
{{- range .}}
- "--{{.Name}}=\"{{.Value}}\""
{{- end}}
{{- end}}
- "--num_epochs=1"
restartPolicy: Never
rawTemplate: |-
apiVersion: batch/v1
kind: Job
metadata:
name: {{.Trial}}
namespace: {{.NameSpace}}
spec:
template:
spec:
containers:
- name: {{.Trial}}
image: docker.io/kubeflowkatib/nasrl-cifar10-cpu
command:
- "python3.5"
- "-u"
- "RunTrial.py"
{{- with .HyperParameters}}
{{- range .}}
- "--{{.Name}}=\"{{.Value}}\""
{{- end}}
{{- end}}
- "--num_epochs=1"
restartPolicy: Never
nasConfig:
graphConfig:
numLayers: 1
Expand All @@ -91,83 +64,83 @@ spec:
parameterType: categorical
feasibleSpace:
list:
- "3"
- "5"
- "7"
- "3"
- "5"
- "7"
- name: num_filter
parameterType: categorical
feasibleSpace:
list:
- "32"
- "48"
- "64"
- "96"
- "128"
- "32"
- "48"
- "64"
- "96"
- "128"
- name: stride
parameterType: categorical
feasibleSpace:
list:
- "1"
- "2"
- "1"
- "2"
- operationType: separable_convolution
parameters:
- name: filter_size
parameterType: categorical
feasibleSpace:
list:
- "3"
- "5"
- "7"
- "3"
- "5"
- "7"
- name: num_filter
parameterType: categorical
feasibleSpace:
list:
- "32"
- "48"
- "64"
- "96"
- "128"
- "32"
- "48"
- "64"
- "96"
- "128"
- name: stride
parameterType: categorical
feasibleSpace:
list:
- "1"
- "2"
- "1"
- "2"
- name: depth_multiplier
parameterType: categorical
feasibleSpace:
list:
- "1"
- "2"
- "1"
- "2"
- operationType: depthwise_convolution
parameters:
- name: filter_size
parameterType: categorical
feasibleSpace:
list:
- "3"
- "5"
- "7"
- "3"
- "5"
- "7"
- name: stride
parameterType: categorical
feasibleSpace:
list:
- "1"
- "2"
- "1"
- "2"
- name: depth_multiplier
parameterType: categorical
feasibleSpace:
list:
- "1"
- "2"
- "1"
- "2"
- operationType: reduction
parameters:
- name: reduction_type
parameterType: categorical
feasibleSpace:
list:
- max_pooling
- avg_pooling
- max_pooling
- avg_pooling
- name: pool_size
parameterType: int
feasibleSpace:
Expand Down
Loading

0 comments on commit 1bcd5a7

Please sign in to comment.