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 / 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
@pipeline.step
def preprocess(_input: str) -> PreprocessOutput:
pass
@pipeline.step(num_replicas=10, num_gpus=1)
class Model1:
def __call__(self, _input: PreprocessOutput) -> Model1Output:
pass
@pipeline.step(num_replicas=5, num_cpus=1)
@edoakes
edoakes / message_consumer.py
Created June 9, 2023 21:43
Example of how to use a message passing architecture with Ray Serve.
import asyncio
from ray import serve
@serve.deployment
class MessageConsumer:
def __init__(self, topic: str):
asyncio.get_running_loop().create_task(
self.poll_for_messages(topic)
)