From 6ea203dd84977b8505679f218ee779a8171a59f9 Mon Sep 17 00:00:00 2001 From: Yao Chi Date: Wed, 24 Jan 2024 18:25:29 +0800 Subject: [PATCH] add ci for deepcache and int8 (#556) Co-authored-by: clackhan --- .github/workflows/examples.yml | 10 +++++++++- ...ext_to_image_deep_cache_sdxl_enterprise.py | 12 ++++-------- examples/text_to_image_sdxl_enterprise.py | 19 ++++--------------- examples/unet_torch_interplay.py | 8 +++++++- onediff_diffusers_extensions/setup.py | 1 - 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index e2216ff4b..d85426733 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -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 @@ -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' diff --git a/examples/text_to_image_deep_cache_sdxl_enterprise.py b/examples/text_to_image_deep_cache_sdxl_enterprise.py index aa4a949b8..48cc3f8f1 100644 --- a/examples/text_to_image_deep_cache_sdxl_enterprise.py +++ b/examples/text_to_image_deep_cache_sdxl_enterprise.py @@ -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=( @@ -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 @@ -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: diff --git a/examples/text_to_image_sdxl_enterprise.py b/examples/text_to_image_sdxl_enterprise.py index 693b8551a..654830c7e 100644 --- a/examples/text_to_image_sdxl_enterprise.py +++ b/examples/text_to_image_sdxl_enterprise.py @@ -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=( @@ -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 @@ -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 @@ -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) diff --git a/examples/unet_torch_interplay.py b/examples/unet_torch_interplay.py index d0a9482d6..e7b7250d6 100644 --- a/examples/unet_torch_interplay.py +++ b/examples/unet_torch_interplay.py @@ -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 @@ -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" diff --git a/onediff_diffusers_extensions/setup.py b/onediff_diffusers_extensions/setup.py index e27639a53..7d32be63e 100644 --- a/onediff_diffusers_extensions/setup.py +++ b/onediff_diffusers_extensions/setup.py @@ -16,7 +16,6 @@ "accelerate", "torch", "onefx", - "onediff", ], classifiers=[ "Development Status :: 5 - Production/Stable",