Skip to content

Commit 133b637

Browse files
authored
Merge pull request LykosAI#1085 from ionite34/fix-invoke
Fix invoke
2 parents ea86cbd + bd4a5d5 commit 133b637

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
1212
- Fixed [#1266](https://github.com/LykosAI/StabilityMatrix/issues/1266) - crash when moving or deleting Lora models in the Checkpoint Manager
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
15+
- 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+
1516
### Supporters
1617
#### 🌟 Visionaries
1718
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/InvokeAI.cs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using StabilityMatrix.Core.Extensions;
99
using StabilityMatrix.Core.Helper;
1010
using StabilityMatrix.Core.Helper.Cache;
11+
using StabilityMatrix.Core.Helper.HardwareInfo;
1112
using StabilityMatrix.Core.Models.Api.Invoke;
1213
using StabilityMatrix.Core.Models.FileInterfaces;
1314
using StabilityMatrix.Core.Models.Progress;
@@ -63,14 +64,14 @@ IPrerequisiteHelper prerequisiteHelper
6364
[SharedFolderType.ControlNet] = [Path.Combine(RelativeRootPath, "autoimport", "controlnet")],
6465
[SharedFolderType.IpAdapters15] =
6566
[
66-
Path.Combine(RelativeRootPath, "models", "sd-1", "ip_adapter")
67+
Path.Combine(RelativeRootPath, "models", "sd-1", "ip_adapter"),
6768
],
6869
[SharedFolderType.IpAdaptersXl] =
6970
[
70-
Path.Combine(RelativeRootPath, "models", "sdxl", "ip_adapter")
71+
Path.Combine(RelativeRootPath, "models", "sdxl", "ip_adapter"),
7172
],
7273
[SharedFolderType.ClipVision] = [Path.Combine(RelativeRootPath, "models", "any", "clip_vision")],
73-
[SharedFolderType.T2IAdapter] = [Path.Combine(RelativeRootPath, "autoimport", "t2i_adapter")]
74+
[SharedFolderType.T2IAdapter] = [Path.Combine(RelativeRootPath, "autoimport", "t2i_adapter")],
7475
};
7576

7677
public override Dictionary<SharedOutputType, IReadOnlyList<string>>? SharedOutputFolders =>
@@ -85,15 +86,15 @@ IPrerequisiteHelper prerequisiteHelper
8586
{
8687
Name = "Root Directory",
8788
Type = LaunchOptionType.String,
88-
Options = ["--root"]
89+
Options = ["--root"],
8990
},
9091
new()
9192
{
9293
Name = "Config File",
9394
Type = LaunchOptionType.String,
94-
Options = ["--config"]
95+
Options = ["--config"],
9596
},
96-
LaunchOptionDefinition.Extras
97+
LaunchOptionDefinition.Extras,
9798
];
9899

99100
public override IEnumerable<TorchIndex> AvailableTorchIndices =>
@@ -114,7 +115,7 @@ public override TorchIndex GetRecommendedTorchVersion()
114115
PackagePrerequisite.Python310,
115116
PackagePrerequisite.VcRedist,
116117
PackagePrerequisite.Git,
117-
PackagePrerequisite.Node
118+
PackagePrerequisite.Node,
118119
];
119120

120121
public override async Task InstallPackage(
@@ -148,20 +149,29 @@ await SetupAndBuildInvokeFrontend(
148149
var pipCommandArgs = "-e . --use-pep517 --extra-index-url https://download.pytorch.org/whl/cpu";
149150

150151
var torchVersion = options.PythonOptions.TorchIndex ?? GetRecommendedTorchVersion();
152+
var isLegacyNvidiaGpu =
153+
torchVersion is TorchIndex.Cuda
154+
&& (
155+
SettingsManager.Settings.PreferredGpu?.IsLegacyNvidiaGpu()
156+
?? HardwareHelper.HasLegacyNvidiaGpu()
157+
);
158+
151159
var torchInstallArgs = new PipInstallArgs();
152160

153161
switch (torchVersion)
154162
{
155163
case TorchIndex.Cuda:
164+
var torchIndex = isLegacyNvidiaGpu ? "cu126" : "cu128";
156165
torchInstallArgs = torchInstallArgs
157-
.WithTorch("==2.4.1")
158-
.WithTorchVision("==0.19.1")
159-
.WithXFormers("==0.0.28.post1")
160-
.WithTorchExtraIndex("cu124");
166+
.WithTorch("==2.7.0")
167+
.WithTorchVision("==0.22.0")
168+
.WithTorchAudio("==2.7.0")
169+
.WithXFormers("==0.0.30")
170+
.WithTorchExtraIndex(torchIndex);
161171

162172
Logger.Info("Starting InvokeAI install (CUDA)...");
163173
pipCommandArgs =
164-
"-e .[xformers] --use-pep517 --extra-index-url https://download.pytorch.org/whl/cu124";
174+
$"-e .[xformers] --use-pep517 --extra-index-url https://download.pytorch.org/whl/{torchIndex}";
165175
break;
166176

167177
case TorchIndex.Rocm:
@@ -321,10 +331,10 @@ await SetupAndBuildInvokeFrontend(
321331
// above the minimum in invokeai.frontend.install.widgets
322332

323333
var code = $"""
324-
import sys
325-
from {split[0]} import {split[1]}
326-
sys.exit({split[1]}())
327-
""";
334+
import sys
335+
from {split[0]} import {split[1]}
336+
sys.exit({split[1]}())
337+
""";
328338

329339
if (runDetached)
330340
{
@@ -383,9 +393,15 @@ await SetupInvokeModelSharingConfig(onConsoleOutput, match, s)
383393
}
384394

385395
// Invoke doing shared folders on startup instead
386-
public override Task SetupModelFolders(DirectoryPath installDirectory, SharedFolderMethod sharedFolderMethod) => Task.CompletedTask;
396+
public override Task SetupModelFolders(
397+
DirectoryPath installDirectory,
398+
SharedFolderMethod sharedFolderMethod
399+
) => Task.CompletedTask;
387400

388-
public override Task RemoveModelFolderLinks(DirectoryPath installDirectory, SharedFolderMethod sharedFolderMethod) => Task.CompletedTask;
401+
public override Task RemoveModelFolderLinks(
402+
DirectoryPath installDirectory,
403+
SharedFolderMethod sharedFolderMethod
404+
) => Task.CompletedTask;
389405

390406
private async Task<bool> SetupInvokeModelSharingConfig(
391407
Action<ProcessOutput>? onConsoleOutput,
@@ -405,7 +421,7 @@ ProcessOutput s
405421
{
406422
ContentSerializer = new SystemTextJsonContentSerializer(
407423
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }
408-
)
424+
),
409425
}
410426
);
411427

@@ -422,7 +438,7 @@ await invokeAiApi
422438
new InstallModelRequest
423439
{
424440
Name = Path.GetFileNameWithoutExtension(model.Path),
425-
Description = Path.GetFileName(model.Path)
441+
Description = Path.GetFileName(model.Path),
426442
},
427443
source: model.Path,
428444
inplace: true
@@ -435,10 +451,9 @@ await invokeAiApi
435451
var installCheckCount = 0;
436452

437453
while (
438-
!installStatus.All(
439-
x =>
440-
(x.Status != null && x.Status.Equals("completed", StringComparison.OrdinalIgnoreCase))
441-
|| (x.Status != null && x.Status.Equals("error", StringComparison.OrdinalIgnoreCase))
454+
!installStatus.All(x =>
455+
(x.Status != null && x.Status.Equals("completed", StringComparison.OrdinalIgnoreCase))
456+
|| (x.Status != null && x.Status.Equals("error", StringComparison.OrdinalIgnoreCase))
442457
)
443458
)
444459
{
@@ -449,7 +464,7 @@ await invokeAiApi
449464
new ProcessOutput
450465
{
451466
Text =
452-
"This may take awhile, feel free to use the web interface while the rest of your models are imported.\n"
467+
"This may take awhile, feel free to use the web interface while the rest of your models are imported.\n",
453468
}
454469
);
455470

@@ -466,7 +481,7 @@ await invokeAiApi
466481
{
467482
Text =
468483
$"\nWaiting for model import... ({installStatus.Count(x => (x.Status != null && !x.Status.Equals("completed",
469-
StringComparison.OrdinalIgnoreCase)) && !x.Status.Equals("error", StringComparison.OrdinalIgnoreCase))} remaining)\n"
484+
StringComparison.OrdinalIgnoreCase)) && !x.Status.Equals("error", StringComparison.OrdinalIgnoreCase))} remaining)\n",
470485
}
471486
);
472487
await Task.Delay(5000).ConfigureAwait(false);

0 commit comments

Comments
 (0)