Skip to content

Instantly share code, notes, and snippets.

View edoakes's full-sized avatar

Edward Oakes edoakes

  • Anyscale
  • Minneapolis, MN
View GitHub Profile
@edoakes
edoakes / code_sample.py
Last active January 27, 2021 16:14
Ray for training + Ray Serve for inference
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("train_s3_urls")
parser.add_argument("inference_s3_urls")
parser.add_argument("output_path")
import ray
from ray import serve
ray.init()
@ray.remote
class Controller:
def start_me_an_actor(self, cls):
# Start an actor on behalf of the caller.
ray.remote(cls).remote()
Controller.options(name="controller", lifetime="detached").remote()
@edoakes
edoakes / ray-cluster.yaml
Last active August 11, 2021 13:46
10-node AWS Ray cluster configuration
cluster_name: monte_carlo_pi
# The number of worker nodes to launch in addition to the head node.
min_workers: 9
max_workers: 9
provider:
type: aws
region: us-west-2
availability_zone: us-west-2a
import ray
from ray import serve
ray.init(address='auto', namespace="serve-example", ignore_reinit_error=True) # Connect to the local running Ray cluster.
serve.start(detached=True) # Start the Ray Serve processes within the Ray cluster.
import ray
from ray import serve
ray.init(address='auto', namespace="serve-example", ignore_reinit_error=True)
serve.start(detached=True)
SentimentDeployment.deploy()
import joblib
import s3fs
import sklearn
@serve.deployment(route_prefix="/sentiment", name="sentiment-deployment")
class SentimentDeployment:
def __init__(self):
fs = s3fs.S3FileSystem(anon=True)
with fs.open('ray-serve-blog/unigram_vectorizer.joblib', 'rb') as f:
self.vectorizer = joblib.load(f)
import ray
from ray import serve
# Connect to the running Ray Serve instance.
ray.init(address='auto', namespace="serve-example", ignore_reinit_error=True)
serve.start(detached=True)
# Deploy the model.
SentimentDeployment.deploy()
from transformers import pipeline
@serve.deployment(route_prefix="/sentiment", name="sentiment")
class SentimentDeployment:
def __init__(self):
self.classifier = pipeline("sentiment-analysis")
async def __call__(self, request):
data = await request.body()
[result] = self.classifier(str(data))
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.graph_objs as obj
import uvicorn as uvicorn
from fastapi import FastAPI
from starlette.middleware.wsgi import WSGIMiddleware
app = dash.Dash(__name__, requests_pathname_prefix="/dash/")
@edoakes
edoakes / serve_plotly.py
Created September 21, 2021 20:22
Ray Serve plotly wrapper (working but hacky)
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.graph_objs as obj
import uvicorn as uvicorn
from fastapi import FastAPI
from starlette.middleware.wsgi import WSGIMiddleware
import ray