feat: migrate legacy hf.co tags to huggingface.co during client initialization#645
feat: migrate legacy hf.co tags to huggingface.co during client initialization#645ilopezluna wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello @ilopezluna, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where models pulled with the legacy Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces an automatic migration of legacy hf.co/ tags to the canonical huggingface.co/ format upon client initialization. This is a valuable fix to prevent cache misses for models downloaded before the normalization was in place. The implementation is clean, with the migration logic well-encapsulated in client.migrateHFTags and store.MigrateTags. The accompanying tests are thorough, covering migration scenarios and ensuring idempotency. I have a couple of minor suggestions to improve the test code's clarity and maintainability.
| for _, tag := range tags { | ||
| if strings.Contains(tag, "hf.co/") && !strings.Contains(tag, "huggingface.co/") { | ||
| hasOldTag = true | ||
| } | ||
| if strings.Contains(tag, "huggingface.co/") { | ||
| hasNewTag = true | ||
| } | ||
| } |
There was a problem hiding this comment.
The logic to check for old and new tags can be simplified and made more robust by using strings.HasPrefix instead of strings.Contains. This more clearly expresses the intent of checking for a specific domain prefix and avoids potential false positives if hf.co appeared elsewhere in a tag.
| for _, tag := range tags { | |
| if strings.Contains(tag, "hf.co/") && !strings.Contains(tag, "huggingface.co/") { | |
| hasOldTag = true | |
| } | |
| if strings.Contains(tag, "huggingface.co/") { | |
| hasNewTag = true | |
| } | |
| } | |
| for _, tag := range tags { | |
| if strings.HasPrefix(tag, "hf.co/") { | |
| hasOldTag = true | |
| } | |
| if strings.HasPrefix(tag, "huggingface.co/") { | |
| hasNewTag = true | |
| } | |
| } |
| migrated, err := s.MigrateTags(func(tag string) string { | ||
| if rest, found := strings.CutPrefix(tag, "hf.co/"); found { | ||
| return "huggingface.co/" + rest | ||
| } | ||
| return tag | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("MigrateTags failed: %v", err) | ||
| } | ||
|
|
||
| if migrated != 1 { | ||
| t.Errorf("Expected 1 migrated tag, got %d", migrated) | ||
| } | ||
|
|
||
| // Verify the model can be found with the new tag | ||
| if _, err := s.Read("huggingface.co/testorg/testmodel:latest"); err != nil { | ||
| t.Fatalf("Failed to read model with migrated tag: %v", err) | ||
| } | ||
|
|
||
| // Verify the old tag no longer works | ||
| if _, err := s.Read("hf.co/testorg/testmodel:latest"); !errors.Is(err, store.ErrModelNotFound) { | ||
| t.Errorf("Expected ErrModelNotFound for old tag, got: %v", err) | ||
| } | ||
|
|
||
| // Verify the non-HF model is unaffected | ||
| if _, err := s.Read("ai/some-model:latest"); err != nil { | ||
| t.Fatalf("Non-HF model should be unaffected: %v", err) | ||
| } | ||
|
|
||
| // Running migration again should be a no-op | ||
| migrated2, err := s.MigrateTags(func(tag string) string { | ||
| if rest, found := strings.CutPrefix(tag, "hf.co/"); found { | ||
| return "huggingface.co/" + rest | ||
| } | ||
| return tag | ||
| }) |
Models pulled with
hf.co/before the normalization fix in #617 were stored with un-normalized tags, causing cache misses and duplicate downloads. This adds an automatic tag migration on client startup that rewriteshf.co/→huggingface.co/in the store index, so previously-pulled models are found by the cache check.