Skip to content
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

Improve HF download speed #1899

Merged
merged 3 commits into from
Jan 8, 2025
Merged

Improve HF download speed #1899

merged 3 commits into from
Jan 8, 2025

Conversation

rasbt
Copy link
Collaborator

@rasbt rasbt commented Jan 7, 2025

Addresses the speed issue discussed in #1886. I think the issue is that the setting needs to happen before importing huggingface packages @Andrei-Aksionov .

@rasbt rasbt requested a review from lantiga as a code owner January 7, 2025 18:53
@rasbt rasbt requested a review from Andrei-Aksionov January 7, 2025 18:53
@Andrei-Aksionov
Copy link
Collaborator

I think I tested the same approach and it didn't work.
I think the import happens somewhere even earlier.

⚡ rasbt-patch-4 ~/litgpt export repo_id=Qwen/Qwen2.5-0.5B-Instruct
⚡ rasbt-patch-4 ~/litgpt litgpt download $repo_id                 
Setting HF_HUB_ENABLE_HF_TRANSFER=1
config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 659/659 [00:00<00:00, 7.81MB/s]
generation_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 242/242 [00:00<00:00, 1.32MB/s]
model.safetensors: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████| 988M/988M [01:35<00:00, 10.4MB/s]
tokenizer.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7.03M/7.03M [00:00<00:00, 12.0MB/s]
tokenizer_config.json: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 7.30k/7.30k [00:00<00:00, 69.2MB/s]
Converting checkpoint files to LitGPT format.
{'checkpoint_dir': PosixPath('checkpoints/Qwen/Qwen2.5-0.5B-Instruct'),
 'debug_mode': False,
 'dtype': None,
 'model_name': None}
Loading weights: model.safetensors: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 00:01<00:00, 76.08it/s
Saving converted checkpoint to checkpoints/Qwen/Qwen2.5-0.5B-Instruct
⚡ rasbt-patch-4 ~/litgpt export HF_HUB_ENABLE_HF_TRANSFER=1                   
⚡ rasbt-patch-4 ~/litgpt rm -rf checkpoints                
⚡ rasbt-patch-4 ~/litgpt litgpt download $repo_id          
config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 659/659 [00:00<00:00, 9.15MB/s]
generation_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 242/242 [00:00<00:00, 1.54MB/s]
model.safetensors: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████▉| 988M/988M [00:02<00:00, 459MB/s]
tokenizer.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7.03M/7.03M [00:00<00:00, 22.1MB/s]
tokenizer_config.json: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 7.30k/7.30k [00:00<00:00, 64.1MB/s]
Converting checkpoint files to LitGPT format.
{'checkpoint_dir': PosixPath('checkpoints/Qwen/Qwen2.5-0.5B-Instruct'),
 'debug_mode': False,
 'dtype': None,
 'model_name': None}
Loading weights: model.safetensors: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 00:01<00:00, 75.90it/s
Saving converted checkpoint to checkpoints/Qwen/Qwen2.5-0.5B-Instruct

2 seconds vs 1 minute 35 seconds.

litgpt/scripts/download.py Outdated Show resolved Hide resolved
@rasbt
Copy link
Collaborator Author

rasbt commented Jan 7, 2025

@Andrei-Aksionov thanks for checking, I will poke around a bit more

@rasbt
Copy link
Collaborator Author

rasbt commented Jan 7, 2025

Hm, this is weird:

With the code in main:

  1. if I HF_HUB_ENABLE_HF_TRANSFER=1 it complaints that hf_transfer is not installed; when installing it then, the download goes fast as advertised.

  2. If changing back to HF_HUB_ENABLE_HF_TRANSFER=0, it's still fast.

  3. when running withHF_HUB_ENABLE_HF_TRANSFER=0 but hf_transfer uninstalled, it's back to slow

  4. when reinstalling hf_transfer but keeping HF_HUB_ENABLE_HF_TRANSFER=0 it's still fast.

So I think all one needs to do is to add hf_transfer to the dependencies? And printing a message to suggest installing it if users don't have it already installed.

@rasbt rasbt merged commit a439338 into main Jan 8, 2025
8 of 9 checks passed
@rasbt rasbt deleted the rasbt-patch-4 branch January 8, 2025 19:56
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.

2 participants