Open huangjianyi0701 opened 2 months ago
I don't know how old such a question is, and every time it's the same: Just put all your models in a dedicated folder with subfolders and then junction it to where you need it.
Two webui using the same model will load the model into memory twice.
--ckpt-dir in the launch options
^ would be the easiest ^ but here are some other options for you
EDIT: my comments are assisted by chatgpt but its correct information as far as i know, (i have personally only used mklink /D
though)
mklink /J
)A junction creates a link to an entire directory on the same drive, which is ideal for sharing folders without duplicating the content.
Open Command Prompt as Administrator:
Create the Junction Link:
mklink /J "target_directory_path" "source_directory_path"
mklink /J "C:\webui_1\models" "D:\shared_models"
mklink /J
: The /J
flag specifies that you are creating a junction, which is essentially a shortcut to the source directory.target_directory_path
: This is where you want the linked directory to appear. It will look like a regular folder, but the content will be from source_directory_path
.source_directory_path
: This is the actual folder containing the models. C:
). Junctions are great when you need maximum compatibility with applications that expect a physical directory rather than a symbolic reference.mklink /D
)Symbolic links are more flexible than junctions as they can be used across different drives and can link both files and directories.
Open Command Prompt as Administrator:
Create the Symbolic Link for the Directory:
mklink /D "target_directory_path" "source_directory_path"
mklink /D "C:\webui_2\models" "E:\shared_models"
mklink /D
: The /D
flag specifies that you are creating a symbolic link to a directory. This is different from a junction in that it supports linking across different drives.target_directory_path
: The location where you want the symbolic link to appear. This folder will be a reference to the real directory.source_directory_path
: The actual directory where your models are stored.C:
and E:
). It provides flexibility without being constrained by drive limits.mklink /H
)Hard links are suitable for pointing to the same individual file in multiple locations without duplicating data.
Open Command Prompt as Administrator:
Create the Hard Link:
mklink /H "target_file_path" "source_file_path"
mklink /H "C:\webui_1\models\model.ckpt" "D:\shared_models\model.ckpt"
mklink /H
: The /H
flag creates a hard link, which allows you to link to an individual file rather than a directory.target_file_path
: The location where you want the linked file to be. This link will behave as if the file exists in the specified location.source_file_path
: The actual file you want to link.This is an alternative similar to a junction for linking directories, but integrates more directly with the file system.
Open Command Prompt as Administrator:
Create the Directory Hard Link using PowerShell:
New-Item -ItemType HardLink -Path "C:\webui_1\models" -Target "D:\shared_models"
New-Item -ItemType HardLink
: This creates a hard link via PowerShell, which is another way to achieve functionality similar to junctions but potentially with better integration for some modern applications.-Path
: The target path where you want the directory link to appear.-Target
: The actual directory that holds the data.Junction (/J
):
Symbolic Link (/D
):
Hard Link (/H
):
Directory Hard Link (PowerShell):
ln -s
)Symbolic links (often called symlinks) are similar to shortcuts. They can point to directories or files, and they can link across different file systems or drives.
Open Terminal:
Create the Symbolic Link:
ln -s source_path target_path
ln -s /mnt/shared_models /home/user/webui_1/models
ln -s
: The -s
flag specifies that you are creating a symbolic link. Without -s
, it would create a hard link, which is different.source_path
: This is the actual directory or file you want to share (/mnt/shared_models
).target_path
: This is where you want the symbolic link to appear (/home/user/webui_1/models
).Explanation:
source_path
. Any changes in the source are immediately visible in the link, making it great for sharing model files across projects without duplicating data.ln
)A hard link points to the same physical file on disk, effectively creating another reference to the same data. Hard links can only be used for files, not directories, and must be on the same filesystem.
Open Terminal:
Create the Hard Link:
ln source_file target_file
ln /home/user/shared_models/model.ckpt /home/user/webui_1/models/model.ckpt
ln
: Without the -s
flag, ln
creates a hard link.source_file
: The actual file you want to link (/home/user/shared_models/model.ckpt
).target_file
: The location where you want the linked file to be (/home/user/webui_1/models/model.ckpt
).Explanation:
mount --bind
) (For Directories)A bind mount is a more advanced way to "link" directories, allowing you to mount a directory in multiple locations. This is often used for more flexible sharing of directories, especially when permissions or chroot environments are involved.
Open Terminal with Root Permissions:
sudo
.Create the Bind Mount:
sudo mount --bind source_directory target_directory
sudo mount --bind /mnt/shared_models /home/user/webui_1/models
mount --bind
: The --bind
option mounts the source_directory
at the target_directory
.source_directory
: The directory you want to share (/mnt/shared_models
).target_directory
: The location where you want the directory to appear (/home/user/webui_1/models
).Persisting Bind Mounts:
/etc/fstab
:
/mnt/shared_models /home/user/webui_1/models none bind 0 0
/etc/fstab
, you ensure it will be re-mounted after a system reboot.Symbolic Link (ln -s
):
Hard Link (ln
):
Bind Mount (mount --bind
):
Each method provides a different way to share or link model files and directories across different projects or environments on Linux. Symbolic links are the most commonly used because of their flexibility, while hard links are good for files on the same disk, and bind mounts give extra power for advanced usage. Choose based on your file structure, needs, and desired control over the linked resources.
启动选项中的 --ckpt-dir
^ 将是最简单的 ^ 但这里有一些其他选项供您选择
编辑:我的评论得到了 chatgpt 的帮助,但据我所知,它的信息是正确的,(虽然我个人只使用了)
mklink /D
1. 连接点 ()
联结会创建指向同一驱动器上整个目录的链接,这非常适合在不复制内容的情况下共享文件夹。
步骤和原因:
以管理员身份打开命令提示符:
- 原因:创建联结需要管理权限,因为您正在低级别修改文件系统。以管理员身份运行命令提示符可确保您拥有必要的权限。
创建交汇点链接:
- 命令格式:
mklink /J "target_directory_path" "source_directory_path"
- 例:
mklink /J "C:\webui_1\models" "D:\shared_models"
原因:
- **:该标志指定您正在创建交汇点,该交汇**点实质上是源目录的快捷方式。
/J
- ****:这是您希望链接目录出现的位置。它看起来像一个常规文件夹,但内容将来自 .
source_directory_path
- ****:这是包含模型的实际文件夹。
- 场景:当您希望两个 webui 实例指向同一目录,但两者必须位于同一驱动器上(例如,都在 上)时,请使用此选项。当您需要与需要物理目录而不是符号引用的应用程序的最大兼容性时,Junction 非常有用。
C:
2. 目录的符号链接 ()
符号链接比联结更灵活,因为它们可以跨不同的驱动器使用,并且可以链接文件和目录。
步骤和原因:
以管理员身份打开命令提示符:
- 原因:创建符号链接还需要管理权限,因为它涉及修改系统级文件路径。
为目录创建符号链接:
- 命令格式:
mklink /D "target_directory_path" "source_directory_path"
- 例:
mklink /D "C:\webui_2\models" "E:\shared_models"
原因:
- **:该标志指定您正在创建指向目录的符号链接**。这与 junction 的不同之处在于,它支持跨不同驱动器的链接。
/D
- ****:您希望符号链接出现的位置。此文件夹将是对真实目录的引用。
- ****:存储模型的实际目录。
- 场景:如果您的 webui 安装在不同的驱动器上,请使用此选项。符号链接适用于您的存储可能分布在多个卷中的情况(例如 和 )。它提供了灵活性,而不受驱动器限制。
C:``E:
3. 文件的硬链接 ()
硬链接适用于指向多个位置的同一单个文件,而无需复制数据。
步骤和原因:
以管理员身份打开命令提示符:
- 原因:硬链接还会修改文件系统记录,这需要管理员级别的权限。
创建硬链接:
- 命令格式:
mklink /H "target_file_path" "source_file_path"
- 例:
mklink /H "C:\webui_1\models\model.ckpt" "D:\shared_models\model.ckpt"
原因:
- **:该标志会创建一个硬链接**,它允许您链接到单个文件而不是目录。
/H
- ****:您希望链接文件所在的位置。此链接的行为就像文件存在于指定位置一样。
- ****:要链接的实际文件。
- 场景:当您需要链接特定文件而不是完整目录时,请使用硬链接,尤其是在两个工程之间共享单个模型文件时。硬链接允许对磁盘上的相同数据进行多次引用,这样可以节省空间,但只能在同一个驱动器上使用。
4. 目录硬链接 (Windows 10+)
这是一种类似于链接目录的 junction 的替代方法,但更直接与文件系统集成。
步骤和原因:
以管理员身份打开命令提示符:
- 原因:目录硬链接会修改文件系统,并且需要管理访问权限才能进行更改。
使用 PowerShell 创建目录硬链接:
- PowerShell 命令:
New-Item -ItemType HardLink -Path "C:\webui_1\models" -Target "D:\shared_models"
原因:
- **:这将通过 PowerShell 创建硬链接**,这是实现类似于交汇点的功能的另一种方法,但可能会为某些现代应用程序提供更好的集成。
- ****:要显示目录链接的目标路径。
- ****:保存数据的实际目录。
- 场景:如果您更喜欢使用 PowerShell 编写脚本,或者希望使用另一种方式在不使用 Command Prompt 的情况下创建硬链接,请使用此方法。它适用于 Windows 10+,对于喜欢 PowerShell 环境的人来说可能更加用户友好。
何时使用每个摘要:
交汇点 ():
- 最适合同一驱动器上的目录。
- 简单有效,看起来像应用程序的常规文件夹。
符号链接 ():
- 最适合可能位于不同驱动器上的**目录**。
- 比联结更通用,可以跨卷链接文件或目录。
硬链接 ():
- 最适合单个文件。
- 创建对单个文件的多个引用,节省空间,但仅限于同一驱动器。
目录硬链接 (PowerShell):
- 与联结类似,但具有更直接的文件系统集成。
- 适用于同一卷上的目录以及喜欢 PowerShell 的用户。
Thank you for your answer, it's really great that it's so detailed!
I don't know how old such a question is, and every time it's the same: Just put all your models in a dedicated folder with subfolders and then junction it to where you need it.
Thanks for the answer, but mainly because I have more model files and migrate my machines more often, so your method may not be a good method
@huangjianyi0701
here is a method for windows, using the network sharing built in feature on windows
Here's how to set up a Windows Shared Folder and access it across a local network for use by two versions of WebUI, with detailed instructions for mapping and configuration.
Navigate to the Model Folder:
your model folder path here
in File Explorer.Set Up Sharing:
\\<Your-PC-Name>\Stable-diffusion
Confirm Permissions:
Open File Explorer:
Map Network Drive:
Z:
.\\<Your-PC-Name>\Stable-diffusion
Edit the WebUI Configuration:
config.json
or similar), point the model directory to the mapped network drive.Example Configuration:
{
"model_dir": "Z:\\"
}
Z:
with the drive letter you chose when mapping the network drive.Alternative - Use Launch Options:
webui-user.bat
) to point to the shared directory directly.Example Command:
webui-user.bat --ckpt-dir "Z:\\"
Test Loading Models:
Z:
drive.Monitor Performance:
Static IP Address:
Firewall Settings:
File and Printer Sharing
in the Windows Firewall settings.By following these steps, you can efficiently share your model files between multiple WebUI instances without needing to move or duplicate large files, all while keeping the setup straightforward and Windows-native.
Did the other option help? @huangjianyi0701 ?
Checklist
What happened?
Can model sharing be realized for two webui projects? I need to test the effect of different versions, now I have two versions of webui, but my model files need to be migrated a lot, is there any configuration file to support model path sharing? Like comfyui
Steps to reproduce the problem
Can model sharing be realized for two webui projects? I need to test the effect of different versions, now I have two versions of webui, but my model files need to be migrated a lot, is there any configuration file to support model path sharing? Like comfyui
What should have happened?
Can model sharing be realized for two webui projects? I need to test the effect of different versions, now I have two versions of webui, but my model files need to be migrated a lot, is there any configuration file to support model path sharing? Like comfyui
What browsers do you use to access the UI ?
Google Chrome
Sysinfo
Can model sharing be realized for two webui projects? I need to test the effect of different versions, now I have two versions of webui, but my model files need to be migrated a lot, is there any configuration file to support model path sharing? Like comfyui
Console logs
Additional information
No response