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
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 |
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
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() |
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
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 |
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
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. |
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
import ray | |
from ray import serve | |
ray.init(address='auto', namespace="serve-example", ignore_reinit_error=True) | |
serve.start(detached=True) | |
SentimentDeployment.deploy() |
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
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) |
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
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() |
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
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)) |
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
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/") |
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
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 |