huggingface_hub v2.3.0 lists an 800,000-file dataset in 20 seconds, down from 13 minutes

3 weeks ago

huggingface_hub v2.3.0: HfFileSystem lists large repos in parallel (an 800,000-file dataset in about 20 seconds instead of 13 minutes), Bucket listings that refresh live, attachments in Hub discussions, one-request safetensors shard headers, and fixes for create_commit, hf jobs run, InferenceClient and custom endpoints. https://github.com/huggingface/huggingface_hub/releases/tag/v2.3.0 https://github.com/huggingface/huggingface_hub/compare/v2.2.0...v2.3.0

Ask about this presentation

Chapters

  1. 0:00Large repos list in parallel
  2. 0:15Shallow listings stop early
  3. 0:28Bucket listings stay fresh
  4. 0:44Live follow limits
  5. 0:5802: Discussions and models
  6. 1:00Attachments in discussions
  7. 1:15Shard headers in one request
  8. 1:28Gated repos that hide requesters
  9. 1:4403: Fixes
  10. 1:46create_commit keeps re-added files
  11. 1:59hf jobs run keeps streaming
  12. 2:12Queued Jobs show their status
  13. 2:26InferenceClient fixes
  14. 2:41Endpoint, offline and Bucket fixes
  15. 2:56The biggest repo you list
Show transcript
  1. huggingface_hub 2.3 lists large repos in parallel. Listing every file in the objaverse dataset, almost 800,000 of them, took about 13 minutes. Now it takes about 20 seconds.

    Slide text
    01 02 03 HfFileSystem
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5153
    Hugging Face

    huggingface_hub v2.3.0 lists large repos in parallel

    allenai/objaverse · 798,924 files 776 s → 19.7 s
  2. The Hub sends a file tree a thousand entries at a time, each page after the last, so the library now lists folders side by side. And a listing two levels deep stops at two levels, in six requests.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 HfFileSystem
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5153

    A two-level listing now stops at two levels

    datasets/allenai/objaversebeforeafter
    find(), 798,924 files801 requests, 776 s807 requests, 19.7 s
    find(maxdepth=2), 328 entries801 requests, 776 s6 requests, 1.5 s
  3. HfFileSystem caches folder listings, so files another process added to a Bucket stayed hidden until you cleared the cache. With live follow, the Hub sends each change and the stale listing is dropped. It works from pandas and pyarrow too.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 HfFileSystem
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5096

    Bucket listings update while another process writes

    HfFileSystem(live_follow=True)
    fsspec pandas pyarrow
  4. It's off by default, because it keeps a connection open for every Bucket it follows. It only refreshes listings, since reading a file always fetches it from the Hub. Model, dataset and Space repos don't get it.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 HfFileSystem
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5096

    Live follow is off by default, and Buckets only

    One open connection per followed Bucket
    Listings and metadata file reads already fetch from the Hub
    Model, dataset and Space repos not supported
  5. Discussions, models and gated repos.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Discussions and models
    02
    Discussions and models
  6. Discussions and pull requests on the Hub can now carry images, video and audio, from Python or from the hf command line. Before, that meant calling an undocumented Hub endpoint by hand.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Discussions and models
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5161

    Attach images, video and audio to discussions and PRs

    api.upload_attachment("screenshot.png")

    hf discussions create … --attach ./after.png
  7. Reading the safetensors headers of a sharded model took one request per shard. A new function gets them all in one. It only reads the main revision, and the old function is unchanged.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Discussions and models
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5159

    Every safetensors shard header in one request

    get_sharded_safetensors_metadata reads the main revision only. get_safetensors_metadata is unchanged.

  8. Gated repos can now hide the name and email of people asking for access. Listing their requests used to crash. Now you accept each request by its own identifier. Type checkers may flag code that expects a username.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Discussions and models
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5047

    Access requests work on repos that hide who asked

    Listing requests used to fail with a KeyError
    Each request now has a request_id to accept or reject it by
    username, fullname now typed str | None
  9. Fixes you may have hit.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    03
    Fixes
  10. Since version 0.24, deleting a folder and pushing the same unchanged files back in one commit removed those files from the repo, without any error. Now the files are kept.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5196

    create_commit keeps files you re-add after a delete

    CommitOperationDelete("x/", is_folder=True),
    # unchanged on the Hub:
    CommitOperationAdd("x/a.txt", b"keep me\n"),
    
    # before: x/a.txt is deleted
    # after:  x/a.txt is kept
  11. hf jobs run used to stop printing logs when the stream ended before the Job did. It now reconnects until the Job finishes, and Control C exits right away with a hint on how to follow or cancel it.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5162

    hf jobs run keeps streaming logs

    hf jobs run before and after: logs keep streaming and Ctrl+C exits with a hint
  12. While a Job waited for hardware, the CLI printed nothing, so it looked stuck. Now it shows the Hub's status message and how long the Job has been waiting, in interactive terminals only.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5163

    A Job waiting for hardware says so

    hf jobs run showing the scheduling status while the Job waits for hardware
  13. A reused Inference Client stops holding every finished response in memory. The async client stops freezing your event loop while queue-based providers like fal work. And a timeout raises the documented timeout error.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5197 · #5200 · #5150

    InferenceClient frees memory and unblocks async

    Non-streaming responses freed after each call; 30 calls with a 1 MB prompt held 30 MB
    AsyncInferenceClient queue-based providers such as fal-ai no longer freeze the event loop
    timeout raises InferenceTimeoutError, as documented
  14. With a custom endpoint, 20 methods were sent to huggingface dot co with your token. In offline mode, a pinned download could delete your local copy. And pushing a dataset into a new Bucket works again.

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    huggingface/huggingface_hub · GitHub release notes v2.3.0 · #5149 · #5199 · #5237

    Your token stays on your endpoint

    HfApi(endpoint=...) 20 methods went to huggingface.co with your token
    HF_HUB_OFFLINE=1 a pinned download could delete the file in local_dir
    push_to_hub into a new Bucket failed with FileNotFoundError since v2.2.0
  15. The full list is in the 2.3 release notes on GitHub. So, how many files are in the biggest repo you list with HfFileSystem?

    Slide text
    huggingface_hub v2.3.0
    01 02 03 Fixes
    huggingface/huggingface_hub · GitHub release notes v2.3.0

    How many files are in the biggest repo you list?

    Release notes: github.com/huggingface/huggingface_hub › Releases › v2.3.0

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York