Skip to content

Commit

Permalink
add ci for deepcache and int8 (#556)
Browse files Browse the repository at this point in the history
Co-authored-by: clackhan <han_binbin@163.com>
  • Loading branch information
doombeaker and clackhan authored Jan 24, 2024
1 parent e777af6 commit 6ea203d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ jobs:
- run: docker exec ${{ env.CONTAINER_NAME }} python3 -m oneflow --doctor
- run: docker exec ${{ env.CONTAINER_NAME }} python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
- name: Install onediff-quant if needed
if: matrix.image == 'onediff-pro:cu121'
if: startsWith(matrix.image, 'onediff-pro')
run: |
docker exec ${{ env.CONTAINER_NAME }} python3 -m pip install --pre onediff-quant -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/onediff-quant/
- name: Pip Install Requirements for ComfyUI & Test
Expand Down Expand Up @@ -200,6 +200,14 @@ jobs:
if: matrix.test-suite == 'comfy'
run: |
docker exec ${{ env.CONTAINER_NAME }} cat /app/ComfyUI/onediff_comfyui.log
- name: Setup OneDiff diffusers extension
if: matrix.test-suite == 'diffusers_examples' && startsWith(matrix.image, 'onediff-pro')
run: |
docker exec -w /src/onediff/onediff_diffusers_extensions ${{ env.CONTAINER_NAME }} python3 -m pip install e .
- if: matrix.test-suite == 'diffusers_examples' && startsWith(matrix.image, 'onediff-pro')
run: docker exec ${{ env.CONTAINER_NAME }} python3 examples/text_to_image_sdxl_enterprise.py --model /share_nfs/hf_models/stable-diffusion-xl-base-1.0-int8 --width 512 --height 512 --saved_image output_enterprise_sdxl.png
- if: matrix.test-suite == 'diffusers_examples' && startsWith(matrix.image, 'onediff-pro')
run: docker exec ${{ env.CONTAINER_NAME }} python3 examples/text_to_image_deep_cache_sdxl_enterprise.py --model /share_nfs/stable-diffusion-xl-base-1.0-int8-deep-cache --width 512 --height 512 --saved_image output_enterprise_deepcache_sdxl.png
- if: matrix.test-suite == 'diffusers_examples'
run: docker exec ${{ env.CONTAINER_NAME }} python3 examples/text_to_image.py --model_id=/share_nfs/hf_models/stable-diffusion-v1-5
- if: matrix.test-suite == 'diffusers_examples'
Expand Down
12 changes: 4 additions & 8 deletions examples/text_to_image_deep_cache_sdxl_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def parse_args():
parser.add_argument("--steps", type=int, default=30)
parser.add_argument("--bits", type=int, default=8)
parser.add_argument(
"--complie",
"--compile",
default=True,
type=(lambda x: str(x).lower() in ["true", "1", "yes"]),
)
parser.add_argument(
"--complie_text_encoder",
"--compile_text_encoder",
default=False,
type=(lambda x: str(x).lower() in ["true", "1", "yes"]),
help=(
Expand Down Expand Up @@ -61,10 +61,6 @@ def parse_args():
os.path.join(args.model, "calibrate_info.txt")
), f"calibrate_info.txt is required in args.model ({args.model})"

assert (
args.complie
), "Onediff enterprise model can not be executed in pytorch environment. Please set args.complie to 1!"

from diffusers_extensions.deep_cache import StableDiffusionXLPipeline
import onediff_quant
from onediff_quant.utils import replace_sub_module_with_quantizable_module
Expand Down Expand Up @@ -113,13 +109,13 @@ def parse_args():
args.bits,
)

if args.complie_text_encoder:
if args.compile_text_encoder:
if pipe.text_encoder is not None:
pipe.text_encoder = oneflow_compile(pipe.text_encoder, use_graph=args.graph)
if pipe.text_encoder_2 is not None:
pipe.text_encoder_2 = oneflow_compile(pipe.text_encoder_2, use_graph=args.graph)

if args.complie:
if args.compile:
if pipe.text_encoder is not None:
pipe.text_encoder = oneflow_compile(pipe.text_encoder, use_graph=args.graph)
if pipe.text_encoder_2 is not None:
Expand Down
19 changes: 4 additions & 15 deletions examples/text_to_image_sdxl_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def parse_args():
parser.add_argument("--steps", type=int, default=30)
parser.add_argument("--bits", type=int, default=8)
parser.add_argument(
"--complie",
"--compile",
default=True,
type=(lambda x: str(x).lower() in ["true", "1", "yes"]),
)
parser.add_argument(
"--complie_text_encoder",
"--compile_text_encoder",
default=False,
type=(lambda x: str(x).lower() in ["true", "1", "yes"]),
help=(
Expand All @@ -47,9 +47,6 @@ def parse_args():
)
parser.add_argument("--seed", type=int, default=1)
parser.add_argument("--warmup", type=int, default=1)
parser.add_argument("--cache_interval", type=int, default=3)
parser.add_argument("--cache_layer_id", type=int, default=0)
parser.add_argument("--cache_block_id", type=int, default=0)

args = parser.parse_args()
return args
Expand All @@ -61,10 +58,6 @@ def parse_args():
os.path.join(args.model, "calibrate_info.txt")
), f"calibrate_info.txt is required in args.model ({args.model})"

assert (
args.complie
), "Onediff enterprise model can not be executed in pytorch environment. Please set args.complie to 1!"

from diffusers import StableDiffusionXLPipeline
import onediff_quant
from onediff_quant.utils import replace_sub_module_with_quantizable_module
Expand Down Expand Up @@ -111,17 +104,13 @@ def parse_args():
args.bits,
)

if args.complie_text_encoder:
if args.compile_text_encoder:
if pipe.text_encoder is not None:
pipe.text_encoder = oneflow_compile(pipe.text_encoder, use_graph=args.graph)
if pipe.text_encoder_2 is not None:
pipe.text_encoder_2 = oneflow_compile(pipe.text_encoder_2, use_graph=args.graph)

if args.complie:
if pipe.text_encoder is not None:
pipe.text_encoder = oneflow_compile(pipe.text_encoder, use_graph=args.graph)
if pipe.text_encoder_2 is not None:
pipe.text_encoder_2 = oneflow_compile(pipe.text_encoder_2, use_graph=args.graph)
if args.compile:
pipe.unet = oneflow_compile(pipe.unet, use_graph=args.graph)
pipe.vae.decoder = oneflow_compile(pipe.vae.decoder, use_graph=args.graph)

Expand Down
8 changes: 7 additions & 1 deletion examples/unet_torch_interplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
load graph compiled example: python3 examples/unet_torch_interplay.py --load
"""
import os
import importlib.metadata
from packaging import version
import random
import click
import oneflow as flow
Expand Down Expand Up @@ -112,7 +114,11 @@ def benchmark(token, repeat, sync_interval, save, load, file, model_id, variant)

num_channels = 4
cross_attention_dim = unet.config["cross_attention_dim"]
from diffusers.utils import floats_tensor
diffusers_version = version.parse(importlib.metadata.version("diffusers"))
if diffusers_version < version.parse("0.21.0"):
from diffusers.utils import floats_tensor
else:
from diffusers.utils.testing_utils import floats_tensor

if (
model_id == "stabilityai/stable-diffusion-xl-base-1.0"
Expand Down
1 change: 0 additions & 1 deletion onediff_diffusers_extensions/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"accelerate",
"torch",
"onefx",
"onediff",
],
classifiers=[
"Development Status :: 5 - Production/Stable",
Expand Down

0 comments on commit 6ea203d

Please sign in to comment.