HUB
Sign inSign up

lukehoban/skylearn-svc

By lukehoban

•Updated over 9 years ago

Main API service for Skylearn.

Image
0

1.4K

lukehoban/skylearn-svc repository overview

⁠SkyLearn

Skylearn⁠ is an ML as a Service platform for training and infrerence on deep learning workloads.

Skylearn lets you run deep learning jobs on either CPU or GPU instances in the cloud, sharing data sources as persistent inputs and outputs between jobs.

Skylearn jobs run inside an environment with access to current versions of Python 3, Tensorflow, Keras, OpenAI Universe, OpenCV, and more.

⁠Examples

⁠Hello World

You can run any command within Skylearn. We can start with a simple echo.

> skylearn run "echo hello world"
Task: 384313b1-6745-4836-ac48-b65bc8f360e0
Output Data: e107fc9e-9098-42c2-8374-c32197d19990
For logs, use: skylearn logs 384313b1-6745-4836-ac48-b65bc8f360e0

> skylearn logs 384313b1-6745-4836-ac48-b65bc8f360e0
1494307350223: hello world

We can check the version of Python, and verify that it is the latest Python 3.

> skylearn run "python -V"
Task: a4c79ff0-f00f-4a14-9eab-9f6fa0b42d19
Output Data: cb631b0c-5211-4fa9-bd0a-bf4032124b52
For logs, use: skylearn logs a4c79ff0-f00f-4a14-9eab-9f6fa0b42d19

> skylearn logs a4c79ff0-f00f-4a14-9eab-9f6fa0b42d19
1494307684352: Python 3.5.3
⁠Keras Examples

Get the Keras examples.

> git clone --branch 1.2.2 https://github.com/fchollet/keras
> cd keras/examples

Run one of the examples. For most, running on GPU will be significantly faster.

> skylearn run --gpu "python addition_rnn.py"
...
1494311055875: --------------------------------------------------
1494311055875: Iteration 199
1494311055875: Train on 45000 samples, validate on 5000 samples
1494311055875: Epoch 1/1
1494311064502: Using TensorFlow backend.
1494311064503: ---
1494311064503: Q 444+724
1494311064503: T 1168
1494311064503: ☑ 1168
45000/45000 [==============================] - 8s - loss: 1.3783e-04 - acc: 1.0000 - val_loss: 8.8817e-04 - val_acc: 0.9996
1494311064503: Q 48+926
1494311064503: T 974
1494311064503: ☑ 974
1494311064503: ---
1494311064503: Q 628+308
1494311064503: T 936
1494311064503: ☑ 936
1494311064503: ---
1494311064503: Q 240+50
1494311064503: T 290
1494311064503: ☑ 290
1494311064503: ---
1494311064503: Q 159+312
1494311064503: T 471
1494311064503: ☑ 471
1494311064503: ---
1494311064503: Q 52+93
1494311064503: T 145
1494311064503: ☑ 145
1494311064503: ---
1494311064503: Q 373+85
1494311064503: T 458
1494311064503: ☑ 458
1494311064503: ---
1494311064503: Q 111+589
1494311064503: T 700
1494311064503: ☑ 700
1494311064503: ---
1494311064503: Q 736+731
1494311064503: T 1467
1494311064503: ☑ 1467
1494311064503: ---
1494311064503: Q 111+26
1494311064503: T 137
1494311064503: ☑ 137
1494311064503: ---

And another:

> skylearn run --gpu "python imdb_lstm.py"
...

### Style Transfer

Get the style transfer code.

```bash
> git clone https://github.com/lukehoban/fast-style-transfer
> cd fast-style-transfer

Start by training a model on the la_muse⁠ style.

>  skylearn run --gpu --input 7756d556-b281-4069-ae83-7edeafcd80dc "python style.py --style examples/style/la_muse.jpg --base-model-path /input/pre-trained-tf/la_muse.ckpt --epoch 1 --total-iterations 10 --checkpoint-dir /output"
Task: db36f52b-e7ab-43b3-8585-dae9d3e7247c
Output Data: ed4fcb90-90b3-4036-b707-f283633d5fa4

For logs, use: skylearn logs db36f52b-e7ab-43b3-8585-dae9d3e7247c

On a GPU, this will take less than a minute. On a CPU, it may take over 8 hours. Take a look at the logs.

> skylearn logs db36f52b-e7ab-43b3-8585-dae9d3e7247c
1494276827160: I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
1494276827168: I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
1494276827171: I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
1494276829377: I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
1494276829379: I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
1494277034785: Train set has been trimmed slightly..
1494277034785: (1, 512, 512, 3)
1494277034785: Precomputing style features
1494277036042: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:937] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
1494277036043: major: 3 minor: 7 memoryClockRate (GHz) 0.8235
1494277036043: name: Tesla K80
1494277036043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
1494277036043: pciBusID 0000:00:1e.0
1494277036043: Total memory: 11.17GiB
1494277036043: Free memory: 11.11GiB
1494277036043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0
1494277036043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y
1494277036043: I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0)
1494277048634: I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0)
1494277048646: Precomputing content features
1494277049945: Building VGG net
1494277054226: UID: 68
1494277054226: number of examples: 82780
1494277054226: Current iteration : 0
1494277058337: Current iteration : 1
1494277059533: Current iteration : 2
1494277060714: Current iteration : 3
1494277061897: Current iteration : 4
1494277063078: Current iteration : 5
1494277064271: Current iteration : 6
1494277065467: Current iteration : 7
1494277066640: Current iteration : 8
1494277067814: Current iteration : 9
1494277072162: Epoch 0, Iteration: 10, Loss: 1.07063e+07
1494277072162: style: 1.96267e+06, content:8.46504e+06, tv: 278605.0
1494277072222: Training complete. For evaluation:
1494277072222:     `python evaluate.py --checkpoint /output ...`

Now that we have a trained model, use the output from training as the input for evaluation of the model on any images in the ./images folder. Add additional images there to produce results.

> skylearn run --input ed4fcb90-90b3-4036-b707-f283633d5fa4 "python evaluate.py --allow-different-dimensions  --checkpoint /input/fns.ckpt --in-path ./images/ --out-path /output/"
Task: f3038148-86b2-444a-b183-68a3a6f78048
Output Data: 6801c28e-be3e-49f2-b8a8-6a8012b52b31

For logs, use: skylearn logs f3038148-86b2-444a-b183-68a3a6f78048

Check out the results at https://skylearn.io/files/6801c28e-be3e-49f2-b8a8-6a8012b52b31/taipei101.jpg⁠.

StyleInputOutput
style imageinput imageoutput image

⁠Building and Deploying

Developers who want to deploy their the Skylearn platform on their own infrastrcture can use the CloudFormation template. To deploy updated builds of the Skylearn service, modify formation.json to point to a different Docker image (in a repository you can push updates to). The following settings in CloudFormation may need to be modified:

  • SkylearnServiceTask.Properties.ContainerDefintions[0].Image: This should point to a docker repository you can push updated builds for the Skylearn service to. See also ./scripts/build-and-push-service.sh.
  • GPUInstanceLaunchConfiguration.Properties.ImageId: Currently hard coded to the Amazon Deep Learning AMI in us-west-2.
  • GPUInstances.Properties.DesiredCapacity: Sets the default number of P2 instances to 0 to avoid cost. Increase manually via the console.
⁠Step 1: Create stack
> aws cloudformation create-stack --stack-name skylearn --template-body "$(cat formation.json)" --capabilities "CAPABILITY_IAM"
{
    "StackId": "arn:aws:cloudformation:us-west-2:490047557317:stack/skylearn/1a5f0ac0-2c33-11e7-80b3-50d5ca11b8d2"
}
⁠Step 2: Set API environment variable
> export SKYLEARN_API=`aws cloudformation describe-stacks --stack-name skylearn --query 'Stacks[0].Outputs[?OutputKey==`LoadBalancer`].OutputValue' --output text`
> echo $SKYLEARN_API
Skylearn-ALB-451780314.us-west-2.elb.amazonaws.com
⁠Step 3: Run the Skylearn CLI
> go install .
> skylearn run echo Hello World!
9830c1cd-04a7-404f-a49d-69969a4bb645
> skylearn logs 9830c1cd-04a7-404f-a49d-69969a4bb645
1493704997915: Hello World!

⁠TODO

  • Dockerfile for ML sandbox

  • First ML example working

  • Extract API from CLI as local HTTP service

  • Move local HTTP service to ECS service

  • Write sources into EFS and mount EFS volume into job container

  • Use skylearn domain

  • Add P2 instances

  • Create Lambda to watch ECS CloudWatch Events for task start/stop

  • Create Web UI

  • Move web to Gorilla

  • Make web prettier :-)

  • Capture output

  • Allow input data

  • Add some public data sets

  • Image transfer example working

  • Track tasks and output in Dynamo table for easy querying

  • Handle paged logs in logs API

  • Support deleting (and do some cleanup)

  • skylearn jobs CLI command

  • skylearn data CLI command (ls on dirs, download on files so you can pipe it)

  • Indicate when job is pending/started/finished

  • Account creation

  • Limit API access based on accounts

  • Limit web access based on accounts

  • Limit data access based on accounts

  • GitHub badge to launch into Skylearn from a GitHub repo/folder

  • Add more data sets

  • Don't upload current folder if it matches an existing hash

  • Provide download link for CLI from website

  • Alpha launch :-)

  • Autoscale CPU and GPU container instances on load

  • Deploy ECS task change handler with CloudFormation

  • Stripe for payments

  • HTTP APIs based on /input and /output conventions??

Tag summary

Content type

Image

Digest

Size

302.4 MB

Last updated

over 9 years ago

docker pull lukehoban/skylearn-svc