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 / 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)
)
@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 / 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
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/")
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 / 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
import asyncio
from asyncio.futures import Future
from collections import defaultdict
from typing import Dict, Any, List, Optional, Set, Tuple
import ray
import ray.cloudpickle as pickle
from ray.actor import ActorHandle
from ray.serve.async_goal_manager import AsyncGoalManager
from ray.serve.backend_worker import create_backend_replica
@edoakes
edoakes / mp.py
Last active November 20, 2020 21:00
import math
import random
import time
from multiprocessing.pool import Pool
NUM_SAMPLES = 100000000
NUM_PROCESSES = 8
def take_sample(index):
@edoakes
edoakes / pass_by_ref.py
Last active October 22, 2020 19:59
Ray Serve by reference vs. pass by value experiment
import time
import numpy as np
import ray
ray.init(log_to_driver=False)
@ray.remote
class Actor:
def __init__(self, next_actor, by_ref):
This file has been truncated, but you can view the full file.
This time, a new baby is on the way, and it's a girl. Wrapped together with the standard conflict between mother and father, Mikey engages in a bit of sibling rivalry with his new sister.
Excited with the arrival of their baby girl, Julie, the happy couple of James, the cab driver, and Molly, the accountant, will have to prepare young Mikey for the role of the big brother. Against the backdrop of rigorous potty training, heated arguments, and, first and foremost, healthy sibling rivalry, both adults and children alike will learn that family is above all. Will Julie follow in Mikey's footsteps?
Mollie and James are together and raising a family, which now consists of an older Mikey and his baby sister, Julie. Tension between the siblings arises, and as well with Mollie and James when Mollie's brother Stuart moves in. Mikey is also learning how to use the toilet for the first time.
Excited with the arrival of their baby girl, Julie, the happy couple of James, the cab driver, and Molly, the accountant, will have