Skip to content

[Feature Request]: Use the huggingface_hub library for downloading checkpoints from the HF Hub  #8217

Description

@sayakpaul

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

Currently, the model checkpoints from the Hugging Face (HF) Hub are downloaded using the following

dl = load_file_from_url(model_url, model_path, True, download_name)

The HF team provides a separate library called huggingface_hub that lets anyone seamlessly interact with the HF Hub and its files. It comes packed with support for caching as well. So, I was wondering if we should consider refactoring this with huggingface_hub.

Proposed workflow

If a user enters, say, andite/anything-v4.0 (a repository on the HF Hub), we would automatically download this checkpoint and cache it. An option for downloading a specific checkpoint can also be added.

The code for this is relatively quite simple:

import huggingface_hub as hub

repo_id = "andite/anything-v4.0"
filename = "anything-v4.0.ckpt"

file_path = hub.hf_hub_download(repo_id, filename)

Here are some number on loading a checkpoint:

Without caching:

CPU times: user 14.3 s, sys: 14.2 s, total: 28.5 s
Wall time: 1min 59s

With caching:

CPU times: user 380 ms, sys: 48.7 ms, total: 428 ms
Wall time: 682 ms

Additional information

Cc: @patrickvonplaten

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions