-
Notifications
You must be signed in to change notification settings - Fork 541
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
[Example] Add Replicate Cog example #3219
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
694f0b0
[Example] Add Replicate Cog example
concretevitamin 2a26617
Format
concretevitamin 48eaaa8
lint
concretevitamin cd13fc1
Fix
concretevitamin 6b1c878
isort
concretevitamin 18edaa5
Add skyserve
concretevitamin af4b4aa
fix
concretevitamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Example: Cog + SkyPilot | ||
|
||
Use SkyPilot to self-host any Cog-packaged projects. | ||
|
||
This is the "Blur" example from https://github.com/replicate/cog-examples/blob/main/blur/README.md | ||
|
||
## Serve using a single instance | ||
```console | ||
sky launch -c cog ./sky.yaml | ||
|
||
IP=$(sky status --ip cog) | ||
|
||
curl http://$IP:5000/predictions -X POST \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"input": {"image": "https://blog.skypilot.co/introducing-sky-serve/images/sky-serve-thumbnail.png"}}' \ | ||
| jq -r '.output | split(",")[1]' | base64 --decode > output.png | ||
``` | ||
|
||
## Scale up the deployment using SkyServe | ||
We can use SkyServe (`sky serve`) to scale up the deployment to multiple instances, while enjoying load balancing, autoscaling, and other [SkyServe features](https://skypilot.readthedocs.io/en/latest/serving/sky-serve.html). | ||
```console | ||
sky serve up -n cog ./sky.yaml | ||
``` | ||
|
||
Notice the only change is from `sky launch` to `sky serve up`. The same YAML can be used without changes. | ||
|
||
After the service is launched, access the deployment with the following: | ||
```console | ||
ENDPOINT=$(sky serve status --endpoint cog) | ||
|
||
curl -L http://$ENDPOINT/predictions -X POST \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"input": {"image": "https://blog.skypilot.co/introducing-sky-serve/images/sky-serve-thumbnail.png"}}' \ | ||
| jq -r '.output | split(",")[1]' | base64 --decode > output.png | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build: | ||
python_version: "3.8" | ||
python_packages: | ||
- "pillow==8.2.0" | ||
system_packages: | ||
- "libpng-dev" | ||
- "libjpeg-dev" | ||
predict: "predict.py:Predictor" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import tempfile | ||
|
||
import cog | ||
from PIL import Image | ||
from PIL import ImageFilter | ||
|
||
|
||
class Predictor(cog.BasePredictor): | ||
|
||
def predict( | ||
self, | ||
image: cog.Path = cog.Input(description='Input image'), | ||
blur: float = cog.Input(description='Blur radius', default=5), | ||
) -> cog.Path: | ||
if blur == 0: | ||
return input | ||
im = Image.open(str(image)) | ||
im = im.filter(ImageFilter.BoxBlur(blur)) | ||
out_path = cog.Path(tempfile.mkdtemp()) / 'out.png' | ||
im.save(str(out_path)) | ||
return out_path |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Example: Cog + SkyPilot. | ||
# | ||
# This is the "Blur" example from https://github.com/replicate/cog-examples/blob/main/blur/README.md | ||
# | ||
# Usage (1 serving instance): | ||
# | ||
# sky launch -c cog ./sky.yaml | ||
# | ||
# IP=$(sky status --ip cog) | ||
# curl http://$IP:5000/predictions -X POST \ | ||
# -H 'Content-Type: application/json' \ | ||
# -d '{"input": {"image": "https://blog.skypilot.co/introducing-sky-serve/images/sky-serve-thumbnail.png"}}' \ | ||
# | jq -r '.output | split(",")[1]' | base64 --decode > output.png | ||
# | ||
# Usage (SkyServe): See README.md | ||
|
||
service: | ||
readiness_probe: | ||
path: /predictions | ||
post_data: | ||
input: {"image": "https://blog.skypilot.co/introducing-sky-serve/images/sky-serve-thumbnail.png"} | ||
replicas: 2 | ||
|
||
resources: | ||
accelerators: {L4, T4, A10G} | ||
ports: | ||
- 5000 | ||
|
||
workdir: . | ||
|
||
setup: | | ||
set -e | ||
sudo curl -o /usr/local/bin/cog -L "https://github.com/replicate/cog/releases/latest/download/cog_$(uname -s)_$(uname -m)" | ||
sudo chmod +x /usr/local/bin/cog | ||
|
||
cog build -t my-model | ||
|
||
run: | | ||
docker run -d -p 5000:5000 --gpus all my-model |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. Is it possible to havea section for launching it with
sky serve
as well? It seems suitable as a serving example : )There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, PTAL.