-
Notifications
You must be signed in to change notification settings - Fork 84
/
demo.py
53 lines (45 loc) · 1.67 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# ---------------------------------------------------------------------
# Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
# ---------------------------------------------------------------------
from diffusers import DPMSolverMultistepScheduler, UNet2DConditionModel
from transformers import CLIPTokenizer
from qai_hub_models.models._shared.stable_diffusion.demo import stable_diffusion_demo
from qai_hub_models.models.riffusion_quantized.model import (
MODEL_ASSET_VERSION,
MODEL_ID,
ClipVITTextEncoder,
Unet,
VAEDecoder,
)
# Run Riffuison end-to-end on a given prompt. The demo will output an
# AI-generated image based on the description in the prompt.
def main(is_test: bool = False):
tokenizer = CLIPTokenizer.from_pretrained(
"openai/clip-vit-large-patch14", subfolder="", revision="main"
)
scheduler = DPMSolverMultistepScheduler(
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
num_train_timesteps=1000,
)
time_embedding = UNet2DConditionModel.from_pretrained(
"riffusion/riffusion-model-v1", subfolder="unet"
).time_embedding
text_encoder = ClipVITTextEncoder.from_precompiled()
unet = Unet.from_precompiled()
vae_decoder = VAEDecoder.from_precompiled()
stable_diffusion_demo(
model_id=MODEL_ID,
model_asset_version=MODEL_ASSET_VERSION,
text_encoder=text_encoder,
unet=unet,
vae_decoder=vae_decoder,
tokenizer=tokenizer,
scheduler=scheduler,
time_embedding=time_embedding,
is_test=is_test,
)
if __name__ == "__main__":
main()