Skip to content

Commit ea42e5a

Browse files
authored
Merge pull request #1087 from ionite34/backport/main/pr-1086
[dev to main] backport: Add SharedFolderThing for TextEncoders in SwarmUI … (1086)
2 parents 133b637 + 4c96472 commit ea42e5a

File tree

3 files changed

+65
-38
lines changed

3 files changed

+65
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
1313
- Fixed [#1268](https://github.com/LykosAI/StabilityMatrix/issues/1268) - wrong torch index used for Nvidia 1000-series GPUs and older
1414
- Fixed [#1269](https://github.com/LykosAI/StabilityMatrix/issues/1269), [#1257](https://github.com/LykosAI/StabilityMatrix/issues/1257), [#1234](https://github.com/LykosAI/StabilityMatrix/issues/1234) - "no such file or directory" errors when updating certain packages after folder migration
1515
- Fixed [#1274](https://github.com/LykosAI/StabilityMatrix/issues/1274), [#1276](https://github.com/LykosAI/StabilityMatrix/issues/1276) - incorrect torch installed when updating to InvokeAI v5.12+
16+
- Fixed missing shared folder links for SwarmUI's diffusion_models and clip folders
1617
### Supporters
1718
#### 🌟 Visionaries
1819
Our deepest gratitude to the brilliant Visionary-tier Patrons: **Waterclouds**, **bluepopsicle**, **Bob S**, **Ibixat**, and **Corey T**! Your incredible backing is instrumental in shaping the future of Stability Matrix and empowering us to deliver cutting-edge features. Thank you for believing in our vision! 🙏

StabilityMatrix.Core/Models/Packages/Config/FdsConfigSharingStrategy.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,8 @@ ConfigSharingOptions options
9999

100100
if (normalizedPaths.Count > 0)
101101
{
102-
// FDS might store lists separated by newline or another char, or just the first path?
103-
// Assuming SwarmUI expects a single path string per key, potentially the first one.
104-
// If it supports lists (e.g., newline separated), adjust here.
105-
// For now, let's assume it takes the first path if multiple are generated,
106-
// or handles lists internally if the key implies it (needs SwarmUI knowledge).
107-
pathsSection.Set(configPath, normalizedPaths.First());
102+
// FDS lists are separated by semicolon
103+
pathsSection.Set(configPath, string.Join(';', normalizedPaths));
108104

109105
// If FDS supports lists explicitly (e.g., via SetList), use that:
110106
// pathsSection.SetList(configPath, normalizedPaths);

StabilityMatrix.Core/Models/Packages/StableSwarm.cs

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public override List<ExtraPackageCommand> GetExtraCommands() =>
6666

6767
await RebuildDotnetProject(installedPackage.FullPath, csprojName, null)
6868
.ConfigureAwait(false);
69-
}
70-
}
69+
},
70+
},
7171
];
7272

7373
public override List<LaunchOptionDefinition> LaunchOptions =>
@@ -77,46 +77,46 @@ await RebuildDotnetProject(installedPackage.FullPath, csprojName, null)
7777
Name = "Host",
7878
Type = LaunchOptionType.String,
7979
DefaultValue = "127.0.0.1",
80-
Options = ["--host"]
80+
Options = ["--host"],
8181
},
8282
new LaunchOptionDefinition
8383
{
8484
Name = "Port",
8585
Type = LaunchOptionType.String,
8686
DefaultValue = "7801",
87-
Options = ["--port"]
87+
Options = ["--port"],
8888
},
8989
new LaunchOptionDefinition
9090
{
9191
Name = "Ngrok Path",
9292
Type = LaunchOptionType.String,
93-
Options = ["--ngrok-path"]
93+
Options = ["--ngrok-path"],
9494
},
9595
new LaunchOptionDefinition
9696
{
9797
Name = "Ngrok Basic Auth",
9898
Type = LaunchOptionType.String,
99-
Options = ["--ngrok-basic-auth"]
99+
Options = ["--ngrok-basic-auth"],
100100
},
101101
new LaunchOptionDefinition
102102
{
103103
Name = "Cloudflared Path",
104104
Type = LaunchOptionType.String,
105-
Options = ["--cloudflared-path"]
105+
Options = ["--cloudflared-path"],
106106
},
107107
new LaunchOptionDefinition
108108
{
109109
Name = "Proxy Region",
110110
Type = LaunchOptionType.String,
111-
Options = ["--proxy-region"]
111+
Options = ["--proxy-region"],
112112
},
113113
new LaunchOptionDefinition
114114
{
115115
Name = "Launch Mode",
116116
Type = LaunchOptionType.Bool,
117-
Options = ["--launch-mode web", "--launch-mode webinstall"]
117+
Options = ["--launch-mode web", "--launch-mode webinstall"],
118118
},
119-
LaunchOptionDefinition.Extras
119+
LaunchOptionDefinition.Extras,
120120
];
121121

122122
public override SharedFolderLayout SharedFolderLayout =>
@@ -126,44 +126,50 @@ await RebuildDotnetProject(installedPackage.FullPath, csprojName, null)
126126
ConfigFileType = ConfigFileType.Fds,
127127
Rules =
128128
[
129-
new SharedFolderLayoutRule { IsRoot = true, ConfigDocumentPaths = ["ModelRoot"], },
129+
new SharedFolderLayoutRule { IsRoot = true, ConfigDocumentPaths = ["ModelRoot"] },
130130
new SharedFolderLayoutRule
131131
{
132132
SourceTypes = [SharedFolderType.StableDiffusion],
133133
TargetRelativePaths = ["Models/Stable-Diffusion"],
134-
ConfigDocumentPaths = ["SDModelFolder"]
134+
ConfigDocumentPaths = ["SDModelFolder"],
135135
},
136136
new SharedFolderLayoutRule
137137
{
138138
SourceTypes = [SharedFolderType.Lora, SharedFolderType.LyCORIS],
139139
TargetRelativePaths = ["Models/Lora"],
140-
ConfigDocumentPaths = ["SDLoraFolder"]
140+
ConfigDocumentPaths = ["SDLoraFolder"],
141141
},
142142
new SharedFolderLayoutRule
143143
{
144144
SourceTypes = [SharedFolderType.VAE],
145145
TargetRelativePaths = ["Models/VAE"],
146-
ConfigDocumentPaths = ["SDVAEFolder"]
146+
ConfigDocumentPaths = ["SDVAEFolder"],
147147
},
148148
new SharedFolderLayoutRule
149149
{
150150
SourceTypes = [SharedFolderType.Embeddings],
151151
TargetRelativePaths = ["Models/Embeddings"],
152-
ConfigDocumentPaths = ["SDEmbeddingFolder"]
152+
ConfigDocumentPaths = ["SDEmbeddingFolder"],
153153
},
154154
new SharedFolderLayoutRule
155155
{
156156
SourceTypes = [SharedFolderType.ControlNet, SharedFolderType.T2IAdapter],
157157
TargetRelativePaths = ["Models/controlnet"],
158-
ConfigDocumentPaths = ["SDControlNetsFolder"]
158+
ConfigDocumentPaths = ["SDControlNetsFolder"],
159159
}, // Assuming Swarm maps T2I to ControlNet folder
160160
new SharedFolderLayoutRule
161161
{
162162
SourceTypes = [SharedFolderType.ClipVision],
163163
TargetRelativePaths = ["Models/clip_vision"],
164-
ConfigDocumentPaths = ["SDClipVisionFolder"]
164+
ConfigDocumentPaths = ["SDClipVisionFolder"],
165+
},
166+
new SharedFolderLayoutRule
167+
{
168+
SourceTypes = [SharedFolderType.TextEncoders],
169+
TargetRelativePaths = ["Models/clip"],
170+
ConfigDocumentPaths = ["SDClipFolder"],
165171
},
166-
]
172+
],
167173
};
168174

169175
public override Dictionary<SharedOutputType, IReadOnlyList<string>> SharedOutputFolders =>
@@ -178,7 +184,7 @@ await RebuildDotnetProject(installedPackage.FullPath, csprojName, null)
178184
PackagePrerequisite.Git,
179185
PackagePrerequisite.Dotnet,
180186
PackagePrerequisite.Python310,
181-
PackagePrerequisite.VcRedist
187+
PackagePrerequisite.VcRedist,
182188
];
183189

184190
private FilePath GetSettingsPath(string installLocation) =>
@@ -198,8 +204,8 @@ public override async Task InstallPackage(
198204
{
199205
progress?.Report(new ProgressReport(-1f, "Installing SwarmUI...", isIndeterminate: true));
200206

201-
var comfy = settingsManager.Settings.InstalledPackages.FirstOrDefault(
202-
x => x.PackageName is nameof(ComfyUI) or "ComfyUI-Zluda"
207+
var comfy = settingsManager.Settings.InstalledPackages.FirstOrDefault(x =>
208+
x.PackageName is nameof(ComfyUI) or "ComfyUI-Zluda"
203209
);
204210

205211
if (comfy == null)
@@ -217,7 +223,7 @@ await prerequisiteHelper
217223
"source",
218224
"https://api.nuget.org/v3/index.json",
219225
"--name",
220-
"\"NuGet official package source\""
226+
"\"NuGet official package source\"",
221227
],
222228
workingDirectory: installLocation,
223229
onProcessOutput: onConsoleOutput
@@ -277,7 +283,7 @@ await prerequisiteHelper
277283
SDClipVisionFolder = Path.Combine(
278284
settingsManager.ModelsDirectory,
279285
SharedFolderType.ClipVision.ToString()
280-
)
286+
),
281287
};
282288
}
283289

@@ -315,9 +321,9 @@ await prerequisiteHelper
315321
// Create a wrapper batch file that runs zluda.exe
316322
var wrapperScriptPath = Path.Combine(installLocation, "Data", "zluda_wrapper.bat");
317323
var scriptContent = $"""
318-
@echo off
319-
"{zludaPath}" {args}
320-
""";
324+
@echo off
325+
"{zludaPath}" {args}
326+
""";
321327

322328
// Ensure the Data directory exists
323329
Directory.CreateDirectory(Path.Combine(installLocation, "Data"));
@@ -334,7 +340,7 @@ await File.WriteAllTextAsync(wrapperScriptPath, scriptContent, cancellationToken
334340
DisableInternalArgs = false,
335341
AutoUpdate = false,
336342
UpdateManagedNodes = "true",
337-
ExtraArgs = string.Empty // Arguments are already in the batch file
343+
ExtraArgs = string.Empty, // Arguments are already in the batch file
338344
}.Save(true)
339345
);
340346
}
@@ -348,7 +354,7 @@ await File.WriteAllTextAsync(wrapperScriptPath, scriptContent, cancellationToken
348354
DisableInternalArgs = false,
349355
AutoUpdate = false,
350356
UpdateManagedNodes = "true",
351-
ExtraArgs = comfyArgs
357+
ExtraArgs = comfyArgs,
352358
}.Save(true)
353359
);
354360
}
@@ -371,7 +377,7 @@ public override async Task RunPackage(
371377
{
372378
["ASPNETCORE_ENVIRONMENT"] = "Production",
373379
["ASPNETCORE_URLS"] = "http://*:7801",
374-
["GIT"] = portableGitBin.JoinFile("git.exe")
380+
["GIT"] = portableGitBin.JoinFile("git.exe"),
375381
};
376382
aspEnvVars.Update(settingsManager.Settings.EnvironmentVariables);
377383

@@ -400,6 +406,30 @@ void HandleConsoleOutput(ProcessOutput s)
400406
}
401407
}
402408

409+
var sharedDiffusionModelsPath = new DirectoryPath(
410+
settingsManager.ModelsDirectory,
411+
nameof(SharedFolderType.DiffusionModels)
412+
);
413+
var swarmDiffusionModelsPath = new DirectoryPath(settingsManager.ModelsDirectory, "diffusion_models");
414+
415+
try
416+
{
417+
swarmDiffusionModelsPath.Create();
418+
await Helper
419+
.SharedFolders.CreateOrUpdateLink(sharedDiffusionModelsPath, swarmDiffusionModelsPath)
420+
.ConfigureAwait(false);
421+
}
422+
catch (Exception e)
423+
{
424+
onConsoleOutput?.Invoke(
425+
new ProcessOutput
426+
{
427+
Text =
428+
$"Failed to create symlink for {nameof(SharedFolderType.DiffusionModels)}: {e.Message}.",
429+
}
430+
);
431+
}
432+
403433
var releaseFolder = Path.Combine(installLocation, "src", "bin", "live_release");
404434
var dllName = "StableSwarmUI.dll";
405435
if (File.Exists(Path.Combine(releaseFolder, "SwarmUI.dll")))
@@ -409,7 +439,7 @@ void HandleConsoleOutput(ProcessOutput s)
409439

410440
dotnetProcess = await prerequisiteHelper
411441
.RunDotnet(
412-
args: [Path.Combine(releaseFolder, dllName), ..options.Arguments],
442+
args: [Path.Combine(releaseFolder, dllName), .. options.Arguments],
413443
workingDirectory: installLocation,
414444
envVars: aspEnvVars,
415445
onProcessOutput: HandleConsoleOutput,
@@ -509,7 +539,7 @@ await prerequisiteHelper
509539
"--configuration",
510540
"Release",
511541
"-o",
512-
"src/bin/live_release"
542+
"src/bin/live_release",
513543
],
514544
workingDirectory: installLocation,
515545
onProcessOutput: onConsoleOutput
@@ -576,7 +606,7 @@ private Task SetupModelFoldersConfig(DirectoryPath installDirectory)
576606
SDClipVisionFolder = Path.Combine(
577607
settingsManager.ModelsDirectory,
578608
SharedFolderType.ClipVision.ToString()
579-
)
609+
),
580610
};
581611

582612
existingSettings.Save(true).SaveToFile(settingsPath);

0 commit comments

Comments
 (0)