uv improvements

This commit is contained in:
CyrixJD115 2026-06-02 23:02:20 -07:00 committed by GitHub
parent e5dc54a3f9
commit 1344b6927b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 8 deletions

1
.gitignore vendored
View File

@ -9,6 +9,7 @@ __pycache__
*.sft
.DS_Store
.vscode
/.uv-cache
/cache
/config.json
/config_states/

View File

@ -89,7 +89,7 @@ The name "Forge" is inspired by "Minecraft Forge". This project aims to become t
<br>
- [X] Rewrite Preset System
- now remembers the checkpoint/module selection and parameters for each preset
- now save the checkpoint/module selection and parameters per each Preset
> [!Note]
> This overrides the `UI Defaults` for the controlled parameters
@ -101,7 +101,7 @@ The name "Forge" is inspired by "Minecraft Forge". This project aims to become t
- adjust in **Settings/System**
- [X] Support [uv](https://github.com/astral-sh/uv) package manager
- drastically speed up installation
- requires **manually** installing [uv](https://github.com/astral-sh/uv/releases)
- require **manually** installing [uv](https://github.com/astral-sh/uv/releases)
- see [Commandline](#by-neo)
- [X] Support [SageAttention](https://github.com/thu-ml/SageAttention), [FlashAttention](https://github.com/Dao-AILab/flash-attention), `fp16_accumulation`, `torch._scaled_mm`
- see [Commandline](#by-neo)
@ -110,7 +110,7 @@ The name "Forge" is inspired by "Minecraft Forge". This project aims to become t
- enable by selecting `int8` in the `Diffusion in Low Bits`
- [X] Implement [Radial Attention](https://github.com/mit-han-lab/radial-attention)
- speed up `Wan 2.2`
- requires **manually** installing [SpargeAttn](https://github.com/thu-ml/SpargeAttn)
- require **manually** installing [SpargeAttn](https://github.com/thu-ml/SpargeAttn)
- [X] Implement fast `state_dict` switching for Refiner
- enable in **Settings/Refiner**
- [X] Implement RescaleCFG
@ -264,12 +264,17 @@ The name "Forge" is inspired by "Minecraft Forge". This project aims to become t
<br>
- `--uv`: Replace the `python -m pip` calls with `uv pip` to massively speed up package installation
- requires **uv** to be installed first *(see [Installation](#installation))*
- requires **uv** to be installed first *(see [Extra Installations](https://github.com/Haoming02/sd-webui-forge-classic/wiki/Extra-Installations))*
- `--uv-symlink`: Same as above; but additionally pass `--link-mode symlink` to the commands
- significantly reduces installation size (`~7 GB` to `~100 MB`)
- `--uv-local-cache`: Same as above; but additionally set `UV_CACHE_DIR` to a `.uv-cache` folder within WebUI directory
- speed up installation on non-default drive *(**i.e.** not `C:` on Windows)*
- allow clean uninstallation by simply deleting the WebUI directory
> [!Important]
> Using `symlink` means it will directly access the packages from the cache folders; refrain from clearing the cache if using this option
> `symlink` means it will directly access the packages from the cache folder instead of copying the packages over ; refrain from clearing the cache when using this option
<br>
- `--model-ref`: Points to a central `models` folder that contains all your models
- said folder should contain subfolders like `Stable-diffusion`, `Lora`, `VAE`, `ESRGAN`, etc.
@ -277,6 +282,8 @@ The name "Forge" is inspired by "Minecraft Forge". This project aims to become t
> [!Important]
> This simply **replaces** the `models` folder rather than adding on top of it
<br>
- `--forge-ref-a1111-home`: Point to an Automatic1111 installation to load its `models` folders
- **i.e.** `Stable-diffusion`, `text_encoder`, etc.

View File

@ -6,9 +6,10 @@ git = launch_utils.git
index_url = launch_utils.index_url
dir_repos = launch_utils.dir_repos
if args.uv or args.uv_symlink:
if args.uv or args.uv_symlink or args.uv_local_cache:
from modules_forge.uv_hook import patch
patch(args.uv_symlink)
patch(not args.uv, args.uv_local_cache)
git_tag = launch_utils.git_tag

View File

@ -101,6 +101,7 @@ parser.add_argument("--adv-samplers", action="store_true", help='show the "sampl
pkm = parser.add_mutually_exclusive_group()
pkm.add_argument("--uv", action="store_true", help="Use the uv package manager")
pkm.add_argument("--uv-symlink", action="store_true", help="Use the uv package manager with symlink")
pkm.add_argument("--uv-local-cache", action="store_true", help="Use the uv package manager with a local cache (.uv-cache) instead of the system-wide cache")
parser = _parser
paths_internal.parser = parser

View File

@ -4,10 +4,42 @@ from copy import copy
from functools import wraps
def patch(symlink: bool):
def _pre_check():
try:
subprocess.run(["uv", "--help"], capture_output=True)
except FileNotFoundError:
print("\n[Error] uv is not installed...")
except Exception:
print("\n[Error] Failed to access uv...")
else:
return
input("Press Enter to Continue...")
raise SystemExit
def _set_cache():
import os
webui = os.path.dirname(os.path.dirname(__file__))
cache = os.path.normpath(os.path.join(webui, ".uv-cache"))
if not os.path.exists(cache):
print("[uv] Creating .uv-cache folder...")
os.makedirs(cache)
os.environ.setdefault("UV_CACHE_DIR", cache)
def patch(symlink: bool, local: bool):
if hasattr(subprocess, "__original_run"):
return
_pre_check()
if local:
_set_cache()
subprocess.__original_run = subprocess.run
BAD_FLAGS = ("--prefer-binary", "--ignore-installed", "-I")