Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add beam.cloud deployment example #1228

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/beam-cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Deploy Outlines on Beam

1. Create an account [here](https://beam.cloud) and install the Beam SDK
2. Download the `app.py` file to your computer
3. Deploy it as a serverless API by running: `beam deploy app.py:predict`
39 changes: 39 additions & 0 deletions examples/beam-cloud/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from beam import Image, endpoint, env

if env.is_remote():
import outlines


# Pre-load models when the container first starts
def load_models():
import outlines

model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
return model


@endpoint(
name="outlines-serverless",
gpu="A10G",
cpu=1,
memory="16Gi",
on_start=load_models,
image=Image().add_python_packages(
["outlines", "torch", "transformers", "accelerate"]
),
)
def predict(context, **inputs):
default_prompt = """You are a sentiment-labelling assistant.
Is the following review positive or negative?

Review: This restaurant is just awesome!
"""

prompt = inputs.get("prompt", default_prompt)

# Unpack cached model from context
model = context.on_start_value
# Inference
generator = outlines.generate.choice(model, ["Positive", "Negative"])
answer = generator(prompt)
return {"answer": answer}
Loading