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

chore: Remove dump example and add sd-gpu example #1065

Merged
merged 2 commits into from
Oct 20, 2022
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
16 changes: 0 additions & 16 deletions examples/pytorch_profiler/build.envd

This file was deleted.

66 changes: 0 additions & 66 deletions examples/pytorch_profiler/main.py

This file was deleted.

15 changes: 15 additions & 0 deletions examples/stable-diffusion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Stable Diffusion

## Requirements

<ol>
<li><a href="https://huggingface.co/join">Sign up to Huggingface</a></li>
<li><a href="https://huggingface.co/CompVis/stable-diffusion-v1-4">Accept the Stable Diffusion models agreement</a></li>
<li><a href="https://huggingface.co/settings/tokens">Create an Access Token</a>. You’ll use it in the Python script below.</li>
</ol>

## Steps

- `envd up`
- `export HUGGINGFACE_TOKEN=<token>
- `python main.py`
14 changes: 14 additions & 0 deletions examples/stable-diffusion/build.envd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def build():
base(os="ubuntu20.04", language="python")
# config.pip_index(url = "https://pypi.tuna.tsinghua.edu.cn/simple")
install.python_packages(
[
"torch",
"transformers",
"diffusers",
]
)
install.cuda(version="11.2.0", cudnn="8")
runtime.mount(
host_path="~/.cache/huggingface", envd_path="/home/envd/.cache/huggingface"
)
27 changes: 27 additions & 0 deletions examples/stable-diffusion/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import random
import sys
import os

from diffusers import StableDiffusionPipeline

device = "cuda"


def dummy(images, **kwargs):
return images, False


# Read prompt from command line
prompt = " ".join(sys.argv[1:])

pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4", use_auth_token=os.environ["HUGGINGFACE_TOKEN"]
)
pipe.to(device)
pipe.safety_checker = dummy

# Run until we exit with CTRL+C
while True:
n = random.randint(1000, 9999)
image = pipe(prompt, guidance_scale=7.5)["sample"][0]
image.save(f"{n}.jpeg")