Repository reference types and helpers for HuggingFace Hub.
Provides Bumblebee-compatible repository tuple types alongside the existing keyword-based API.
Repository Types
A repository can be referenced as:
{:hf, repository_id}- HuggingFace Hub repository{:hf, repository_id, opts}- HuggingFace Hub repository with options{:local, directory}- Local directory containing model files
Options for :hf repositories
:revision- Git revision (branch, tag, or commit). Defaults to"main".:cache_dir- Override the cache directory:offline- Iftrue, only use cached files:auth_token- Authentication token for private repos:subdir- Subdirectory within the repository
Examples
# Simple HuggingFace repository
{:hf, "bert-base-uncased"}
# With options
{:hf, "bert-base-uncased", revision: "v1.0", auth_token: "hf_xxx"}
# Local directory
{:local, "/path/to/model"}
Summary
Functions
Converts a repository ID to a cache scope string.
Returns a URL to list the contents of a HuggingFace repository.
Returns a URL pointing to a file in a HuggingFace repository.
Normalizes a repository reference to its canonical form.
Types
Functions
Converts a repository ID to a cache scope string.
Used for organizing cached files by repository.
Examples
iex> HfHub.Repository.cache_scope("openai/gpt-2")
"openai--gpt-2"
Returns a URL to list the contents of a HuggingFace repository.
Examples
iex> HfHub.Repository.file_listing_url({:hf, "bert-base-uncased", []})
"https://huggingface.co/api/models/bert-base-uncased/tree/main"
Returns a URL pointing to a file in a HuggingFace repository.
Examples
iex> HfHub.Repository.file_url({:hf, "bert-base-uncased", []}, "config.json")
"https://huggingface.co/bert-base-uncased/resolve/main/config.json"
iex> HfHub.Repository.file_url({:hf, "bert-base-uncased", revision: "v1.0"}, "config.json")
"https://huggingface.co/bert-base-uncased/resolve/v1.0/config.json"
Normalizes a repository reference to its canonical form.
Converts {:hf, id} to {:hf, id, []} for consistent handling.
Examples
iex> HfHub.Repository.normalize!({:hf, "bert-base-uncased"})
{:hf, "bert-base-uncased", []}
iex> HfHub.Repository.normalize!({:hf, "bert-base-uncased", revision: "v1.0"})
{:hf, "bert-base-uncased", [revision: "v1.0"]}
iex> HfHub.Repository.normalize!({:local, "/path/to/model"})
{:local, "/path/to/model"}