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

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 #16502

Open
1 of 6 tasks
huangjianyi0701 opened this issue Sep 19, 2024 · 9 comments
Labels
asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance

Comments

@huangjianyi0701
Copy link

Checklist

  • The issue exists after disabling all extensions
  • The issue exists on a clean installation of webui
  • The issue is caused by an extension, but I believe it is caused by a bug in the webui
  • The issue exists in the current version of the webui
  • The issue has not been reported before recently
  • The issue has been reported before but has not been fixed yet

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

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

Additional information

No response

@huangjianyi0701 huangjianyi0701 added the bug-report Report of a bug, yet to be confirmed label Sep 19, 2024
@missionfloyd
Copy link
Collaborator

--ckpt-dir

@missionfloyd missionfloyd added asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance and removed bug-report Report of a bug, yet to be confirmed labels Sep 20, 2024
@Woisek
Copy link

Woisek commented Sep 21, 2024

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.

@skyliwq
Copy link

skyliwq commented Sep 25, 2024

Two webui using the same model will load the model into memory twice.

@richrobber2
Copy link

richrobber2 commented Oct 5, 2024

--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)

1. Junction (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.

Steps and Reasons:

  1. Open Command Prompt as Administrator:

    • Reason: Creating junctions requires administrative privileges because you are modifying the file system at a low level. Running Command Prompt as an administrator ensures you have the necessary permissions.
  2. Create the Junction Link:

    • Command Format:
      mklink /J "target_directory_path" "source_directory_path"
      
    • Example:
      mklink /J "C:\webui_1\models" "D:\shared_models"
      
    • Reasons:
      • 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.
      • Scenario: Use this when you want both webui instances to point to the same directory but both must be on the same drive (e.g., both on C:). Junctions are great when you need maximum compatibility with applications that expect a physical directory rather than a symbolic reference.

2. Symbolic Link for a Directory (mklink /D)

Symbolic links are more flexible than junctions as they can be used across different drives and can link both files and directories.

Steps and Reasons:

  1. Open Command Prompt as Administrator:

    • Reason: Creating symbolic links also requires administrative privileges since it involves modifying system-level file paths.
  2. Create the Symbolic Link for the Directory:

    • Command Format:
      mklink /D "target_directory_path" "source_directory_path"
      
    • Example:
      mklink /D "C:\webui_2\models" "E:\shared_models"
      
    • Reasons:
      • 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.
      • Scenario: Use this if your webui installations are on different drives. A symbolic link is versatile for cases where your storage might be distributed across multiple volumes (e.g., C: and E:). It provides flexibility without being constrained by drive limits.

3. Hard Link for a File (mklink /H)

Hard links are suitable for pointing to the same individual file in multiple locations without duplicating data.

Steps and Reasons:

  1. Open Command Prompt as Administrator:

    • Reason: Hard linking also modifies file system records, which needs administrator-level privileges.
  2. Create the Hard Link:

    • Command Format:
      mklink /H "target_file_path" "source_file_path"
      
    • Example:
      mklink /H "C:\webui_1\models\model.ckpt" "D:\shared_models\model.ckpt"
      
    • Reasons:
      • 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.
      • Scenario: Use a hard link when you need to link a specific file rather than a full directory, especially if you have a single model file that is shared between two projects. Hard links allow multiple references to the same data on disk, which saves space but can only be used on the same drive.

4. Directory Hard Link (Windows 10+)

This is an alternative similar to a junction for linking directories, but integrates more directly with the file system.

Steps and Reasons:

  1. Open Command Prompt as Administrator:

    • Reason: Directory hard links modify the file system and require administrative access to make changes.
  2. Create the Directory Hard Link using PowerShell:

    • PowerShell Command:
      New-Item -ItemType HardLink -Path "C:\webui_1\models" -Target "D:\shared_models"
    • Reasons:
      • 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.
      • Scenario: Use this method if you prefer PowerShell for scripting or want an alternative way to create hard links without using Command Prompt. It works on Windows 10+ and may be more user-friendly for those who prefer the PowerShell environment.

Summary of When to Use Each:

  • Junction (/J):

    • Best for directories on the same drive.
    • Simple and effective, looks like a regular folder to applications.
  • Symbolic Link (/D):

    • Best for directories that may be on different drives.
    • More versatile than junctions and can link files or directories across volumes.
  • Hard Link (/H):

    • Best for individual files.
    • Creates multiple references to a single file, saving space but restricted to the same drive.
  • Directory Hard Link (PowerShell):

    • Similar to junctions but with more direct file system integration.
    • Good for directories on the same volume and for users who prefer PowerShell.

@richrobber2
Copy link

1. Symbolic Link (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.

Steps and Reasons:

  1. Open Terminal:

    • You can use the Terminal application to create links. Ensure you have the necessary permissions to modify the directories.
  2. Create the Symbolic Link:

    • Command Format:
      ln -s source_path target_path
    • Example:
      ln -s /mnt/shared_models /home/user/webui_1/models
    • Reasons:
      • 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).
      • Scenario: Use a symbolic link if the original files and the linked path are on different drives or file systems. This is the most versatile and commonly used type of link for directories or files in Linux.
  3. Explanation:

    • A symbolic link behaves like a pointer to the 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.

2. Hard Link (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.

Steps and Reasons:

  1. Open Terminal:

    • Similar to creating a symbolic link, you need to use the terminal.
  2. Create the Hard Link:

    • Command Format:
      ln source_file target_file
    • Example:
      ln /home/user/shared_models/model.ckpt /home/user/webui_1/models/model.ckpt
    • Reasons:
      • 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).
      • Scenario: Use a hard link if you need two paths to refer to the same file on the same filesystem. Hard links are useful if you want redundancy without duplicating the content.
  3. Explanation:

    • Hard links allow two different filenames to reference the same data on disk. If one is modified, the other will reflect those changes since both point to the same physical file.

3. Bind Mount (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.

Steps and Reasons:

  1. Open Terminal with Root Permissions:

    • Reason: Bind mounts require root privileges, so use sudo.
  2. Create the Bind Mount:

    • Command Format:
      sudo mount --bind source_directory target_directory
    • Example:
      sudo mount --bind /mnt/shared_models /home/user/webui_1/models
    • Reasons:
      • 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).
      • Scenario: Use a bind mount if you need a dynamic mount for a directory without creating a symlink. Bind mounts are particularly useful for virtualized environments or if you want to make a directory appear at multiple locations with the exact same content.
  3. Persisting Bind Mounts:

    • To make the bind mount persistent across reboots, add it to /etc/fstab:
      /mnt/shared_models /home/user/webui_1/models none bind 0 0
      
    • Reason: By adding the bind mount to /etc/fstab, you ensure it will be re-mounted after a system reboot.

Summary of When to Use Each:

  • Symbolic Link (ln -s):

    • Best for: Linking files or directories, across different drives or filesystems.
    • Reasons: It's versatile, supports linking across filesystems, and is easy to set up.
  • Hard Link (ln):

    • Best for: Linking individual files on the same filesystem.
    • Reasons: It allows multiple references to a file, saving space. Any change to the file will be reflected across all links, but it’s restricted to the same filesystem.
  • Bind Mount (mount --bind):

    • Best for: Creating a shared mount point for directories, with additional control over mounts, useful in system-level or virtualized environments.
    • Reasons: It provides a flexible way to share directories with the exact same content without creating symbolic references. It’s powerful for setting up chroot environments or managing filesystem mounts dynamically.

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.

@huangjianyi0701
Copy link
Author

启动选项中的 --ckpt-dir

^ 将是最简单的 ^ 但这里有一些其他选项供您选择

编辑:我的评论得到了 chatgpt 的帮助,但据我所知,它的信息是正确的,(虽然我个人只使用了)mklink /D

1. 连接点 ()

联结会创建指向同一驱动器上整个目录的链接,这非常适合在不复制内容的情况下共享文件夹。

步骤和原因:

  1. 以管理员身份打开命令提示符:

    • **原因:**创建联结需要管理权限,因为您正在低级别修改文件系统。以管理员身份运行命令提示符可确保您拥有必要的权限。
  2. 创建交汇点链接:

    • 命令格式:

      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. 目录的符号链接 ()

符号链接比联结更灵活,因为它们可以跨不同的驱动器使用,并且可以链接文件和目录。

步骤和原因:

  1. 以管理员身份打开命令提示符:

    • **原因:**创建符号链接还需要管理权限,因为它涉及修改系统级文件路径。
  2. 为目录创建符号链接:

    • 命令格式:

      mklink /D "target_directory_path" "source_directory_path"
      
    • 例:

      mklink /D "C:\webui_2\models" "E:\shared_models"
      
    • 原因:

      • ****:该标志指定您正在创建指向目录的符号链接。这与 junction 的不同之处在于,它支持跨不同驱动器的链接。/D
      • ****:您希望符号链接出现的位置。此文件夹将是对真实目录的引用。
      • ****:存储模型的实际目录。
      • **场景:**如果您的 webui 安装在不同的驱动器上,请使用此选项。符号链接适用于您的存储可能分布在多个卷中的情况(例如 和 )。它提供了灵活性,而不受驱动器限制。C:``E:

3. 文件的硬链接 ()

硬链接适用于指向多个位置的同一单个文件,而无需复制数据。

步骤和原因:

  1. 以管理员身份打开命令提示符:

    • **原因:**硬链接还会修改文件系统记录,这需要管理员级别的权限。
  2. 创建硬链接:

    • 命令格式:

      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 的替代方法,但更直接与文件系统集成。

步骤和原因:

  1. 以管理员身份打开命令提示符:

    • **原因:**目录硬链接会修改文件系统,并且需要管理访问权限才能进行更改。
  2. 使用 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!

@huangjianyi0701
Copy link
Author

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

@richrobber2
Copy link

richrobber2 commented Oct 7, 2024

not tested since i dont have multiple devices to test, but this should be accurate

@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.

Step 1: Create a Shared Folder on Windows

  1. Navigate to the Model Folder:

    • Go to your model folder path here in File Explorer.
  2. Set Up Sharing:

    • Right-click the folder and select "Properties."
    • Go to the "Sharing" tab and click on "Share..."
    • Choose users you want to share with or select "Everyone" for broad access. Set the permissions to "Read" or "Read/Write" based on your needs.
    • Click "Share" and take note of the network path, which will be something like:
      \\<Your-PC-Name>\Stable-diffusion
      
  3. Confirm Permissions:

    • To avoid any issues with permissions, ensure "Everyone" has at least Read access if the other devices need only to load the models.
    • Click "Apply" and then "OK" to confirm the sharing setup.

Step 2: Map the Network Drive on Other Devices

  1. Open File Explorer:

    • On the other machine(s), open "This PC" in File Explorer.
  2. Map Network Drive:

    • Click on "Map Network Drive" from the top ribbon.
    • Choose a drive letter, such as Z:.
    • In the "Folder" field, enter the network path to the shared folder from Step 1, for example:
      \\<Your-PC-Name>\Stable-diffusion
      
    • Make sure to check the "Reconnect at sign-in" option so the network drive remains mapped after rebooting.
    • Click "Finish."

Step 3: Configure Both WebUI Projects

  1. Edit the WebUI Configuration:

    • In the configuration file for both versions of your WebUI (e.g., config.json or similar), point the model directory to the mapped network drive.

    Example Configuration:

    {
      "model_dir": "Z:\\"
    }
    • Replace Z: with the drive letter you chose when mapping the network drive.
  2. Alternative - Use Launch Options:

    • If the WebUI allows it, you could also modify the launch script (e.g., webui-user.bat) to point to the shared directory directly.

    Example Command:

    webui-user.bat --ckpt-dir "Z:\\"

Step 4: Verify Access and Performance

  • Test Loading Models:

    • Launch both WebUI versions and ensure they can access and load models from the shared Z: drive.
  • Monitor Performance:

    • Since models are accessed over the network, ensure your local network has sufficient bandwidth. Ideally, both devices should be on a wired Ethernet connection or a strong Wi-Fi network to avoid loading delays.

Additional Tips:

  • Static IP Address:

    • Assign a static IP to the machine hosting the shared folder to avoid having to change the mapped drive settings if the IP changes.
  • Firewall Settings:

    • Ensure that the firewall on the host machine allows file and printer sharing. You may need to add an exception for 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.

@richrobber2
Copy link

Did the other option help? @huangjianyi0701 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asking-for-help-with-local-system-issues This issue is asking for help related to local system; please offer assistance
Projects
None yet
Development

No branches or pull requests

6 participants
@missionfloyd @richrobber2 @skyliwq @Woisek @huangjianyi0701 and others