Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat pre commit lint #1024

Merged
merged 18 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exclude: '((generator.py)|(generated/.*))$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-docstring-first
- id: check-toml
- id: check-yaml
exclude: packaging/.*
args:
- --allow-multiple-documents
- id: mixed-line-ending
args: [--fix=lf]
- id: end-of-file-fixer

- repo: https://github.com/omnilib/ufmt
rev: v1.3.3
hooks:
- id: ufmt
additional_dependencies:
- black == 22.3.0
strint marked this conversation as resolved.
Show resolved Hide resolved
- usort == 1.0.2

# - repo: https://github.com/PyCQA/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
#
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ For example:
+ [onediff Enterprise Edition](#onediff-enterprise-edition)
<!-- tocstop -->

## Documentation
## Documentation
onediff is the abbreviation of "**one** line of code to accelerate **diff**usion models".

### Use with HF diffusers and ComfyUI
Expand Down Expand Up @@ -180,8 +180,20 @@ python3 -m pip install --pre onediff
- From source
```
git clone https://github.com/siliconflow/onediff.git
```
```
cd onediff && python3 -m pip install -e .
```
Or install for development:
```
# install for dev
cd onediff && python3 -m pip install -e '.[dev]'

# code formatting and linting
pip3 install pre-commit
pre-commit install
pre-commit run --all-files
strint marked this conversation as resolved.
Show resolved Hide resolved
```

> **_NOTE:_** If you intend to utilize plugins for ComfyUI/StableDiffusion-WebUI, we highly recommend installing OneDiff from the source rather than PyPI. This is necessary as you'll need to manually copy (or create a soft link) for the relevant code into the extension folder of these UIs/Libs.

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
31 changes: 21 additions & 10 deletions benchmarks/image_to_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@
CACHE_INTERVAL = 3
CACHE_BRANCH = 0

import os
import argparse
import importlib
import inspect
import argparse
import time
import json
import os
import random
import time

from PIL import Image, ImageDraw

import oneflow as flow
import oneflow as flow # usort: skip
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


def parse_args():
Expand Down Expand Up @@ -84,10 +85,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 +115,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 +224,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
25 changes: 14 additions & 11 deletions benchmarks/instant_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@
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
import numpy as np
import torch
from diffusers.utils import load_image
from huggingface_hub import snapshot_download
from insightface.app import FaceAnalysis
from PIL import Image, ImageDraw

import oneflow as flow
import oneflow as flow # usort: skip
from onediffx import compile_pipe


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
Loading