Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions StabilityMatrix.Core/Helper/RemoteModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private static RemoteResource ControlNetCommon(string path, string sha256)
[
new()
{
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8m.pt"),
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/b0a075fd35454c86bb453a1ca06b29ffee704c20/face_yolov8m.pt"),
HashSha256 = "f02b8a23e6f12bd2c1b1f6714f66f984c728fa41ed749d033e7d6dea511ef70c",
InfoUrl = new Uri("https://huggingface.co/Bingsu/adetailer"),
Author = "Bingsu",
Expand All @@ -212,7 +212,7 @@ private static RemoteResource ControlNetCommon(string path, string sha256)
},
new()
{
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/main/hand_yolov8s.pt"),
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/b0a075fd35454c86bb453a1ca06b29ffee704c20/hand_yolov8s.pt"),
HashSha256 = "5c4faf8d17286ace2c3d3346c6d0d4a0c8d62404955263a7ae95c1dd7eb877af",
InfoUrl = new Uri("https://huggingface.co/Bingsu/adetailer"),
Author = "Bingsu",
Expand All @@ -225,7 +225,7 @@ private static RemoteResource ControlNetCommon(string path, string sha256)
},
new()
{
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/main/person_yolov8m-seg.pt"),
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/b0a075fd35454c86bb453a1ca06b29ffee704c20/person_yolov8m-seg.pt"),
HashSha256 = "9d881ec50b831f546e37977081b18f4e3bf65664aec163f97a311b0955499795",
InfoUrl = new Uri("https://huggingface.co/Bingsu/adetailer"),
Author = "Bingsu",
Expand All @@ -238,7 +238,7 @@ private static RemoteResource ControlNetCommon(string path, string sha256)
},
new()
{
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/main/person_yolov8s-seg.pt"),
Url = new Uri("https://huggingface.co/Bingsu/adetailer/resolve/b0a075fd35454c86bb453a1ca06b29ffee704c20/person_yolov8s-seg.pt"),
HashSha256 = "b5684835e79fd8b805459e0f7a0f9daa437e421cb4a214fff45ec4ac61767ef9",
InfoUrl = new Uri("https://huggingface.co/Bingsu/adetailer"),
Author = "Bingsu",
Expand Down
45 changes: 45 additions & 0 deletions StabilityMatrix.Tests/Core/RemoteModelsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Reflection;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models;

namespace StabilityMatrix.Tests.Core;

public class RemoteModelsTests
{
[Fact]

Check failure on line 9 in StabilityMatrix.Tests/Core/RemoteModelsTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Fact' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 9 in StabilityMatrix.Tests/Core/RemoteModelsTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'FactAttribute' could not be found (are you missing a using directive or an assembly reference?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I'm not sure this PR needs tests exactly, but you will need to change to MSTest format, we're not using xunit and this isn't building right now.

public void ExecutableHuggingFaceModelsUsePinnedRevisions()
{
var executableExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
".bin",
".ckpt",
".pt",
".pth",
};

var resources = typeof(RemoteModels)
.GetProperties(BindingFlags.Public | BindingFlags.Static)
.Select(property => property.GetValue(null))
.SelectMany(
value =>
value switch
{
IEnumerable<RemoteResource> remoteResources => remoteResources,
IEnumerable<HybridModelFile> hybridModels => hybridModels
.Where(model => model.DownloadableResource.HasValue)
.Select(model => model.DownloadableResource!.Value),
HybridModelFile { DownloadableResource: { } resource } => [resource],
_ => [],
}
);

var unpinnedModels = resources
.Where(resource => resource.Url.Host == "huggingface.co")
.Where(resource => executableExtensions.Contains(Path.GetExtension(resource.Url.AbsolutePath)))
.Where(resource => resource.Url.AbsolutePath.Contains("/resolve/main/", StringComparison.Ordinal))
.Select(resource => resource.Url)
.ToArray();

Assert.Empty(unpinnedModels);
}
Comment on lines +2 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current regression test only validates RemoteModels.UltralyticsModelFiles. To make this test comprehensive and future-proof against any new model collections or properties added to RemoteModels, we can use reflection to scan all public static properties for downloadable resources (RemoteResource and HybridModelFile). This ensures that any executable Hugging Face models added anywhere in RemoteModels in the future will automatically be validated.

using System.Reflection;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models;

namespace StabilityMatrix.Tests.Core;

public class RemoteModelsTests
{
    [Fact]
    public void ExecutableHuggingFaceModelsUsePinnedRevisions()
    {
        var executableExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
        {
            ".bin",
            ".ckpt",
            ".pt",
            ".pth",
        };

        var properties = typeof(RemoteModels).GetProperties(BindingFlags.Public | BindingFlags.Static);
        var resources = new List<RemoteResource>();

        foreach (var prop in properties)
        {
            var value = prop.GetValue(null);
            if (value is IEnumerable<RemoteResource> remoteResources)
            {
                resources.AddRange(remoteResources);
            }
            else if (value is IEnumerable<HybridModelFile> hybridModels)
            {
                resources.AddRange(hybridModels
                    .Where(m => m.DownloadableResource.HasValue)
                    .Select(m => m.DownloadableResource!.Value));
            }
            else if (value is HybridModelFile singleHybrid && singleHybrid.DownloadableResource.HasValue)
            {
                resources.Add(singleHybrid.DownloadableResource.Value);
            }
        }

        var unpinnedModels = resources
            .Where(resource => resource.Url.Host == "huggingface.co")
            .Where(resource => executableExtensions.Contains(Path.GetExtension(resource.Url.AbsolutePath)))
            .Where(resource => resource.Url.AbsolutePath.Contains("/resolve/main/", StringComparison.Ordinal))
            .Select(resource => resource.Url)
            .ToArray();

        Assert.Empty(unpinnedModels);
    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have read the CLA Document and I hereby sign the CLA

}
Loading