Skip to content

Upgrade hf-hub to 1.0.0-rc.1#865

Draft
assafvayner wants to merge 3 commits into
huggingface:mainfrom
assafvayner:assaf/upgrade-hf-hub-1.0.0-rc.1
Draft

Upgrade hf-hub to 1.0.0-rc.1#865
assafvayner wants to merge 3 commits into
huggingface:mainfrom
assafvayner:assaf/upgrade-hf-hub-1.0.0-rc.1

Conversation

@assafvayner
Copy link
Copy Markdown

Summary

Upgrade hf-hub from 0.4 to 1.0.0-rc.1. The 1.0 release is a full API rewrite — Api / ApiBuilder / ApiRepo are gone, replaced by HFClient / HFRepository. This PR migrates the workspace to the new surface and switches the TLS backend to rustls.

Filed as a draft so it can sit behind the final 1.0 release on crates.io if desired; ready for review against the RC.

Notable changes

  • Workspace dep: hf-hub = "0.4" (feature tokio) → 1.0.0-rc.1 (feature rustls-tls).
  • backends/candle dev-dep: feature ureqblocking (sync API in tests).
  • core dev-dep: new hf-hub = { workspace = true, features = ["blocking"] } for the in-tree tokenization test that uses the sync surface.
  • New text_embeddings_backend::ModelRepo: bundles (HFRepository<RepoTypeModel>, Option<String> /* revision */). The old ApiRepo carried the revision internally; the new API takes it per-call, so we keep them together for ergonomic plumbing through download_artifacts etc.
  • Builder migration: ApiBuilder::from_env().with_progress(false).with_*HFClient::builder().cache_dir(..).token(..).build(). The HF_HUB_USER_AGENT_ORIGIN env var is read inside build(), so the explicit with_user_agent("origin", ..) call is no longer needed.
  • Repo handle: api.repo(Repo::with_revision(id, RepoType::Model, rev))client.model(owner, name) with revision threaded per-call. model_id is split on / (anyhow context if malformed).
  • Per-call download: api_repo.get(file).awaitrepo.download_file().filename(file).maybe_revision(..).send().await.
  • info(): api.info().awaitrepo.info().maybe_revision(..).send().await. info.siblings is now Option<Vec<RepoSibling>>, handled with unwrap_or_default().
  • JoinHandle results: HFError does not impl From<JoinError>, so the awaited handle is mapped to HFError::Other(...) explicitly instead of handle.await??.

Test plan

  • cargo check --tests --workspace
  • cargo clippy --workspace --tests -- -D warnings
  • Live model download smoke test (router + candle backend) before flipping to ready-for-review
  • Re-run once hf-hub@1.0.0 (final) is published, bumping the dep

The 1.0 release of hf-hub is a full API rewrite — the `Api`/`ApiBuilder`/
`ApiRepo` types are gone, replaced by `HFClient`/`HFRepository`. This change
migrates the workspace to the new surface and switches the TLS backend to
rustls.

- Workspace dep: `hf-hub = "0.4"` (features `tokio`) → `1.0.0-rc.1`
  (features `rustls-tls`).
- `backends/candle` dev-dep: feature `ureq` → `blocking` (sync API).
- `core` gains a dev-dep on `hf-hub` with `blocking` for the in-tree
  tokenization test that uses the sync surface directly.
- New `text_embeddings_backend::ModelRepo` bundles
  `(HFRepository<RepoTypeModel>, Option<revision>)` to replace the old
  `ApiRepo` (which carried the revision internally — the new API takes it
  per-call).
- Calls migrated:
  - `ApiBuilder::from_env().with_progress(false).with_*` →
    `HFClient::builder().cache_dir(..).token(..).build()`. The
    `HF_HUB_USER_AGENT_ORIGIN` env var is read inside `build()`, so the
    explicit `with_user_agent("origin", ..)` call is no longer needed.
  - `api.repo(Repo::with_revision(id, RepoType::Model, rev))` →
    `client.model(owner, name)` with revision threaded per-call.
  - `api_repo.get(file).await` →
    `repo.download_file().filename(file).maybe_revision(..).send().await`.
  - `api.info().await` → `repo.info().maybe_revision(..).send().await`;
    `info.siblings` is now `Option<Vec<RepoSibling>>`, handled with
    `unwrap_or_default()`.
  - `JoinHandle` results: `HFError` does not impl `From<JoinError>`, so
    the awaited handle is mapped to `HFError::Other` explicitly.
- Tests in `backends/candle/tests/common.rs` switched to the sync
  `HFClientSync`/`HFRepositorySync` handles and a small `fetch` helper
  to keep call sites readable.

Verified: `cargo check --tests --workspace` and
`cargo clippy --workspace --tests -- -D warnings` both pass.
Per review: instead of a struct bundling `HFRepository<RepoTypeModel>` and
`Option<String>`, plumb both as separate parameters through the download
helpers. `HFRepository` is already cheap to clone (`Arc<HFClientInner>`
inside), so the explicit `Arc<ModelRepo>` wrapping in the spawn closures is
also gone — closures clone the repo handle directly and the revision
`Option<String>` per task.
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.

1 participant