-
Notifications
You must be signed in to change notification settings - Fork 76
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
[WIP]Autoscaling Controller #385
Merged
Merged
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
5b95916
publish files
typhoonzero 04ab2f5
publish files
typhoonzero 63f1c95
fix travis error
typhoonzero f227e48
Merge branch 'develop' of https://github.com/PaddlePaddle/cloud into …
typhoonzero 34bbe7a
Merge branch 'develop' of https://github.com/PaddlePaddle/cloud into …
typhoonzero bb23b77
Merge branch 'develop' of https://github.com/PaddlePaddle/cloud into …
typhoonzero 8f602e7
WIP
typhoonzero 453986e
WIP
helinwang f05985d
change folder structure: move controller/* to controller/k8s
helinwang 1e99ba1
move operator/* to controller/
helinwang a72a6bb
add cluster abstraction
helinwang ed564fe
improve cluster interface
helinwang e10df61
rename k8s package name
helinwang 5e5ceb9
rename Controller to Autoscaler
helinwang 8efa7d8
refine naming and structure
typhoonzero 0bd78c4
have crash bug
typhoonzero 3199e78
fix glog flag duplicate
typhoonzero 0b4deba
adjust comments
helinwang 9af94cf
event fetch ok
typhoonzero 50cfe7f
update
typhoonzero c4c7208
autoscale function
typhoonzero d65a60a
update
typhoonzero 9bda7fd
not tested scaling
typhoonzero 0253fc0
improvements
helinwang 2461395
use Go idiomatic constants
helinwang 4860c27
Merge branch 'develop' of https://github.com/PaddlePaddle/cloud into …
typhoonzero 936053f
update
typhoonzero e75e8b7
Merge branch 'controller' of https://github.com/PaddlePaddle/cloud in…
typhoonzero 7575bdd
polish and add TODO
helinwang 241fad0
use channel for autoscaler event handling to avoid using mutex
helinwang 22c161e
remove TODO comment that is done.
helinwang 1c8fa5d
rename autoscaler event handler
helinwang ba1b17f
make all tests pass.
helinwang 587a266
fix build
helinwang 75407df
try fix travis build
helinwang 1f76064
try fix travis build
helinwang 28dd711
adding testcase, still need test
typhoonzero 4640b59
fix test case
typhoonzero 526ea80
scale up: consider both GPU and CPU constraint. And add comments
helinwang 27f4866
Simply Cluster interface, update scaling algorithm.
helinwang 11ec9dd
Restructure controller and autoscalar packages
helinwang d78b11e
fix typo in comment
helinwang 9da79b2
Add unit test for scaleDryRun and scaleAllDryRun
helinwang 69675b4
code refine
typhoonzero 1cbca13
add mnist example
typhoonzero 76265b3
Add missing go files, fix unit test
helinwang 9b5da6f
move controller
typhoonzero 6feb1ba
Fix SyncResource returning decreasing free resource over time.
helinwang 3143d00
Improve autoscaling documentation, change k8s config alway pull image.
helinwang d67d37a
merge1
typhoonzero 1523923
Fix crash by make map
helinwang 65a24a4
merge2
typhoonzero f59c750
Merge branch 'controller' of https://github.com/PaddlePaddle/cloud in…
typhoonzero bbac308
refine cluster.go and update
typhoonzero 6a6811f
add cfs and utils
typhoonzero 22bdcd7
fix glide nested vendor
typhoonzero 6053c2d
fix ci
typhoonzero 45a3dcb
add scale down
typhoonzero d67ade4
add mnist ft demo
typhoonzero d0902d9
Rename method, avoid unnecessarily passing pointer, refactor unit test
helinwang e9f6339
Add InitContainers into cluster resource utilization calculation, pol…
helinwang 01b3411
Get the lastest TrainerJob before updating it, with retry.
helinwang 6b55869
Support TrainingJob update.
helinwang ee6a6fc
Add TODO for fixing incorrect training job pod count.
helinwang b11fab3
fix scale before running
typhoonzero b855f38
Rename JobRunning to JobPods
helinwang c7a6fa2
Change imagePullPolicy to Always
helinwang 919d323
Update tutorial
helinwang b20826f
Update tutorial
helinwang e225843
Update tutorial
helinwang 070af1e
Update autoscale.md
helinwang a2d1adc
Temporately change trainer docker image name
helinwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Run Autoscaling job on your local machine | ||
|
||
This documentation shows an example to run two jobs on a local kubernetes cluster and see the job scaling status. | ||
|
||
## Prerequisites | ||
|
||
- [install minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) | ||
- [install kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) | ||
|
||
## Run local Autoscaling job | ||
|
||
1. Start a local minikube cluster. | ||
|
||
```bash | ||
minikube start --kubernetes-version v1.6.4 | ||
``` | ||
|
||
1. Run the following commands to create sample training workspace and | ||
data. | ||
|
||
```bash | ||
mkdir /path/to/workspace | ||
cp $REPO_PATH/doc/autoscale_example/*.py /path/to/workspace | ||
mkdir -p /path/to/workspace/data/ | ||
cp -r $REPO_PATH/doc/autoscale_example/uci_housing/ /path/to/workspace/data/ | ||
``` | ||
|
||
1. Mount the workspace folder into Minikube: | ||
|
||
```bash | ||
minikube mount /path/to/workspace:/workspace | ||
``` | ||
|
||
The `minikube mount` command will block, so start a new terminal to | ||
continue the tutorial. | ||
|
||
1. Start controller and a example job: | ||
|
||
```bash | ||
cd $REPO_PATH/k8s/controller | ||
kubectl create -f controller.yaml | ||
kubectl create -f trainingjob_resource.yaml | ||
kubectl create -f autoscale_job/ | ||
kubectl get pods | ||
``` | ||
|
||
1. Start another job simulating cluster load, then you can observe the | ||
scale process using `kubectl get pods`: | ||
|
||
```bash | ||
kubectl create -f autoscale_load/ | ||
kubectl get pods | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sys | ||
import os | ||
import errno | ||
import recordio | ||
import paddle.v2.dataset as ds | ||
|
||
def convert(output_path, name): | ||
mod = __import__("paddle.v2.dataset." + name, fromlist=['']) | ||
|
||
path = os.path.join(output_path, name) | ||
|
||
mod.convert(path) | ||
|
||
if __name__ == '__main__': | ||
a = ['uci_housing'] | ||
for m in a: | ||
convert("./data", m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import paddle.v2 as paddle | ||
import os | ||
import gzip | ||
from paddle.v2.reader.creator import cloud_reader | ||
import paddle.v2.dataset.uci_housing as uci_housing | ||
|
||
etcd_ip = os.getenv("ETCD_IP") | ||
etcd_endpoint = "http://" + etcd_ip + ":" + "2379" | ||
trainer_id = int(os.getenv("PADDLE_INIT_TRAINER_ID")) | ||
|
||
def main(): | ||
# init | ||
paddle.init() | ||
|
||
# network config | ||
x = paddle.layer.data(name='x', type=paddle.data_type.dense_vector(13)) | ||
y_predict = paddle.layer.fc(input=x, | ||
param_attr=paddle.attr.Param(name='w', learning_rate=1e-3), | ||
size=1, | ||
act=paddle.activation.Linear(), | ||
bias_attr=paddle.attr.Param(name='b', learning_rate=1e-3)) | ||
y = paddle.layer.data(name='y', type=paddle.data_type.dense_vector(1)) | ||
cost = paddle.layer.square_error_cost(input=y_predict, label=y) | ||
|
||
# create parameters | ||
parameters = paddle.parameters.create(cost) | ||
|
||
# create optimizer | ||
optimizer = paddle.optimizer.Momentum(momentum=0, learning_rate=2e-4) | ||
|
||
trainer = paddle.trainer.SGD( | ||
cost=cost, | ||
parameters=parameters, | ||
update_equation=optimizer, | ||
is_local=False, | ||
pserver_spec=etcd_endpoint, | ||
use_etcd=True) | ||
|
||
feeding = {'x': 0, 'y': 1} | ||
|
||
# event_handler to print training and testing info | ||
def event_handler(event): | ||
if isinstance(event, paddle.event.EndIteration): | ||
if event.batch_id % 100 == 0: | ||
print "Pass %d, Batch %d, Cost %f" % ( | ||
event.pass_id, event.batch_id, event.cost) | ||
|
||
if isinstance(event, paddle.event.EndPass): | ||
result = trainer.test( | ||
reader=paddle.batch(uci_housing.test(), batch_size=2), | ||
feeding=feeding) | ||
print "Test %d, Cost %f" % (event.pass_id, result.cost) | ||
if trainer_id == "0": | ||
with gzip.open("fit-a-line_pass_%05d.tar.gz" % event.pass_id, | ||
"w") as f: | ||
parameters.to_tar(f) | ||
# training | ||
trainer.train( | ||
reader=paddle.batch( | ||
paddle.reader.shuffle(cloud_reader( | ||
["/workspace/data/uci_housing/uci_housing_train-*"], | ||
etcd_endpoint), buf_size=500), | ||
batch_size=2), | ||
feeding=feeding, | ||
event_handler=event_handler, | ||
num_passes=30) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from PIL import Image | ||
import numpy as np | ||
import paddle.v2 as paddle | ||
import paddle.v2.dataset.common as common | ||
import paddle.v2.dataset.mnist as mnist | ||
from paddle.v2.reader.creator import cloud_reader | ||
import os | ||
import sys | ||
import glob | ||
import pickle | ||
|
||
|
||
# NOTE: must change this to your own username on paddlecloud. | ||
TRAIN_FILES_PATH = "/workspace/data/mnist/minist_train-*" | ||
TEST_FILES_PATH = "/workspace/data/mnist/minist_test-*" | ||
|
||
etcd_ip = os.getenv("ETCD_IP") | ||
etcd_endpoint = "http://" + etcd_ip + ":" + "2379" | ||
trainer_id = int(os.getenv("PADDLE_INIT_TRAINER_ID", "-1")) | ||
|
||
|
||
def softmax_regression(img): | ||
predict = paddle.layer.fc( | ||
input=img, size=10, act=paddle.activation.Softmax()) | ||
return predict | ||
|
||
|
||
def multilayer_perceptron(img): | ||
# The first fully-connected layer | ||
hidden1 = paddle.layer.fc(input=img, size=128, act=paddle.activation.Relu()) | ||
# The second fully-connected layer and the according activation function | ||
hidden2 = paddle.layer.fc( | ||
input=hidden1, size=64, act=paddle.activation.Relu()) | ||
# The thrid fully-connected layer, note that the hidden size should be 10, | ||
# which is the number of unique digits | ||
predict = paddle.layer.fc( | ||
input=hidden2, size=10, act=paddle.activation.Softmax()) | ||
return predict | ||
|
||
|
||
def convolutional_neural_network(img): | ||
# first conv layer | ||
conv_pool_1 = paddle.networks.simple_img_conv_pool( | ||
input=img, | ||
filter_size=5, | ||
num_filters=20, | ||
num_channel=1, | ||
pool_size=2, | ||
pool_stride=2, | ||
act=paddle.activation.Relu()) | ||
# second conv layer | ||
conv_pool_2 = paddle.networks.simple_img_conv_pool( | ||
input=conv_pool_1, | ||
filter_size=5, | ||
num_filters=50, | ||
num_channel=20, | ||
pool_size=2, | ||
pool_stride=2, | ||
act=paddle.activation.Relu()) | ||
# fully-connected layer | ||
predict = paddle.layer.fc( | ||
input=conv_pool_2, size=10, act=paddle.activation.Softmax()) | ||
return predict | ||
|
||
|
||
def main(): | ||
paddle.init() | ||
|
||
# define network topology | ||
images = paddle.layer.data( | ||
name='pixel', type=paddle.data_type.dense_vector(784)) | ||
label = paddle.layer.data( | ||
name='label', type=paddle.data_type.integer_value(10)) | ||
|
||
# Here we can build the prediction network in different ways. Please | ||
# choose one by uncomment corresponding line. | ||
# predict = softmax_regression(images) | ||
# predict = multilayer_perceptron(images) | ||
predict = convolutional_neural_network(images) | ||
|
||
cost = paddle.layer.classification_cost(input=predict, label=label) | ||
|
||
parameters = paddle.parameters.create(cost) | ||
|
||
optimizer = paddle.optimizer.Momentum( | ||
learning_rate=0.1 / 128.0, | ||
momentum=0.9, | ||
regularization=paddle.optimizer.L2Regularization(rate=0.0005 * 128)) | ||
|
||
trainer = paddle.trainer.SGD( | ||
cost=cost, | ||
parameters=parameters, | ||
update_equation=optimizer, | ||
is_local=False, | ||
pserver_spec=etcd_endpoint, | ||
use_etcd=True) | ||
|
||
def event_handler(event): | ||
if isinstance(event, paddle.event.EndIteration): | ||
if event.batch_id % 100 == 0: | ||
print "Pass %d, Batch %d, Cost %f, %s" % ( | ||
event.pass_id, event.batch_id, event.cost, event.metrics) | ||
if isinstance(event, paddle.event.EndPass): | ||
result = trainer.test( | ||
reader=paddle.batch( | ||
mnist.test(), | ||
batch_size=2)) | ||
print "Test with Pass %d, Cost %f, %s\n" % ( | ||
event.pass_id, result.cost, result.metrics) | ||
|
||
trainer.train( | ||
reader=paddle.batch( | ||
cloud_reader([TRAIN_FILES_PATH], etcd_endpoint), | ||
batch_size=128), | ||
event_handler=event_handler, | ||
num_passes=30) | ||
|
||
if __name__ == '__main__': | ||
usage = "python train.py [prepare|train]" | ||
if len(sys.argv) != 2: | ||
print usage | ||
exit(1) | ||
|
||
if trainer_id == -1 or etcd_ip == "": | ||
print "no cloud environ found, must run on cloud" | ||
exit(1) | ||
|
||
if sys.argv[1] == "train": | ||
main() | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
# FIXME: should run this script before build, when using api >= 1.7 | ||
# api == 1.6 is not compatible with this deep copy code generations. | ||
|
||
go get -u k8s.io/gengo | ||
go build -o /tmp/deepcopy-gen k8s.io/gengo/examples/deepcopy-gen | ||
/tmp/deepcopy-gen -i github.com/PaddlePaddle/cloud/go/api -O zz_generated.deepcopy 2> /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* Copyright (c) 2016 PaddlePaddle Authors All Rights Reserve. | ||
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. */ | ||
|
||
package api | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
clientgoapi "k8s.io/client-go/pkg/api" | ||
"k8s.io/client-go/pkg/api/v1" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
// ConfigureClient will setup required field that the k8s rest client needs. | ||
func ConfigureClient(config *rest.Config) { | ||
groupversion := schema.GroupVersion{ | ||
Group: "paddlepaddle.org", | ||
Version: "v1", | ||
} | ||
|
||
config.GroupVersion = &groupversion | ||
config.APIPath = "/apis" | ||
config.ContentType = runtime.ContentTypeJSON | ||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: clientgoapi.Codecs} | ||
|
||
schemeBuilder := runtime.NewSchemeBuilder( | ||
func(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes( | ||
groupversion, | ||
&TrainingJob{}, | ||
&TrainingJobList{}, | ||
&v1.ListOptions{}, | ||
&v1.DeleteOptions{}, | ||
) | ||
return nil | ||
}) | ||
schemeBuilder.AddToScheme(clientgoapi.Scheme) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pods may be scaled.