Skip to content

Commit

Permalink
add readme and test pre commit
Browse files Browse the repository at this point in the history
  • Loading branch information
strint committed Jul 18, 2024
1 parent f09ab41 commit f699b4a
Show file tree
Hide file tree
Showing 247 changed files with 2,900 additions and 1,428 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assignees: strint
#### A clear and concise description of what the bug is.

### Your environment
#### OS
#### OS

#### OneDiff git commit id

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ jobs:
SDXL_BASE: ${{ env.SDXL_BASE }}
UNET_INT8: ${{ env.UNET_INT8 }}
SILICON_ONEDIFF_LICENSE_KEY: ${{ secrets.SILICON_ONEDIFF_LICENSE_KEY }}

- name: Setup docker for WebUI Test
if: matrix.test-suite == 'webui'
run: |
Expand Down Expand Up @@ -351,7 +351,7 @@ jobs:
run: |
docker exec -w /src/onediff ${{ env.CONTAINER_NAME }} python3 onediff_diffusers_extensions/examples/text_to_image_sd_enterprise.py --model /share_nfs/hf_models/stable-diffusion-v1-5-int8 --width 512 --height 512 --saved_image /src/onediff/output_enterprise_sd.png
docker exec -w /src/onediff ${{ env.CONTAINER_NAME }} python3 tests/test_quantitative_quality.py
- name: Install Requirements for WebUI
if: matrix.test-suite == 'webui'
run: |
Expand Down
26 changes: 13 additions & 13 deletions README_ENTERPRISE.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Ensure that you have installed [OneDiff ComfyUI Nodes](onediff_comfy_nodes/READM

For more information and to **access the model files and Workflow below**, please visit [Hugging Face - stable-diffusion-v1-5-onediff-enterprise-v1](https://huggingface.co/siliconflow/stable-diffusion-v1-5-onediff-comfy-enterprise-v1/tree/main).

<details>
<details>
<summary> Download the required model files </summary>

1. Download the [`v1-5-pruned.safetensors`](https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors) file and place it in the `ComfyUI/models/checkpoints/` directory:
Expand All @@ -149,7 +149,7 @@ Click the links below to view the workflow images, or load them directly into Co

For more information and to **access the model files and Workflow below**, please visit [Hugging Face - stable-diffusion-v2-1-onediff-enterprise](https://huggingface.co/siliconflow/stable-diffusion-v2-1-onediff-comfy-enterprise/tree/main).

<details>
<details>
<summary> Download the required model files </summary>

1. Download the [`v2-1_768-ema-pruned.zip`](https://huggingface.co/siliconflow/stable-diffusion-v2-1-onediff-comfy-enterprise/blob/main/v2-1_768-ema-pruned.zip) file and unzip ,then place the .safetensors in the `ComfyUI/models/checkpoints/` directory:
Expand All @@ -166,15 +166,15 @@ wget https://huggingface.co/siliconflow/stable-diffusion-v2-1-onediff-comfy-ente

</details>

Click the links below to view the workflow images, or load them directly into ComfyUI.
Click the links below to view the workflow images, or load them directly into ComfyUI.

- Workflow: [SD 2.1](https://huggingface.co/siliconflow/stable-diffusion-v2-1-onediff-comfy-enterprise/blob/main/onediff_stable_diffusion_2_1.png)

### ComfyUI SDXL

For model details and to **access the model files and Workflow below**, please visit [Hugging Face - sdxl-base-1.0-onediff-comfy-enterprise-v1](https://huggingface.co/siliconflow/sdxl-base-1.0-onediff-comfy-enterprise-v1/tree/main).

<details>
<details>
<summary> Download the required model files </summary>

1. Download the [`sd_xl_base_1.0.safetensors`](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors) file and place it in the `ComfyUI/models/checkpoints/` directory:
Expand Down Expand Up @@ -373,20 +373,20 @@ To download the necessary models, please visit the [siliconflow/stable-video-dif
Run [image_to_video.py](benchmarks/image_to_video.py):

```bash
python3 benchmarks/image_to_video.py \
--model $model_path \
--input-image path/to/input_image.jpg \
--output-video path/to/output_image.mp4
python3 benchmarks/image_to_video.py \
--model $model_path \
--input-image path/to/input_image.jpg \
--output-video path/to/output_image.mp4
```

#### SVD + DeepCache

```bash
python3 benchmarks/image_to_video.py \
--model $model_path \
--deepcache \
--input-image path/to/input_image.jpg \
--output-video path/to/output_image.mp4
python3 benchmarks/image_to_video.py \
--model $model_path \
--deepcache \
--input-image path/to/input_image.jpg \
--output-video path/to/output_image.mp4
```

## Quantitative model
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/docker/_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import hashlib
import os
import subprocess
import yaml

from git import Repo
import yaml

from _logger import logger

from git import Repo


def load_yaml(*, file):
if not os.path.exists(file):
Expand Down
43 changes: 31 additions & 12 deletions benchmarks/docker/main.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
import argparse
from datetime import datetime
import os
import sys
from datetime import datetime
from pathlib import Path

ONEDIFFBOX_ROOT = Path(os.path.abspath(__file__)).parents[0]
sys.path.insert(0, str(ONEDIFFBOX_ROOT))

from _logger import logger
from _utils import (
calculate_sha256,
setup_repo,
load_yaml,
generate_docker_file,
build_image,
calculate_sha256,
gen_docker_compose_yaml,
generate_docker_file,
load_yaml,
setup_repo,
)
from _logger import logger


def parse_args():
parser = argparse.ArgumentParser(description="Build OneDiff Box")
formatted_datetime = datetime.now().strftime("%Y%m%d-%H%M")

parser.add_argument(
"-y", "--yaml", type=str, default="config/community-default.yaml",
"-y",
"--yaml",
type=str,
default="config/community-default.yaml",
)
parser.add_argument(
"-i", "--image", type=str, default="onediff",
"-i",
"--image",
type=str,
default="onediff",
)
parser.add_argument(
"-t", "--tag", type=str, default=f"benchmark",
"-t",
"--tag",
type=str,
default=f"benchmark",
)
parser.add_argument(
"-o",
Expand All @@ -39,10 +48,17 @@ def parse_args():
help="the output directory of Dockerfile and Docker-compose file",
)
parser.add_argument(
"-c", "--context", type=str, default=".", help="the path to build context",
"-c",
"--context",
type=str,
default=".",
help="the path to build context",
)
parser.add_argument(
"-q", "--quiet", action="store_true", help="quiet mode",
"-q",
"--quiet",
action="store_true",
help="quiet mode",
)
args = parser.parse_args()
return args
Expand Down Expand Up @@ -77,7 +93,10 @@ def parse_args():

envs = image_config.pop("envs", [])
volumes = image_config.pop(
"volumes", ["$BENCHMARK_MODEL_PATH:/benchmark_model:ro",],
"volumes",
[
"$BENCHMARK_MODEL_PATH:/benchmark_model:ro",
],
)
compose_file, run_command = gen_docker_compose_yaml(
f"onediff-benchmark-{version}", image_name, envs, volumes, args.output
Expand Down
30 changes: 20 additions & 10 deletions benchmarks/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
CACHE_INTERVAL = 3
CACHE_BRANCH = 0

import os
import argparse
import importlib
import inspect
import argparse
import time
import json
import os
import random
from PIL import Image, ImageDraw
import time

import oneflow as flow
import torch
from onediffx import compile_pipe, OneflowCompileOptions
from diffusers.utils import load_image, export_to_video
from diffusers.utils import export_to_video, load_image
from onediffx import compile_pipe, OneflowCompileOptions
from PIL import Image, ImageDraw


def parse_args():
Expand Down Expand Up @@ -84,10 +84,14 @@ def parse_args():
default=ATTENTION_FP16_SCORE_ACCUM_MAX_M,
)
parser.add_argument(
"--alter-height", type=int, default=ALTER_HEIGHT,
"--alter-height",
type=int,
default=ALTER_HEIGHT,
)
parser.add_argument(
"--alter-width", type=int, default=ALTER_WIDTH,
"--alter-width",
type=int,
default=ALTER_WIDTH,
)
return parser.parse_args()

Expand All @@ -110,7 +114,8 @@ def load_pipe(
from diffusers import ControlNetModel

controlnet = ControlNetModel.from_pretrained(
controlnet, torch_dtype=torch.float16,
controlnet,
torch_dtype=torch.float16,
)
extra_kwargs["controlnet"] = controlnet
if os.path.exists(os.path.join(model_name, "calibrate_info.txt")):
Expand Down Expand Up @@ -218,7 +223,12 @@ def main():
control_image = Image.new("RGB", (width, height))
draw = ImageDraw.Draw(control_image)
draw.ellipse(
(width // 4, height // 4, width // 4 * 3, height // 4 * 3,),
(
width // 4,
height // 4,
width // 4 * 3,
height // 4 * 3,
),
fill=(255, 255, 255),
)
del draw
Expand Down
27 changes: 15 additions & 12 deletions benchmarks/instant_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,24 @@
CACHE_LAYER_ID = 0
CACHE_BLOCK_ID = 0

import sys
import os
import argparse
import importlib
import inspect
import argparse
import time
import json
import torch
from PIL import Image, ImageDraw
import numpy as np
import os
import sys
import time

import cv2
from huggingface_hub import snapshot_download
from diffusers.utils import load_image
from insightface.app import FaceAnalysis
import numpy as np

import oneflow as flow
import torch
from diffusers.utils import load_image
from huggingface_hub import snapshot_download
from insightface.app import FaceAnalysis
from onediffx import compile_pipe
from PIL import Image, ImageDraw


def parse_args():
Expand Down Expand Up @@ -97,7 +98,8 @@ def load_pipe(
from diffusers import ControlNetModel

controlnet = ControlNetModel.from_pretrained(
controlnet, torch_dtype=torch.float16,
controlnet,
torch_dtype=torch.float16,
)
extra_kwargs["controlnet"] = controlnet
if os.path.exists(os.path.join(model_name, "calibrate_info.txt")):
Expand Down Expand Up @@ -183,13 +185,14 @@ def main():
if args.repo is None:
custom_pipeline = args.custom_pipeline
from diffusers import DiffusionPipeline

pipeline_cls = DiffusionPipeline
else:
sys.path.insert(0, args.repo)

from pipeline_stable_diffusion_xl_instantid import (
StableDiffusionXLInstantIDPipeline as pipeline_cls,
draw_kps,
StableDiffusionXLInstantIDPipeline as pipeline_cls,
)

if os.path.exists(args.controlnet):
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/patch_stable_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def pixel_shuffle(input, upscale_factor):
*batch_dims, channels, height, width = input.shape

assert (
channels % (upscale_factor ** 2) == 0
channels % (upscale_factor**2) == 0
), "Number of channels must be divisible by the square of the upscale factor"

# Calculate new channels after applying upscale_factor
new_channels = channels // (upscale_factor ** 2)
new_channels = channels // (upscale_factor**2)

# Reshape input to (*batch_dims, new_channels, upscale_factor, upscale_factor, height, width)
reshaped = input.reshape(
Expand Down Expand Up @@ -143,7 +143,7 @@ def pixel_unshuffle(input, downscale_factor):
# Final reshape
output = permuted.reshape(
*batch_dims,
channels * downscale_factor ** 2,
channels * downscale_factor**2,
height // downscale_factor,
width // downscale_factor,
)
Expand Down
8 changes: 5 additions & 3 deletions benchmarks/patch_stable_cascade_of.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import importlib.metadata
from typing import Optional

import oneflow as torch
import oneflow.nn as nn
import oneflow.nn.functional as F
from packaging import version
import importlib.metadata

from onediff.infer_compiler.backends.oneflow.transform import transform_mgr
from packaging import version

diffusers_of = transform_mgr.transform_package("diffusers")
StableCascadeUnet_OF_CLS = (
Expand Down Expand Up @@ -114,14 +115,15 @@ def forward(
return self.clf(x).to(torch.float16)


from contextlib import contextmanager

# diffusers.pipelines.stable_cascade.modeling_stable_cascade_common.StableCascadeUnet
from diffusers.pipelines.stable_cascade.modeling_stable_cascade_common import (
StableCascadeUnet,
)

# torch2oflow_class_map.update({StableCascadeUnet: StableCascadeUnetOflow})
from onediff.infer_compiler.backends.oneflow.transform import register
from contextlib import contextmanager


@contextmanager
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/run_image_to_video_benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ while getopts 'm:w:c:o:h' opt; do
o)
OUTPUT_FILE=$OPTARG
;;

?|h)
echo "Usage: $(basename $0) [-m model_dir] [-w warmups] [-c compiler] [-o output_file]"
echo " -m model_dir: the directory of the models, if not set, use HF models"
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/run_sdxl_light_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ TXT2IMG_ONEFLOW_OUTPUT_FILE=${OUTPUT_DIR}/sdxl_light_oneflow.md
BENCHMARK_RESULT_TEXT="${BENCHMARK_RESULT_TEXT}\n\n### Text to Image (OneFlow)\n\n$(cat ${TXT2IMG_ONEFLOW_OUTPUT_FILE})\n\n"

echo -e "${BENCHMARK_RESULT_TEXT}" > ${OUTPUT_FILE}


Loading

0 comments on commit f699b4a

Please sign in to comment.