Skip to content

Commit

Permalink
Feat: stable-diffusion-v2 (#2009)
Browse files Browse the repository at this point in the history
* Upgrade stable diffusion model to v2



Signed-off-by: jagadeesh <jagadeeshj@ideas2it.com>
Co-authored-by: Mark Saroufim <marksaroufim@fb.com>
Co-authored-by: Ankith Gunapal <agunapal@meta.com>
Co-authored-by: Ankith Gunapal <agunapal@ischool.Berkeley.edu>
Co-authored-by: Mark Saroufim <marksaroufim@gmail.com>
  • Loading branch information
5 people authored Jan 18, 2023
1 parent 5cc8d0f commit eced76d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/diffusers/Download_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
TOKEN = "Token generated from Huggingface dashboard"

pipeline = DiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
"stabilityai/stable-diffusion-2",
revision="fp16",
torch_dtype=torch.float16,
use_auth_token=TOKEN,
Expand Down
6 changes: 6 additions & 0 deletions examples/diffusers/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

Set access token generated form Huggingface in `Download_model.py` file

Install dependencies

```bash
pip install -r requirements.txt
```

```bash
python Download_model.py
```
Expand Down
1 change: 0 additions & 1 deletion examples/diffusers/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ install_py_dep_per_model=true
load_models=all
max_response_size=655350000
model_store=/mnt/models/model_store
model_snapshot={"name":"startup.cfg","modelCount":1,"models":{"stable-diffusion":{"1.0":{"defaultVersion":true,"marName":"stable-diffusion.mar","minWorkers":1,"maxWorkers":1,"batchSize":1,"maxBatchDelay":200,"responseTimeout":60}}}}
6 changes: 3 additions & 3 deletions examples/diffusers/stable_diffusion_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import diffusers
import numpy as np
import torch
from diffusers import StableDiffusionPipeline
from diffusers import DiffusionPipeline

from ts.torch_handler.base_handler import BaseHandler

Expand Down Expand Up @@ -42,7 +42,7 @@ def initialize(self, ctx):
with zipfile.ZipFile(model_dir + "/model.zip", "r") as zip_ref:
zip_ref.extractall(model_dir + "/model")

self.pipe = StableDiffusionPipeline.from_pretrained(model_dir + "/model")
self.pipe = DiffusionPipeline.from_pretrained(model_dir + "/model")
self.pipe.to(self.device)
logger.info("Diffusion model from path %s loaded successfully", model_dir)

Expand Down Expand Up @@ -76,7 +76,7 @@ def inference(self, inputs):
"""
# Handling inference for sequence_classification.
inferences = self.pipe(
inputs, guidance_scale=7.5, num_inference_steps=50
inputs, guidance_scale=7.5, num_inference_steps=50, height=768, width=768
).images

logger.info("Generated image: '%s'", inferences)
Expand Down

0 comments on commit eced76d

Please sign in to comment.