diff --git a/onediff_sd_webui_extensions/README.md b/onediff_sd_webui_extensions/README.md index 8af4250d3..e4a0e3f3a 100644 --- a/onediff_sd_webui_extensions/README.md +++ b/onediff_sd_webui_extensions/README.md @@ -67,6 +67,33 @@ When switching models, if the new model has the same structure as the old model, > Note: The feature is not supported for quantized model. + +### Compiler cache saving and loading + +OneDiff supports saving compiler cache to disk and loading cache from disk. In scenarios where recompiling is required after switching model, you can skip the compilation process by loading the compiler cache from the disk, to saving time of model switching. + +The compiler cache will be saved at `/path/to/your/stable-diffusion-webui/extensions/onediff_sd_webui_extensions/compiler_caches/` by default. If you want to specify the path, you can modify it in webui settings. + +![Path to save compiler cache in Settings](./images/setting_dir_of_compiler_cache.png) + +#### Compiler cache saving + +After selecting onediff, a text box named `Saved cache name` will appear at the bottom right. You can input the file name of the compiler cache you want to save here. After generating the image, the compiler cache will be saved in the `stable-diffusion-webui/extensions/onediff_sd_webui_extensions/compiler_caches/your-compiler-cache-name` path. + +![Compiler caches](./images/saved_cache_name.png) + + +> Note: When the text box is empty or the file with the specified name already exists, the compiler cache will not be saved. + + +#### Compiler cache loading + +After selecting onediff, a dropdown menu named `Compile cache` will appear at the bottom left. Here, you can select the compiler cache you want to load. This dropdown menu will display all files located in the path `stable-diffusion-webui/extensions/onediff_sd_webui_extensions/compiler_caches/`. And click the button on the right side to refresh the `Compile cache` list. + +![Compiler cache loading](./images/compiler_caches.png) + +> Note: To properly use this feature, please ensure that you have added the `--disable-safe-unpickle` parameter when launching sd-webui. + ### LoRA OneDiff supports the complete functionality related to LoRA. You can use OneDiff-based LoRA just like the native LoRA in sd-webui. diff --git a/onediff_sd_webui_extensions/images/compiler_caches.png b/onediff_sd_webui_extensions/images/compiler_caches.png new file mode 100644 index 000000000..955c6a677 Binary files /dev/null and b/onediff_sd_webui_extensions/images/compiler_caches.png differ diff --git a/onediff_sd_webui_extensions/images/saved_cache_name.png b/onediff_sd_webui_extensions/images/saved_cache_name.png new file mode 100644 index 000000000..6b7ea315e Binary files /dev/null and b/onediff_sd_webui_extensions/images/saved_cache_name.png differ diff --git a/onediff_sd_webui_extensions/images/setting_dir_of_compiler_cache.png b/onediff_sd_webui_extensions/images/setting_dir_of_compiler_cache.png new file mode 100644 index 000000000..8fd199cb8 Binary files /dev/null and b/onediff_sd_webui_extensions/images/setting_dir_of_compiler_cache.png differ diff --git a/onediff_sd_webui_extensions/scripts/onediff.py b/onediff_sd_webui_extensions/scripts/onediff.py index e090c23a6..3c7e887cd 100644 --- a/onediff_sd_webui_extensions/scripts/onediff.py +++ b/onediff_sd_webui_extensions/scripts/onediff.py @@ -1,4 +1,5 @@ import os +import zipfile import warnings import gradio as gr from pathlib import Path @@ -7,7 +8,10 @@ import modules.shared as shared from modules.sd_models import select_checkpoint from modules.processing import process_images +from modules.ui_common import create_refresh_button +from modules import script_callbacks +from ui_utils import hints_message, get_all_compiler_caches, refresh_all_compiler_caches, all_compiler_caches_path from compile_ldm import compile_ldm_unet, SD21CompileCtx from compile_sgm import compile_sgm_unet from compile_vae import VaeCompileCtx @@ -15,11 +19,11 @@ from onediff_hijack import do_hijack as onediff_do_hijack from onediff.infer_compiler.utils.log_utils import logger -from onediff.infer_compiler.utils.param_utils import get_constant_folding_info from onediff.optimization.quant_optimizer import ( quantize_model, varify_can_use_quantization, ) +from onediff.infer_compiler.utils.env_var import parse_boolean_from_env from onediff import __version__ as onediff_version from oneflow import __version__ as oneflow_version @@ -113,33 +117,17 @@ def ui(self, is_img2img): The return value should be an array of all components that are used in processing. Values of those returned components will be passed to run() and process() functions. """ + with gr.Row(): + # TODO: set choices as Tuple[str, str] after the version of gradio specified webui upgrades + compiler_cache = gr.Dropdown(label="Compiler caches (Beta)", choices=["None"] + get_all_compiler_caches(), value="None", elem_id="onediff_compiler_cache") + refresh_button = create_refresh_button(compiler_cache, refresh_all_compiler_caches, lambda: {"choices": ["None"] + get_all_compiler_caches()}, "onediff_refresh_compiler_caches") + save_cache_name = gr.Textbox(label="Saved cache name (Beta)") + with gr.Row(): + always_recompile = gr.components.Checkbox(label="always_recompile", visible=parse_boolean_from_env("ONEDIFF_DEBUG")) if not varify_can_use_quantization(): - ret = gr.HTML( - """ -
- If you need Enterprise Level Support for your system or business, please send an email to
- business@siliconflow.com.
-
- Tell us about your use case, deployment scale, and requirements.
-
- GitHub Issue: - https://github.com/siliconflow/onediff/issues -
-
+ If you need Enterprise Level Support for your system or business, please send an email to
+ business@siliconflow.com.
+
+ Tell us about your use case, deployment scale, and requirements.
+
+ GitHub Issue: + https://github.com/siliconflow/onediff/issues +
+