-
-
Notifications
You must be signed in to change notification settings - Fork 584
Pin executable Hugging Face model downloads to revisions #1688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current regression test only validates 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);
}
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have read the CLA Document and I hereby sign the CLA |
||
| } | ||
There was a problem hiding this comment.
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.