### Setup pre-commit hooks Source: https://github.com/siliconflow/onediff/blob/main/README.md Install pre-commit and set up hooks for code formatting and linting. ```bash pip3 install pre-commit pre-commit install pre-commit run --all-files ``` -------------------------------- ### Start ComfyUI Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/OnlineQuantization.md Command to start ComfyUI, optimized for GPU usage. ```bash python main.py --gpu-only ``` -------------------------------- ### Install WSL2 Source: https://github.com/siliconflow/onediff/wiki/Run-OneDiff-on-Windows-by-WSL2 Commands to install and configure the Windows Subsystem for Linux. ```bash wsl --install ``` ```bash dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart ``` ```bash dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart ``` ```bash wsl --set-default-version 2 ``` -------------------------------- ### Install onediff from source Source: https://github.com/siliconflow/onediff/blob/main/README.md Navigate to the cloned onediff directory and install it using pip. ```bash cd onediff && python3 -m pip install -e . ``` -------------------------------- ### Install onediff for development Source: https://github.com/siliconflow/onediff/blob/main/README.md Install onediff from source with development dependencies. ```bash cd onediff && python3 -m pip install -e '.[dev]' ``` -------------------------------- ### Run Examples Source: https://github.com/siliconflow/onediff/blob/main/CONTRIBUTING.md Execute example scripts to verify functionality before proceeding with release steps. Ensure you are in the correct directory. ```bash cd onediff_diffusers_extensions python3 examples/text_to_image.py ``` -------------------------------- ### Install Build Tools Source: https://github.com/siliconflow/onediff/blob/main/CONTRIBUTING.md Install the necessary Python packages for building and uploading distribution packages. ```bash python3 -m pip install build twine ``` -------------------------------- ### Install Dependencies and Build Docker Image Source: https://github.com/siliconflow/onediff/blob/main/benchmarks/README.md Installs project dependencies and builds the OneDiff Docker image. Ensure you have Python 3 and pip installed. ```bash python3 -m pip install -r requirements.txt python3 docker/main.py --yaml ./docker/config/community-default.yaml ``` -------------------------------- ### Install PyTorch and Diffusers Source: https://github.com/siliconflow/onediff/blob/main/README.md Install the required versions of PyTorch, transformers, and diffusers libraries. ```bash python3 -m pip install "torch" "transformers==4.27.1" "diffusers[torch]==0.19.3" ``` -------------------------------- ### Start sd-webui Client with API Source: https://github.com/siliconflow/onediff/blob/main/onediff_sd_webui_extensions/README.md Run this command to start the Stable Diffusion WebUI client with API enabled, allowing external requests. ```bash # start sd-webui client python3 webui.py --api ``` -------------------------------- ### Install OneDiffX Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/README.md Clone the OneDiff repository and install the onediffx package from the cloned directory. ```bash git clone https://github.com/siliconflow/onediff.git cd onediff_diffusers_extensions && python3 -m pip install -e . ``` -------------------------------- ### OneDiff version format example Source: https://github.com/siliconflow/onediff/wiki/How-to-Run-or-Debug-OneDiff Example output showing the standard versioning format for OneDiff and OneDiffX. ```text OneDiff version: 1.1.1.dev63+gb1246aaf.d20240726 OneDiffX version: 1.1.1.dev63+gb1246aaf.d20240726 ``` -------------------------------- ### Install ComfyUI and OneDiff Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/sd3/README.md Installs ComfyUI and the onediff & onediff_comfy_nodes packages. Ensure Python 3.10 is used. This setup links the onediff custom nodes into the ComfyUI directory. ```shell # python 3.10 COMFYUI_DIR=$pwd/ComfyUI # install ComfyUI git clone https://github.com/comfyanonymous/ComfyUI.git # install onediff & onediff_comfy_nodes git clone https://github.com/siliconflow/onediff.git cd onediff && pip install -r onediff_comfy_nodes/sd3/requirements.txt && pip install -e . ln -s $pwd/onediff/onediff_comfy_nodes $COMFYUI_DIR/custom_nodes ``` -------------------------------- ### Install Comfy CLI Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/README.md Installs the Comfy CLI tool. This is the first step for installing ComfyUI via the CLI method. ```shell pip install comfy-cli ``` -------------------------------- ### Install cubiq/ComfyUI_InstantID Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/README.md Clones the repository and resets to a specific commit hash for version stability. ```shell cd ComfyUI/custom_nodes git clone https://github.com/cubiq/ComfyUI_InstantID.git # Date: Thu Jul 11 19:26:22 2024 +0200 git reset --hard 6d95aa6758e58dab550725e59dcefbd426c160c7 ``` -------------------------------- ### Install Nexfort Compiler Backend Source: https://github.com/siliconflow/onediff/blob/main/README.md Install the optional Nexfort compiler backend and compatible PyTorch versions. ```bash python3 -m pip install -U torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 torchao==0.1 python3 -m pip install -U nexfort ``` -------------------------------- ### Install Nexfort Backend Source: https://github.com/siliconflow/onediff/blob/main/src/onediff/infer_compiler/backends/nexfort/README.md Installs the nexfort package. Requires a compatible PyTorch and CUDA environment. ```bash # The current version of nexfort is compatible with torch 2.3.0. pip3 install nexfort ``` -------------------------------- ### Install cubiq/ComfyUI_IPAdapter_plus Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/README.md Clones the repository and resets to a specific commit hash for version stability. ```shell cd ComfyUI/custom_nodes git clone https://github.com/cubiq/ComfyUI_IPAdapter_plus.git # Date: Thu Jul 18 15:12:49 2024 +0200 git reset --hard 78ac59c61c8caf33e3419d2c8f70838b2da0fb04 ``` -------------------------------- ### Install onediff from PyPI Source: https://github.com/siliconflow/onediff/blob/main/README.md Install the onediff package from the Python Package Index (PyPI). ```bash python3 -m pip install --pre onediff ``` -------------------------------- ### Install cubiq/PuLID_ComfyUI Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/README.md Clones the repository and resets to a specific commit hash for version stability. ```shell cd ComfyUI/custom_nodes git clone https://github.com/cubiq/PuLID_ComfyUI.git # Date: Sun May 26 19:23:51 2024 +0200 git reset --hard 80d157ace9e4d2db8c963e770ed99d492d0f4569 ``` -------------------------------- ### Run Stable Diffusion WebUI Service Source: https://github.com/siliconflow/onediff/blob/main/onediff_sd_webui_extensions/README.md Navigate to the stable-diffusion-webui directory and run the webui.sh script with the desired port to start the service. ```bash cd stable-diffusion-webui python webui.py --port 7860 ``` -------------------------------- ### Install PyTorch and Dependencies Source: https://github.com/siliconflow/onediff/blob/main/src/onediff/infer_compiler/backends/nexfort/README.md Installs PyTorch version 2.3.0 and related libraries. Ensure your environment is compatible before running. ```bash pip3 install -U torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 torchao==0.1 ``` -------------------------------- ### Install OneDiff and ComfyUI Nodes Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/benchmarks/README.md Commands to clone the repository, install dependencies, and link the custom nodes to the ComfyUI directory. ```shell # python 3.10 git clone https://github.com/siliconflow/onediff.git cd onediff && pip install -e . ln -s $(pwd)/onediff_comfy_nodes path/to/ComfyUI/custom_nodes/ # or # cp -r onediff_comfy_nodes path/to/ComfyUI/custom_nodes/ ``` -------------------------------- ### Run Stable Diffusion WebUI Source: https://github.com/siliconflow/onediff/wiki/Run-OneDiff-on-Windows-by-WSL2 Commands to navigate to the WebUI directory and start the application. ```bash cd /path/to/your/stable-diffusion-webui ``` ```bash python webui.py ``` -------------------------------- ### Install Stable Diffusion WebUI and OneDiff Extensions Source: https://github.com/siliconflow/onediff/blob/main/onediff_sd_webui_extensions/README.md Clone the repositories for Stable Diffusion WebUI and OneDiff, then link the OneDiff extension to the WebUI's extensions directory. Finally, install all of Stable Diffusion WebUI's dependencies. ```bash git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git git clone https://github.com/siliconflow/onediff.git ln -s "$(pwd)/onediff/onediff_sd_webui_extensions" "$(pwd)/stable-diffusion-webui/extensions/onediff_sd_webui_extensions" cd stable-diffusion-webui # Install all of stable-diffusion-webui's dependencies. # If you install as root user, append `-f` to the end of the command line. venv_dir=- bash webui.sh ``` -------------------------------- ### Initialize Graph Caching Source: https://context7.com/siliconflow/onediff/llms.txt Setup for saving compiled graphs to disk for production deployment. ```python import torch from diffusers import DiffusionPipeline from onediff.infer_compiler import oneflow_compile, OneflowCompileOptions pipe = DiffusionPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", ) pipe.to("cuda") ``` -------------------------------- ### Install ComfyUI-AnimateDiff-Evolved Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/README.md Clones the repository and resets to a specific commit hash for version stability. ```shell cd ComfyUI/custom_nodes git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved.git git reset --hard 1b660e535381a4b4e4028aad38b7ae21c81b861c ``` -------------------------------- ### Run ComfyUI with OneDiff Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/benchmarks/README.md Commands to install the benchmark environment and launch the ComfyUI server with the required extra model paths. ```shell export COMFYUI_ROOT=path/to/ComfyUI cd path/to/onediff/onediff_comfy_nodes/benchmarks bash scripts/install_env.sh $COMFYUI_ROOT cd $COMFYUI_ROOT python main.py --gpu-only --port 8188 --extra-model-paths-config path/to/onediff/tests/comfyui/extra_model_paths.yaml ``` -------------------------------- ### Install Diffusers Library Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/flux/README.md Ensure the diffusers library is installed with PyTorch support. This is a prerequisite for using diffusion models like Flux. ```bash pip3 install --upgrade diffusers[torch] ``` -------------------------------- ### Install Diffusers for Kolors Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/kolors/README.md Install the specific version of the diffusers library required to support the Kolors pipeline. ```bash # Ensure diffusers include the kolors pipeline. pip install git+https://github.com/huggingface/diffusers.git ``` -------------------------------- ### Install OneDiff Package Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/README.md Installs the OneDiff package in editable mode after cloning the repository. This makes the OneDiff library available for use. ```shell cd onediff && pip install -e . ``` -------------------------------- ### Install OneDiff Enterprise (CN, CUDA 12.1) Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Installs OneDiff Enterprise and its dependencies for users in China with CUDA 12.1. Uses CN-specific repositories. ```bash python3 -m pip install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/main/cu121/ && \ python3 -m pip install --pre onediff-quant -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/onediff-quant/ && \ python3 -m pip install git+https://github.com/siliconflow/onediff.git@main#egg=onediff ``` -------------------------------- ### Install OneDiff Enterprise (CN, CUDA 11.8) Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Installs OneDiff Enterprise and its dependencies for users in China with CUDA 11.8. Uses CN-specific repositories. ```bash python3 -m pip install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/main/cu118/ && \ python3 -m pip install --pre onediff-quant -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/onediff-quant/ && \ python3 -m pip install git+https://github.com/siliconflow/onediff.git@main#egg=onediff ``` -------------------------------- ### Install ComfyUI_InstantID Custom Node Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/modules/oneflow/hijack_comfyui_instantid/README.md Clone the ComfyUI_InstantID repository and reset to a specific commit. Ensure you are in the 'ComfyUI/custom_nodes' directory before running. ```shell cd ComfyUI/custom_nodes git clone https://github.com/cubiq/ComfyUI_InstantID.git git reset --hard d8c70a0cd8ce0d4d62e78653674320c9c3084ec1 ``` -------------------------------- ### Install OneDiff Enterprise (CN, CUDA 12.2) Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Installs OneDiff Enterprise and its dependencies for users in China with CUDA 12.2. Uses CN-specific repositories. ```bash python3 -m pip install --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/main/cu122/ && \ python3 -m pip install --pre onediff-quant -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/onediff-quant/ && \ python3 -m pip install git+https://github.com/siliconflow/onediff.git@main#egg=onediff ``` -------------------------------- ### Run SDXL with DeepCache Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Requires OneDiffX installation. Executes the enterprise script with DeepCache enabled for SDXL models. ```bash python text_to_image_deep_cache_sd_sdxl_enterprise.py --model $model_path --model_type sdxl --saved_image output_deepcache.png ``` -------------------------------- ### Install OneDiff Extension for WebUI Source: https://github.com/siliconflow/onediff/wiki/Run-OneDiff-on-Windows-by-WSL2 Commands to clone the OneDiff repository and link it to the Stable Diffusion WebUI extensions directory. ```bash git clone https://github.com/siliconflow/onediff.git ``` ```bash ln -s "$(pwd)/onediff/onediff_sd_webui_extensions" "$(pwd)/stable-diffusion-webui/extensions/onediff_sd_webui_extensions" cd $(pwd)/stable-diffusion-webui venv_dir=- bash webui.sh # Exit webui server and upgrade some of the components that conflict with onediff. cd repositories/generative-models && git checkout 9d759324 && cd - ``` -------------------------------- ### Run SD with DeepCache Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Requires OneDiffX installation. Executes the enterprise script with DeepCache enabled for SD models. ```bash python text_to_image_deep_cache_sd_sdxl_enterprise.py --model $model_path --model_type sd --saved_image output_deepcache_sd.png ``` -------------------------------- ### Run Stable Diffusion XL with OneDiffX DeepCache Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/README.md Initialize and compile a Stable Diffusion XL pipeline with DeepCache enabled for accelerated inference. This example sets up the pipeline and defines a prompt. ```python import torch from onediffx import compile_pipe from onediffx.deep_cache import StableDiffusionXLPipeline pipe = StableDiffusionXLPipeline.from_pretrained( "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True ) pipe.to("cuda") pipe = compile_pipe(pipe) prompt = "A photo of a cat. Focus light and create sharp, defined edges." ``` -------------------------------- ### Install ComfyUI via CLI Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/README.md Installs ComfyUI using the Comfy CLI. This command automates the ComfyUI installation process. ```shell comfy install ``` -------------------------------- ### Compile Arbitrary Models with OneDiff Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/sd3/README.md Demonstrates compiling a custom PyTorch module using OneDiff's infer_compiler with the Nexfort backend. This example requires `is_nexfort_available` to be true and uses specific compilation options for optimization. ```python # Compile arbitrary models (torch.nn.Module) import torch from onediff.utils.import_utils import is_nexfort_available assert is_nexfort_available() == True import onediff.infer_compiler as infer_compiler class MyModule(torch.nn.Module): def __init__(self): super().__init__() self.lin = torch.nn.Linear(100, 10) def forward(self, x): return torch.nn.functional.relu(self.lin(x)) mod = MyModule().to("cuda").half() with torch.inference_mode(): compiled_mod = infer_compiler.compile(mod, backend="nexfort", options={"mode": "max-autotune:cudagraphs", "dynamic": True, "fullgraph": True}, ) print(compiled_mod(torch.randn(10, 100, device="cuda").half()).shape) print("Successfully installed~") ``` -------------------------------- ### Install OneDiff Enterprise (NA/EU, CUDA 12.2) Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Installs OneDiff Enterprise and its dependencies for users in North America/Europe with CUDA 12.2. Ensure you have the correct CUDA version installed. ```bash python3 -m pip install --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/enterprise_cu122 && \ python3 -m pip install --pre onediff-quant -f https://github.com/siliconflow/onediff_releases/releases/expanded_assets/enterprise && \ python3 -m pip install git+https://github.com/siliconflow/onediff.git@main#egg=onediff ``` -------------------------------- ### Set up Latte Environment Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/latte/README.md Clone the Latte repository, navigate into the directory, and set the PYTHONPATH environment variable. This is necessary for using Latte models. ```bash git clone -b run https://github.com/siliconflow/dit_latte/ cd dit_latte export PYTHONPATH=`pwd`:$PYTHONPATH ``` -------------------------------- ### Install OneDiff Enterprise (NA/EU, CUDA 12.1) Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Installs OneDiff Enterprise and its dependencies for users in North America/Europe with CUDA 12.1. Ensure you have the correct CUDA version installed. ```bash python3 -m pip install --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/enterprise_cu121 && \ python3 -m pip install --pre onediff-quant -f https://github.com/siliconflow/onediff_releases/releases/expanded_assets/enterprise && \ python3 -m pip install git+https://github.com/siliconflow/onediff.git@main#egg=onediff ``` -------------------------------- ### Install OneDiff Enterprise (NA/EU, CUDA 11.8) Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Installs OneDiff Enterprise and its dependencies for users in North America/Europe with CUDA 11.8. Ensure you have the correct CUDA version installed. ```bash python3 -m pip install --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/enterprise_cu118 && \ python3 -m pip install --pre onediff-quant -f https://github.com/siliconflow/onediff_releases/releases/expanded_assets/enterprise && \ python3 -m pip install git+https://github.com/siliconflow/onediff.git@main#egg=onediff ``` -------------------------------- ### Build Distribution Wheel Source: https://github.com/siliconflow/onediff/blob/main/CONTRIBUTING.md Clean the distribution directory and then build the wheel package for the project. ```bash rm -rf dist python3 -m build ``` -------------------------------- ### Install Required Python Packages Source: https://github.com/siliconflow/onediff/wiki/Run-OneDiff-on-Windows-by-WSL2 Install specific versions of dependencies required for OneDiff. ```bash pip install -U einops==0.7.0 ``` -------------------------------- ### Download Models for Benchmarking Source: https://github.com/siliconflow/onediff/blob/main/benchmarks/README.md Downloads the necessary models for running the OneDiff benchmark. This script should be executed in the project's root directory. ```bash sh download_models.sh models ``` -------------------------------- ### Download SD 1.5 Quantization Info Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Use wget to download the quantization info file for SD 1.5 and place it in the ComfyUI onediff_quant directory. ```bash wget https://huggingface.co/siliconflow/stable-diffusion-v1-5-onediff-comfy-enterprise-v1/resolve/main/v1-5-pruned_quantize_info.pt -O ComfyUI/models/onediff_quant/v1-5-pruned_quantize_info.pt ``` -------------------------------- ### Install OneFlow for CUDA 12.1 (CN) Source: https://github.com/siliconflow/onediff/blob/main/README.md Install OneFlow for CUDA 12.1 using pip. This command is for users in China. ```bash python3 -m pip install -U --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu122 ``` -------------------------------- ### Install OneFlow for CUDA 11.8 (CN) Source: https://github.com/siliconflow/onediff/blob/main/README.md Install OneFlow for CUDA 11.8 using pip. This command is for users in China. ```bash python3 -m pip install -U --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu118 ``` -------------------------------- ### Download SD 2.1 Quantization Info Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Use wget to download the quantization info file for SD 2.1 and place it in the ComfyUI onediff_quant directory. Note: The target filename in the command is a placeholder and should match the actual file name after download and potential extraction. ```bash wget https://huggingface.co/siliconflow/stable-diffusion-v2-1-onediff-comfy-enterprise/blob/main/v2-1_768-ema-pruned.pt -O ComfyUI/models/onediff_quant/v1-5-pruned_quantize_info.pt ``` -------------------------------- ### Download SDXL Base Model and InstantID Models (NA/EU) Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/modules/oneflow/hijack_comfyui_instantid/README.md Download the Stable Diffusion XL base model, InstantID adapter, and ControlNet model for NA/EU users. Place them in the specified directories within ComfyUI. ```shell cd ComfyUI # Load Checkpoint wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors # Load InstantID Model mkdir -p models/instantid wget -O models/instantid/ip-adapter.bin https://huggingface.co/InstantX/InstantID/resolve/main/ip-adapter.bin # Load ControlNet Model wget -O models/controlnet/diffusion_pytorch_model.safetensors https://huggingface.co/InstantX/InstantID/resolve/main/ControlNetModel/diffusion_pytorch_model.safetensors ``` -------------------------------- ### Install OneFlow for CUDA 12.1 (NA/EU) Source: https://github.com/siliconflow/onediff/blob/main/README.md Install OneFlow for CUDA 12.1 using pip. This command is for users in North America and Europe. ```bash python3 -m pip install -U --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/community_cu122 ``` -------------------------------- ### Download SD 1.5 Checkpoint Model Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Use wget to download the pruned safetensors file for Stable Diffusion 1.5 and place it in the ComfyUI checkpoints directory. ```bash wget https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors -O ComfyUI/models/checkpoints/v1-5-pruned.safetensors ``` -------------------------------- ### Install OneFlow for CUDA 11.8 (NA/EU) Source: https://github.com/siliconflow/onediff/blob/main/README.md Install OneFlow for CUDA 11.8 using pip. This command is for users in North America and Europe. ```bash python3 -m pip install -U --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/community_cu118 ``` -------------------------------- ### Execute Text-to-Image Benchmark Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/benchmarks/README.md Command to run the text-to-image benchmark script, with results saved to the results directory. ```shell cd path/to/onediff/onediff_comfy_nodes/benchmarks bash scripts/run_text_to_image.sh ``` -------------------------------- ### Download SDXL Base Model and InstantID Models (CN) Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/modules/oneflow/hijack_comfyui_instantid/README.md Download the Stable Diffusion XL base model, InstantID adapter, and ControlNet model for CN users using HF mirror. Place them in the specified directories within ComfyUI. ```shell cd ComfyUI wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://hf-mirror.com/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors # Load InstantID Model mkdir -p models/instantid wget -O models/instantid/ip-adapter.bin https://hf-mirror.com/InstantX/InstantID/resolve/main/ip-adapter.bin # Load ControlNet Model wget -O models/controlnet/diffusion_pytorch_model.safetensors https://hf-mirror.com/InstantX/InstantID/resolve/main/ControlNetModel/diffusion_pytorch_model.safetensors ``` -------------------------------- ### Run Quantization Benchmark Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/pixart/README.md Use this command to run a benchmark with quantization enabled. It specifies the model, scheduler, output image, prompt, compiler, compiler configuration, and quantization configuration. Adjust parameters as needed for different models and quantization types. ```python python3 ./benchmarks/text_to_image.py \ --model PixArt-alpha/PixArt-XL-2-1024-MS \ --scheduler none \ --steps 20 \ --output-image ./pixart_alpha_fp8.png \ --prompt "product photography, world of warcraft orc warrior, white background" \ --compiler nexfort \ --compiler-config '{"mode": "quant:max-optimize:max-autotune:freezing:benchmark:low-precision:cudagraphs", "memory_format": "channels_last"}' \ --quantize \ --quantize-config '{"quant_type": "fp8_e4m3_e4m3_dynamic"}' ``` -------------------------------- ### Install OneDiff Comfy Nodes via CLI Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/README.md Installs the OneDiff Comfy Nodes using the Comfy CLI. This command integrates OneDiff functionality into ComfyUI. ```shell comfy node install onediff_comfy_nodes ``` -------------------------------- ### Run SD1.5 Benchmark With NexFort Compilation Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd1.5/README.md Execute the text-to-image benchmark using the NexFort compiler with specific optimization configurations. ```shell python3 benchmarks/text_to_image.py \ --model runwayml/stable-diffusion-v1-5 \ --height 512 --width 512 \ --scheduler none \ --steps 20 \ --output-image ./stable-diffusion-v1-5-compile.png \ --prompt "beautiful scenery nature glass bottle landscape, , purple galaxy bottle," \ --compiler nexfort \ --compiler-config '{"mode": "cudagraphs:benchmark:max-autotune:low-precision:cache-all", "memory_format": "channels_last", "options": {"inductor.optimize_linear_epilogue": true, "overrides.conv_benchmark": true, "overrides.matmul_allow_tf32": true}}' \ --seed 1 \ --print-output ``` -------------------------------- ### Check PyTorch Version Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/OnlineQuantization.md Verify your PyTorch installation version. ```python import torch; print(torch.__version__) ``` -------------------------------- ### Download Model Files Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/modules/nexfort/hijack_comfyui_instantid/README.md Scripts to download required checkpoints and models for InstantID, provided for different geographic regions. ```shell cd ComfyUI # Load Checkpoint wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors # Load InstantID Model mkdir -p models/instantid wget -O models/instantid/ip-adapter.bin https://huggingface.co/InstantX/InstantID/resolve/main/ip-adapter.bin # Load ControlNet Model wget -O models/controlnet/diffusion_pytorch_model.safetensors https://huggingface.co/InstantX/InstantID/resolve/main/ControlNetModel/diffusion_pytorch_model.safetensors ``` ```shell cd ComfyUI wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://hf-mirror.com/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors # Load InstantID Model mkdir -p models/instantid wget -O models/instantid/ip-adapter.bin https://hf-mirror.com/InstantX/InstantID/resolve/main/ip-adapter.bin # Load ControlNet Model wget -O models/controlnet/diffusion_pytorch_model.safetensors https://hf-mirror.com/InstantX/InstantID/resolve/main/ControlNetModel/diffusion_pytorch_model.safetensors ``` -------------------------------- ### Install Diffusers Library Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd35/README.md Upgrade the diffusers library to ensure support for the SD35 pipeline. ```bash # Ensure diffusers include the SD35 pipeline. pip3 install --upgrade diffusers[torch] ``` -------------------------------- ### Text-to-Image Generation with Quantization and T5 Speedup Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/flux/README.md This command enables text-to-image generation with quantization and specifically speeds up the T5 model, which is crucial for memory-constrained GPUs like the RTX 4090. ```bash NEXFORT_FORCE_QUANTE_ON_CUDA=1 python3 onediff_diffusers_extensions/examples/flux/text_to_image_flux.py \ --quantize \ --transform \ --speedup-t5 \ --saved-image flux_compile.png ``` -------------------------------- ### Download SVD and SDXL Model Files Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/ComfyUI_Online_Quantization.md Downloads the Stable Diffusion XL base and SVD XT model checkpoints into the ComfyUI models directory. ```bash cd ComfyUI wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors wget -O models/checkpoints/svd_xt_1_1.safetensors https://huggingface.co/vdo/stable-video-diffusion-img2vid-xt-1-1/resolve/main/svd_xt_1_1.safetensors ``` -------------------------------- ### Quantize Custom Models Source: https://github.com/siliconflow/onediff/blob/main/src/onediff/quantization/README.md Runs the test script to verify and perform quantization on custom models. ```bash python tests/test_quantize_custom_model.py ``` -------------------------------- ### Download SD 2.1 Checkpoint Model Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Use wget to download the SD 2.1 safetensors file (after unzipping the provided zip) and place it in the ComfyUI checkpoints directory. ```bash wget https://huggingface.co/siliconflow/stable-diffusion-v2-1-onediff-comfy-enterprise/blob/main/v2-1_768-ema-pruned.zip -O ComfyUI/models/checkpoints/v2-1_768-ema-pruned.zip ``` -------------------------------- ### Perform inference using native SDXL Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/docs/onediffx_lora_examples.ipynb Initializes and compiles an SDXL pipeline for inference. Ensure the model path is correct and the environment is set up for CUDA. ```python import torch from diffusers import DiffusionPipeline from onediffx import compile_pipe from onediffx.lora import load_and_fuse_lora, set_and_fuse_adapters, delete_adapters, unfuse_lora, load_lora_and_optionally_fuse MODEL_ID = "/share_nfs/hf_models/stable-diffusion-xl-base-1.0" pipe = DiffusionPipeline.from_pretrained(MODEL_ID, variant="fp16", torch_dtype=torch.float16).to("cuda") pipe = compile_pipe(pipe) images_fusion = pipe( "a cat", height=1024, width=1024, generator=torch.manual_seed(0), num_inference_steps=30, ).images[0] display(images_fusion.resize((512, 512))) ``` -------------------------------- ### Accelerate SD3.5 Text-to-Image with Quantization and T5 Speedup Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd35/README.md This command accelerates SD3.5 text-to-image generation, quantizing the T5 model for reduced memory usage on GPUs like the RTX 4090 with limited VRAM. The `--speedup-t5` flag is crucial for memory-constrained environments. ```bash NEXFORT_FORCE_QUANTE_ON_CUDA=1 python3 onediff_diffusers_extensions/examples/sd35/text_to_image_sd35.py \ --quantize \ --transform \ --speedup-t5 \ --saved-image sd35_compile.png ``` -------------------------------- ### Download SDXL Quantization Info for ComfyUI Source: https://github.com/siliconflow/onediff/blob/main/README_ENTERPRISE.md Use this command to download the SDXL quantization info file and place it in the ComfyUI models onediff_quant directory. ```bash wget https://huggingface.co/siliconflow/sdxl-base-1.0-onediff-comfy-enterprise-v1/resolve/main/sd_xl_base_1.0_quantize_info.pt -O ComfyUI/models/onediff_quant/sd_xl_base_1.0_quantize_info.pt ``` -------------------------------- ### Check OneFlow Doctor Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/OnlineQuantization.md Run this command to check your OneFlow installation details, including version and Git commit. ```bash python -m oneflow --doctor ``` -------------------------------- ### Run Text-to-Image Benchmark with Quantization Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/pixart/README.md Executes the text-to-image benchmark script with specific Nexfort compiler configurations and quantization settings. ```bash python3 ./benchmarks/text_to_image.py \ --model PixArt-alpha/PixArt-XL-2-1024-MS \ --scheduler none \ --steps 20 \ --output-image ./pixart_alpha_fp8_90%.png \ --prompt "product photography, world of warcraft orc warrior, white background" \ --compiler nexfort \ --compiler-config '{"mode": "quant:max-optimize:max-autotune:freezing:benchmark:low-precision:cudagraphs", "memory_format": "channels_last"}' \ --quantize \ --quantize-config '{"quant_type": "fp8_e4m3_e4m3_dynamic"}' \ --quant-submodules-config-path /path/to/fp8_e4m3.json ``` -------------------------------- ### Download SDXL Base Model Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/docs/ComfyUI_Online_Quantization.md Use wget to download the SDXL base model safetensors file into the ComfyUI checkpoints directory. This is required for running SDXL workflows. ```bash cd ComfyUI wget -O models/checkpoints/sd_xl_base_1.0.safetensors https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors ``` -------------------------------- ### Register a Workflow Generator Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/benchmarks/README.md Example of using the @register_generator decorator to define a workflow generator for testing with specific image dimensions. ```python # file: onediff/onediff_comfy_nodes/benchmarks/src/input_registration.py @register_generator(f"{WORKFLOW_DIR}/example_workflow_api.json") def _(workflow_path, *args, **kwargs): with open(workflow_path, "r") as fp: workflow = json.load(fp) graph = ComfyGraph(graph=workflow, sampler_nodes=["3"]) for height in [1024, 768, 512]: for width in [1024, 768, 512]: graph.set_image_size(height=height, width=width) yield InputParams(graph=graph) ``` -------------------------------- ### Run SD1.5 Benchmark Without Compilation Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd1.5/README.md Execute the baseline text-to-image benchmark without using the compiler. ```shell python3 benchmarks/text_to_image.py \ --model runwayml/stable-diffusion-v1-5 \ --height 512 --width 512 \ --scheduler none \ --steps 20 \ --output-image ./stable-diffusion-v1-5.png \ --prompt "beautiful scenery nature glass bottle landscape, , purple galaxy bottle," \ --compiler none \ --seed 1 \ --print-output ``` -------------------------------- ### Install ComfyUI Custom Nodes Source: https://github.com/siliconflow/onediff/blob/main/onediff_comfy_nodes/modules/oneflow/hijack_comfyui_instantid/README.md Clone the ComfyUI custom nodes repository and reset to a specific commit. Ensure you are in the 'ComfyUI/custom_nodes' directory before running. ```shell cd ComfyUI/custom_nodes git clone https://github.com/comfyanonymous/ComfyUI git reset --hard 2d4164271634476627aae31fbec251ca748a0ae0 ``` -------------------------------- ### Run SD2 Baseline Benchmark Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd2/README.md Execute the text-to-image benchmark without compilation to establish a baseline. ```shell python3 benchmarks/text_to_image.py \ --model stabilityai/stable-diffusion-2-1 \ --height 768 --width 768 \ --scheduler none \ --steps 20 \ --output-image ./stable-diffusion-2-1.png \ --prompt "beautiful scenery nature glass bottle landscape, , purple galaxy bottle," \ --compiler none \ --print-output ``` -------------------------------- ### Troubleshoot CUDA Error in NexFort Compilation Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd2/README.md If you encounter a CUBLAS_STATUS_NOT_SUPPORTED error during NexFort compilation, adjust the --compiler-config by setting 'inductor.optimize_linear_epilogue' to false. This configuration is shown in the example command. ```text torch._dynamo.exc.BackendCompilerFailed: backend='nexfort' raised: ErrorFromChoice: CUDA error: CUBLAS_STATUS_NOT_SUPPORTED when calling `cublasLtMatmul( ltHandle, computeDesc.descriptor(), &alpha_val, mat1_ptr, Adesc.descriptor(), mat2_ptr, Bdesc.descriptor(), &beta_val, mat3_ptr, Ddesc.descriptor(), result_ptr, Cdesc.descriptor(), &heuristicResult.algo, workspace.data_ptr(), workspaceSize, at::cuda::getCurrentCUDAStream())` From choice ExternKernelCaller(extern_kernels.nexfort_cuda_linear_epilogue) inputs = [ torch.empty_strided((2, 10, 4096, 64), (2621440, 64, 640, 1), dtype=torch.float16, device='cuda'), torch.empty_strided((640, 640), (640, 1), dtype=torch.float16, device='cuda'), torch.empty_strided((640,), (1,), dtype=torch.float16, device='cuda'), torch.empty_strided((2, 4096, 640), (2621440, 640, 1), dtype=torch.float16, device='cuda'), ] out = torch.empty_strided((2, 4096, 640), (2621440, 640, 1), dtype=torch.float16, device='cuda') ``` -------------------------------- ### Run SD2 with NexFort Compilation Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd2/README.md Execute the text-to-image benchmark using the NexFort compiler with specific configuration options. ```shell python3 benchmarks/text_to_image.py \ --model stabilityai/stable-diffusion-2-1 \ --height 768 --width 768 \ --scheduler none \ --steps 20 \ --output-image ./stable-diffusion-2-1-compile.png \ --prompt "beautiful scenery nature glass bottle landscape, , purple galaxy bottle," \ --compiler nexfort \ --compiler-config '{"mode": "cudagraphs:benchmark:max-autotune:low-precision:cache-all", "memory_format": "channels_last", "options": {"triton.fuse_attention_allow_fp16_reduction": false, "inductor.optimize_linear_epilogue": true, "overrides.conv_benchmark": true, "overrides.matmul_allow_tf32": true}}' \ --print-output ``` -------------------------------- ### Configure Compiler Modes Source: https://github.com/siliconflow/onediff/blob/main/src/onediff/infer_compiler/README.md Define optimization strategies using the options dictionary. ```python options = {"mode": "max-optimize:max-autotune:low-precision:cache-all"} ``` ```python options = {"mode": "O3"} ``` -------------------------------- ### Test PixArt Alpha with Dynamic Shape Source: https://github.com/siliconflow/onediff/blob/main/src/onediff/infer_compiler/backends/nexfort/README.md Runs the PixArt Alpha model with the nexfort backend, enabling dynamic shape inference. This example uses a specific model and scheduler configuration, along with `max-optimize:max-autotune:low-precision` mode and `channels_last` memory format. ```bash python3 ./benchmarks/text_to_image.py \ --model PixArt-alpha/PixArt-XL-2-1024-MS \ --scheduler none \ --steps 20 \ --height 512 \ --width 768 \ --compiler nexfort \ --compiler-config '{"mode": "max-optimize:max-autotune:low-precision", "memory_format": "channels_last", "dynamic": true}' \ --run_multiple_resolutions 1 ``` -------------------------------- ### Run SDXL With NexFort Compilation Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sdxl/README.md Execute the text-to-image benchmark script for SDXL with the NexFort compiler enabled. This command includes specific compiler configurations for optimization. ```shell python3 benchmarks/text_to_image.py \ --model stabilityai/stable-diffusion-xl-base-1.0 \ --height 1024 --width 1024 \ --scheduler none \ --steps 20 \ --output-image ./stable-diffusion-xl-compile.png \ --prompt "beautiful scenery nature glass bottle landscape, , purple galaxy bottle," \ --compiler nexfort \ --compiler-config '{"mode": "benchmark:cudagraphs:max-autotune:low-precision:cache-all", "memory_format": "channels_last", "options": {"inductor.optimize_linear_epilogue": true, "overrides.conv_benchmark": true, "overrides.matmul_allow_tf32": true}}' \ --variant fp16 \ --seed 1 \ --print-output ``` -------------------------------- ### Run Text-to-Image with SD3 and Dynamic Shape Source: https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/sd3/README.md Execute the text-to-image script for Stable Diffusion 3 using OneDiff. This example utilizes a specific compiler configuration for dynamic shapes, enabling `max-optimize`, `max-autotune`, `low-precision`, and `cache-all` modes. It also specifies memory format and enables dynamic resolution. ```bash python3 onediff_diffusers_extensions/examples/sd3/text_to_image_sd3.py --compiler-config '{"mode": "max-optimize:max-autotune:low-precision:cache-all", "memory_format": "channels_last", "dynamic": true}' --height 512 --width 768 --run_multiple_resolutions 1 --saved-image sd3_compile.png ```