Skip to content

Add repo revision option #202

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

Merged
merged 12 commits into from
May 28, 2025

Conversation

petrukha-ivan
Copy link
Contributor

What

Added revision parameter to specify a branch, tag, or commit when downloading a model.

@@ -349,7 +350,7 @@ public extension HubApi {
url = url.appending(component: repo.type.rawValue)
}
url = url.appending(path: repo.id)
url = url.appending(path: "resolve/main") // TODO: revisions
url = url.appending(path: "resolve/\(revision)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe best not to do direct string interpolation?
Also needs a null check I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

String interpolation is the preferred method for this in Swift because it's faster and benefits from compile-time optimizations. We also don't need a null check here since revision is not marked as Optional and always has a value. However, I can add something like assert(revision.isEmpty == false, "Revision cannot be empty") if you'd prefer 🙂

@FL33TW00D
Copy link
Collaborator

Just tested:

~/Code/swift-transformers test-revision ❯ .build/release/hub-cli download jinaai/jina-embeddings-v3 --revision BINGO 
Error: Authentication required. Please provide a valid Hugging Face token.
~/Code/swift-transformers test-revision ❯ .build/release/hub-cli download jinaai/jina-embeddings-v3 --revision main 
40.00%
~/Code/swift-transformers test-revision ❯ .build/release/hub-cli download jinaai/jina-embeddings-v3 --revision INVALID$%£@ 
Error: Authentication required. Please provide a valid Hugging Face token.

Works fine with valid revision, incorrect error message if not. Would add a test with janky characters too, can never be too sure!

@petrukha-ivan
Copy link
Contributor Author

@FL33TW00D Hi! You're right 👍 I've fixed the error type to throw the correct error in case of invalid revision, and also added a few unit tests to test both positive and negative cases.

@petrukha-ivan petrukha-ivan requested a review from FL33TW00D May 28, 2025 10:51
Co-authored-by: Pedro Cuenca <pedro@huggingface.co>
Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the great contribution and for iterating 🙌 !

I think we should maybe merge #200 first, just in case. Would you agree, @FL33TW00D?

@FL33TW00D
Copy link
Collaborator

Still seeing an issue here @petrukha-ivan, try the following:
.build/release/hub-cli download jinaai/jina-embeddings-v3 --revision main
.build/release/hub-cli download jinaai/jina-embeddings-v3 --revision refactor-task-type

@petrukha-ivan
Copy link
Contributor Author

@FL33TW00D Ah, good catch — it's fixed now 👍

@FL33TW00D
Copy link
Collaborator

@petrukha-ivan Could you please rebase? We just merged another branch to fix an issue :)

@pcuenca
Copy link
Member

pcuenca commented May 28, 2025

One last thing: getFileMetadata is still using main, I think. Can we pass revision through to it?

@petrukha-ivan
Copy link
Contributor Author

@pcuenca Sure! I've just added a revision argument to those methods 👍

@petrukha-ivan
Copy link
Contributor Author

@FL33TW00D I'm not sure why the tests failed 🤔 I just ran it locally and everything is green. Could it be related to the runner somehow?

@FL33TW00D
Copy link
Collaborator

@petrukha-ivan Nothing you've done, we are getting 429'd by the Hub

@FL33TW00D
Copy link
Collaborator

@petrukha-ivan Appreciate the back and forth here! Thanks for the contribution 🤗

@FL33TW00D FL33TW00D merged commit ca72653 into huggingface:main May 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants