Skip to content

Commit 3580b25

Browse files
authored
Merge pull request LykosAI#981 from ionite34/backport/main/pr-980
[dev to main] backport: Fix models with same name overwriting each other on download & update… (980)
2 parents e7f2093 + c7b232f commit 3580b25

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ 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.13.4
9+
### Changed
10+
- Upgraded ComfyUI CUDA torch to 12.6
11+
### Fixed
12+
- Fixed [#1128](https://github.com/LykosAI/StabilityMatrix/issues/1128) - overwriting models when downloading multiple with the same name
13+
- Fixed ROCm torch indexes for ComfyUI & Forge
14+
815
## v2.13.3
9-
### Added
10-
- Added Safetensor Metadata viewer to the Checkpoint Manager context menu - thanks to @genteure!
1116
### Changed
1217
- "Remove symbolic links on shutdown" option now also removes links from Output Sharing
1318
### Fixed

StabilityMatrix.Avalonia/Services/ModelImportService.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
using AsyncAwaitBestPractices;
66
using Avalonia.Controls.Notifications;
77
using Injectio.Attributes;
8+
using Python.Runtime;
9+
using StabilityMatrix.Core.Extensions;
810
using StabilityMatrix.Core.Models;
911
using StabilityMatrix.Core.Models.Api;
1012
using StabilityMatrix.Core.Models.FileInterfaces;
1113
using StabilityMatrix.Core.Models.Progress;
1214
using StabilityMatrix.Core.Services;
15+
using Dispatcher = Avalonia.Threading.Dispatcher;
1316

1417
namespace StabilityMatrix.Avalonia.Services;
1518

@@ -117,6 +120,23 @@ public async Task DoImport(
117120
modelFile.Name = Path.GetInvalidFileNameChars()
118121
.Aggregate(modelFile.Name, (current, c) => current.Replace(c, '_'));
119122

123+
// New code: Ensure unique file name
124+
var originalFileName = modelFile.Name;
125+
var uniqueFileName = GenerateUniqueFileName(downloadFolder.ToString(), originalFileName);
126+
if (!uniqueFileName.Equals(originalFileName, StringComparison.Ordinal))
127+
{
128+
Dispatcher.UIThread.Post(() =>
129+
{
130+
notificationService.Show(
131+
new Notification(
132+
"File renamed",
133+
$"A file with the name \"{originalFileName}\" already exists. The model will be saved as \"{uniqueFileName}\"."
134+
)
135+
);
136+
});
137+
modelFile.Name = uniqueFileName;
138+
}
139+
120140
var downloadPath = downloadFolder.JoinFile(modelFile.Name);
121141

122142
// Download model info and preview first
@@ -163,4 +183,25 @@ public async Task DoImport(
163183

164184
await trackedDownloadService.TryStartDownload(download);
165185
}
186+
187+
private string GenerateUniqueFileName(string folder, string fileName)
188+
{
189+
var fullPath = Path.Combine(folder, fileName);
190+
if (!File.Exists(fullPath))
191+
return fileName;
192+
193+
var name = Path.GetFileNameWithoutExtension(fileName);
194+
var extension = Path.GetExtension(fileName);
195+
var count = 1;
196+
string newFileName;
197+
198+
do
199+
{
200+
newFileName = $"{name} ({count}){extension}";
201+
fullPath = Path.Combine(folder, newFileName);
202+
count++;
203+
} while (File.Exists(fullPath));
204+
205+
return newFileName;
206+
}
166207
}

StabilityMatrix.Core/Models/Packages/ComfyUI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ public override async Task InstallPackage(
219219
torchVersion switch
220220
{
221221
TorchIndex.Cpu => "cpu",
222-
TorchIndex.Cuda => "cu124",
223-
TorchIndex.Rocm => "rocm6.2",
222+
TorchIndex.Cuda => "cu126",
223+
TorchIndex.Rocm => "rocm6.2.4",
224224
TorchIndex.Mps => "cpu",
225225
_
226226
=> throw new ArgumentOutOfRangeException(

StabilityMatrix.Core/Models/Packages/SDWebForge.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public override async Task InstallPackage(
161161
{
162162
TorchIndex.Cpu => "cpu",
163163
TorchIndex.Cuda => "cu121",
164-
TorchIndex.Rocm => "rocm5.6",
164+
TorchIndex.Rocm => "rocm5.7",
165165
TorchIndex.Mps => "cpu",
166166
_ => throw new ArgumentOutOfRangeException(nameof(torchVersion), torchVersion, null)
167167
}

0 commit comments

Comments
 (0)