Skip to content

Commit e97d0da

Browse files
authored
Merge pull request LykosAI#1077 from ionite34/backport/main/pr-1076
[dev to main] backport: Update GpuInfo parsing to include Compute Capability for nvidia GPUs … (1076)
2 parents bbd1e0d + 96e466b commit e97d0da

File tree

9 files changed

+178
-108
lines changed

9 files changed

+178
-108
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to Stability Matrix will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).
77

8+
## v2.14.2
9+
### Changed
10+
- Changed Nvidia GPU detection to use compute capability level instead of the GPU name for certain feature gates / torch indexes
11+
### Fixed
12+
- Fixed [#1268](https://github.com/LykosAI/StabilityMatrix/issues/1268) - wrong torch index used for Nvidia 1000-series GPUs and older
13+
- 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
14+
815
## v2.14.1
916
### Changed
1017
- Updated Inference Extra Networks (Lora / LyCORIS) base model filtering to consider SDXL variations (e.g., Noob AI / Illustrious) as compatible, unrecognized models or models with no base model will be considered compatible.

StabilityMatrix.Avalonia/ViewModels/MainWindowViewModel.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using StabilityMatrix.Core.Extensions;
2525
using StabilityMatrix.Core.Helper;
2626
using StabilityMatrix.Core.Helper.Analytics;
27+
using StabilityMatrix.Core.Helper.HardwareInfo;
2728
using StabilityMatrix.Core.Models;
2829
using StabilityMatrix.Core.Models.Api.Lykos.Analytics;
2930
using StabilityMatrix.Core.Models.Settings;
@@ -80,7 +81,7 @@ public partial class MainWindowViewModel : ViewModelBase
8081
{ Name: "pt-PT" } => 300,
8182
{ Name: "pt-BR" } => 260,
8283
{ Name: "ko-KR" } => 235,
83-
_ => 200
84+
_ => 200,
8485
};
8586

8687
public MainWindowViewModel(
@@ -156,7 +157,7 @@ protected override async Task OnInitialLoadedAsync()
156157
Content = Resources.Label_AnotherInstanceAlreadyRunning,
157158
IsPrimaryButtonEnabled = true,
158159
PrimaryButtonText = Resources.Action_Close,
159-
DefaultButton = ContentDialogButton.Primary
160+
DefaultButton = ContentDialogButton.Primary,
160161
};
161162
await dialog.ShowAsync();
162163
App.Shutdown();
@@ -262,6 +263,8 @@ settingsManager.Settings.Analytics.LastSeenConsentVersion is null
262263
.SafeFireAndForget();
263264
}
264265

266+
Task.Run(AddComputeCapabilityIfNecessary).SafeFireAndForget();
267+
265268
// Show what's new for updates
266269
if (settingsManager.Settings.UpdatingFromVersion is { } updatingFromVersion)
267270
{
@@ -294,15 +297,15 @@ settingsManager.Settings.Analytics.LaunchDataLastSentAt is null
294297
{
295298
Version = Compat.AppVersion.ToString(),
296299
RuntimeIdentifier = RuntimeInformation.RuntimeIdentifier,
297-
OsDescription = RuntimeInformation.OSDescription
300+
OsDescription = RuntimeInformation.OSDescription,
298301
}
299302
)
300303
.ContinueWith(task =>
301304
{
302305
if (!task.IsFaulted)
303306
{
304-
settingsManager.Transaction(
305-
s => s.Analytics.LaunchDataLastSentAt = DateTimeOffset.UtcNow
307+
settingsManager.Transaction(s =>
308+
s.Analytics.LaunchDataLastSentAt = DateTimeOffset.UtcNow
306309
);
307310
}
308311
})
@@ -467,7 +470,7 @@ private async Task<bool> ShowSelectDataDirectoryDialog()
467470
IsPrimaryButtonEnabled = false,
468471
IsSecondaryButtonEnabled = false,
469472
IsFooterVisible = false,
470-
Content = new SelectDataDirectoryDialog { DataContext = viewModel }
473+
Content = new SelectDataDirectoryDialog { DataContext = viewModel },
471474
};
472475

473476
var result = await dialog.ShowAsync(App.TopLevel);
@@ -500,7 +503,7 @@ public async Task ShowUpdateDialog()
500503
IsPrimaryButtonEnabled = false,
501504
IsSecondaryButtonEnabled = false,
502505
IsFooterVisible = false,
503-
Content = new UpdateDialog { DataContext = viewModel }
506+
Content = new UpdateDialog { DataContext = viewModel },
504507
};
505508

506509
await viewModel.Preload();
@@ -518,4 +521,30 @@ private async Task ShowMigrationTipIfNecessaryAsync()
518521

519522
settingsManager.Transaction(s => s.SeenTeachingTips.Add(TeachingTip.SharedFolderMigrationTip));
520523
}
524+
525+
private void AddComputeCapabilityIfNecessary()
526+
{
527+
try
528+
{
529+
if (settingsManager.Settings.PreferredGpu is not { IsNvidia: true, ComputeCapability: null })
530+
return;
531+
532+
var newGpuInfos = HardwareHelper.IterGpuInfoNvidiaSmi();
533+
var matchedGpuInfo = newGpuInfos?.FirstOrDefault(x =>
534+
x.Name?.Equals(settingsManager.Settings.PreferredGpu.Name) ?? false
535+
);
536+
537+
if (matchedGpuInfo is null)
538+
{
539+
return;
540+
}
541+
542+
using var transaction = settingsManager.BeginTransaction();
543+
transaction.Settings.PreferredGpu = matchedGpuInfo;
544+
}
545+
catch (Exception)
546+
{
547+
// ignored
548+
}
549+
}
521550
}

StabilityMatrix.Core/Helper/HardwareInfo/GpuInfo.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ public record GpuInfo
55
public int Index { get; set; }
66
public string? Name { get; init; } = string.Empty;
77
public ulong MemoryBytes { get; init; }
8+
public string? ComputeCapability { get; init; }
9+
10+
/// <summary>
11+
/// Gets the compute capability as a comparable decimal value (e.g. "8.6" becomes 8.6m)
12+
/// Returns null if compute capability is not available
13+
/// </summary>
14+
public decimal? ComputeCapabilityValue =>
15+
ComputeCapability != null && decimal.TryParse(ComputeCapability, out var value) ? value : null;
16+
817
public MemoryLevel? MemoryLevel =>
918
MemoryBytes switch
1019
{
1120
<= 0 => HardwareInfo.MemoryLevel.Unknown,
1221
< 4 * Size.GiB => HardwareInfo.MemoryLevel.Low,
1322
< 8 * Size.GiB => HardwareInfo.MemoryLevel.Medium,
14-
_ => HardwareInfo.MemoryLevel.High
23+
_ => HardwareInfo.MemoryLevel.High,
1524
};
1625

1726
public bool IsNvidia
@@ -29,26 +38,26 @@ public bool IsNvidia
2938

3039
public bool IsBlackwellGpu()
3140
{
32-
if (Name is null)
41+
if (ComputeCapability is null)
3342
return false;
3443

35-
return IsNvidia
36-
&& Name.Contains("RTX 50", StringComparison.OrdinalIgnoreCase)
37-
&& !Name.Contains("RTX 5000", StringComparison.OrdinalIgnoreCase);
44+
return ComputeCapabilityValue >= 12.0m;
3845
}
3946

4047
public bool IsAmpereOrNewerGpu()
4148
{
42-
if (Name is null)
49+
if (ComputeCapability is null)
50+
return false;
51+
52+
return ComputeCapabilityValue >= 8.6m;
53+
}
54+
55+
public bool IsLegacyNvidiaGpu()
56+
{
57+
if (ComputeCapability is null)
4358
return false;
4459

45-
return IsNvidia
46-
&& Name.Contains("RTX", StringComparison.OrdinalIgnoreCase)
47-
&& !Name.Contains("RTX 20")
48-
&& !Name.Contains("RTX 4000")
49-
&& !Name.Contains("RTX 5000")
50-
&& !Name.Contains("RTX 6000")
51-
&& !Name.Contains("RTX 8000");
60+
return ComputeCapabilityValue < 7.5m;
5261
}
5362

5463
public bool IsAmd => Name?.Contains("amd", StringComparison.OrdinalIgnoreCase) ?? false;

StabilityMatrix.Core/Helper/HardwareInfo/HardwareHelper.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public static partial class HardwareHelper
1717
private static IReadOnlyList<GpuInfo>? cachedGpuInfos;
1818
private static readonly object cachedGpuInfosLock = new();
1919

20-
private static readonly Lazy<IHardwareInfo> HardwareInfoLazy =
21-
new(() => new Hardware.Info.HardwareInfo());
20+
private static readonly Lazy<IHardwareInfo> HardwareInfoLazy = new(() => new Hardware.Info.HardwareInfo()
21+
);
2222

2323
public static IHardwareInfo HardwareInfo => HardwareInfoLazy.Value;
2424

@@ -27,7 +27,7 @@ private static string RunBashCommand(string command)
2727
var processInfo = new ProcessStartInfo("bash", "-c \"" + command + "\"")
2828
{
2929
UseShellExecute = false,
30-
RedirectStandardOutput = true
30+
RedirectStandardOutput = true,
3131
};
3232

3333
var process = Process.Start(processInfo);
@@ -103,7 +103,7 @@ private static IEnumerable<GpuInfo> IterGpuInfoLinux()
103103
{
104104
Index = gpuIndex++,
105105
Name = name,
106-
MemoryBytes = memoryBytes
106+
MemoryBytes = memoryBytes,
107107
};
108108
}
109109
}
@@ -127,7 +127,7 @@ private static IEnumerable<GpuInfo> IterGpuInfoMacos()
127127
{
128128
Index = i,
129129
Name = videoController.Name,
130-
MemoryBytes = gpuMemoryBytes
130+
MemoryBytes = gpuMemoryBytes,
131131
};
132132
}
133133
}
@@ -168,7 +168,7 @@ public static IEnumerable<GpuInfo> IterGpuInfo(bool forceRefresh = false)
168168
{
169169
Name = gpu.Name,
170170
Index = index,
171-
MemoryBytes = gpu.MemoryBytes
171+
MemoryBytes = gpu.MemoryBytes,
172172
}
173173
);
174174

@@ -205,9 +205,9 @@ public static IEnumerable<GpuInfo> IterGpuInfo(bool forceRefresh = false)
205205
{
206206
FileName = "nvidia-smi",
207207
UseShellExecute = false,
208-
Arguments = "--query-gpu name,memory.total --format=csv",
208+
Arguments = "--query-gpu name,memory.total,compute_cap --format=csv",
209209
RedirectStandardOutput = true,
210-
CreateNoWindow = true
210+
CreateNoWindow = true,
211211
};
212212

213213
var process = Process.Start(psi);
@@ -224,7 +224,7 @@ public static IEnumerable<GpuInfo> IterGpuInfo(bool forceRefresh = false)
224224
{
225225
var gpu = results[index];
226226
var datas = gpu.Split(',', StringSplitOptions.RemoveEmptyEntries);
227-
if (datas is not { Length: 2 })
227+
if (datas is not { Length: 3 })
228228
continue;
229229

230230
var memory = Regex.Replace(datas[1], @"([A-Z])\w+", "").Trim();
@@ -234,7 +234,8 @@ public static IEnumerable<GpuInfo> IterGpuInfo(bool forceRefresh = false)
234234
{
235235
Name = datas[0],
236236
Index = index,
237-
MemoryBytes = Convert.ToUInt64(memory) * Size.MiB
237+
MemoryBytes = Convert.ToUInt64(memory) * Size.MiB,
238+
ComputeCapability = datas[2].Trim(),
238239
}
239240
);
240241
}
@@ -253,12 +254,13 @@ public static bool HasNvidiaGpu()
253254
public static bool HasBlackwellGpu()
254255
{
255256
return IterGpuInfo()
256-
.Any(
257-
gpu =>
258-
gpu is { IsNvidia: true, Name: not null }
259-
&& gpu.Name.Contains("RTX 50", StringComparison.OrdinalIgnoreCase)
260-
&& !gpu.Name.Contains("RTX 5000", StringComparison.OrdinalIgnoreCase)
261-
);
257+
.Any(gpu => gpu is { IsNvidia: true, Name: not null, ComputeCapabilityValue: >= 12.0m });
258+
}
259+
260+
public static bool HasLegacyNvidiaGpu()
261+
{
262+
return IterGpuInfo()
263+
.Any(gpu => gpu is { IsNvidia: true, Name: not null, ComputeCapabilityValue: < 7.5m });
262264
}
263265

264266
/// <summary>
@@ -322,7 +324,7 @@ private static MemoryInfo GetMemoryInfoImplWindows()
322324
{
323325
TotalInstalledBytes = (ulong)installedMemoryKb * 1024,
324326
TotalPhysicalBytes = memoryStatus.UllTotalPhys,
325-
AvailablePhysicalBytes = memoryStatus.UllAvailPhys
327+
AvailablePhysicalBytes = memoryStatus.UllAvailPhys,
326328
};
327329
}
328330

@@ -336,15 +338,15 @@ private static MemoryInfo GetMemoryInfoImplGeneric()
336338
return new MemoryInfo
337339
{
338340
TotalPhysicalBytes = HardwareInfo.MemoryStatus.TotalPhysical,
339-
TotalInstalledBytes = HardwareInfo.MemoryStatus.TotalPhysical
341+
TotalInstalledBytes = HardwareInfo.MemoryStatus.TotalPhysical,
340342
};
341343
}
342344

343345
return new MemoryInfo
344346
{
345347
TotalPhysicalBytes = HardwareInfo.MemoryStatus.TotalPhysical,
346348
TotalInstalledBytes = HardwareInfo.MemoryStatus.TotalPhysical,
347-
AvailablePhysicalBytes = HardwareInfo.MemoryStatus.AvailablePhysical
349+
AvailablePhysicalBytes = HardwareInfo.MemoryStatus.AvailablePhysical,
348350
};
349351
}
350352

StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,28 @@ await PrerequisiteHelper
439439
.ConfigureAwait(false);
440440
}
441441

442+
var sharedFolderMethodToUse =
443+
installedPackage.PreferredSharedFolderMethod ?? RecommendedSharedFolderMethod;
444+
// Temporarily remove symlinks if using Symlink method
445+
if (sharedFolderMethodToUse == SharedFolderMethod.Symlink)
446+
{
447+
if (SharedFolders is not null)
448+
{
449+
Helper.SharedFolders.RemoveLinksForPackage(
450+
SharedFolders,
451+
new DirectoryPath(installedPackage.FullPath!)
452+
);
453+
}
454+
455+
if (SharedOutputFolders is not null && installedPackage.UseSharedOutputFolder)
456+
{
457+
Helper.SharedFolders.RemoveLinksForPackage(
458+
SharedOutputFolders,
459+
new DirectoryPath(installedPackage.FullPath!)
460+
);
461+
}
462+
}
463+
442464
var versionOptions = options.VersionOptions;
443465

444466
if (!string.IsNullOrWhiteSpace(versionOptions.VersionTag))

StabilityMatrix.Core/Models/Packages/ComfyUI.cs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -344,33 +344,34 @@ public override async Task InstallPackage(
344344
await venvRunner.PipInstall("--upgrade pip wheel", onConsoleOutput).ConfigureAwait(false);
345345

346346
var torchVersion = options.PythonOptions.TorchIndex ?? GetRecommendedTorchVersion();
347+
var isLegacyNvidia =
348+
torchVersion == TorchIndex.Cuda
349+
&& (
350+
SettingsManager.Settings.PreferredGpu?.IsLegacyNvidiaGpu()
351+
?? HardwareHelper.HasLegacyNvidiaGpu()
352+
);
347353

348354
var pipArgs = new PipInstallArgs();
349355

350356
pipArgs = torchVersion switch
351357
{
352358
TorchIndex.DirectMl => pipArgs.WithTorchDirectML(),
353-
_
354-
=> pipArgs
355-
.AddArg("--upgrade")
356-
.WithTorch()
357-
.WithTorchVision()
358-
.WithTorchAudio()
359-
.WithTorchExtraIndex(
360-
torchVersion switch
361-
{
362-
TorchIndex.Cpu => "cpu",
363-
TorchIndex.Cuda => "cu128",
364-
TorchIndex.Rocm => "rocm6.2.4",
365-
TorchIndex.Mps => "cpu",
366-
_
367-
=> throw new ArgumentOutOfRangeException(
368-
nameof(torchVersion),
369-
torchVersion,
370-
null
371-
)
372-
}
373-
)
359+
_ => pipArgs
360+
.AddArg("--upgrade")
361+
.WithTorch()
362+
.WithTorchVision()
363+
.WithTorchAudio()
364+
.WithTorchExtraIndex(
365+
torchVersion switch
366+
{
367+
TorchIndex.Cpu => "cpu",
368+
TorchIndex.Cuda when isLegacyNvidia => "cu126",
369+
TorchIndex.Cuda => "cu128",
370+
TorchIndex.Rocm => "rocm6.2.4",
371+
TorchIndex.Mps => "cpu",
372+
_ => throw new ArgumentOutOfRangeException(nameof(torchVersion), torchVersion, null),
373+
}
374+
),
374375
};
375376

376377
var requirements = new FilePath(installLocation, "requirements.txt");

0 commit comments

Comments
 (0)