Lightning-AI / litgpt

20+ high-performance LLMs with recipes to pretrain, finetune and deploy at scale.
https://lightning.ai
Apache License 2.0
9.76k stars 974 forks source link

Automatically choose `--from_safetensors` when appropriate #1008

Closed awaelchli closed 6 months ago

awaelchli commented 6 months ago

If you forget to set --from_safetensors True when downloading models, you get:

ValueError: Expected 'checkpoints/google/gemma-2b' to contain .bin files

We assume that users perfectly follow the download tutorial guides where --from_safetensors True for some commands. But intuitively, I feel like the download scripts could probably choose this automatically. Some need it, some don't.

rasbt commented 6 months ago

Yeah, I think we originally added it for mistral and only few others need it (like Gemma).

I wonder if we should make --safetensors true the new default for the new user experience. It's actually safer :). And if a safetensor format is not available, we throw a warning and say "download the model with --safetensors false`. What do you think?

Andrei-Aksionov commented 6 months ago

There should be a way to check are there any files in the repo with .safetensors extension.

Andrei-Aksionov commented 6 months ago

Here is what I found after a quick search. Maybe there is an easier way exists.

from huggingface_hub import HfFileSystem
fs = HfFileSystem()
repo_id = "google/gemma-2b"
filenames = [x["name"] for x in fs.ls(repo_id)]
print(filenames)

outputs:

['google/gemma-2b/.gitattributes',
 'google/gemma-2b/README.md',
 'google/gemma-2b/config.json',
 'google/gemma-2b/gemma-2b.gguf',
 'google/gemma-2b/generation_config.json',
 'google/gemma-2b/model-00001-of-00002.safetensors',
 'google/gemma-2b/model-00002-of-00002.safetensors',
 'google/gemma-2b/model.safetensors.index.json',
 'google/gemma-2b/special_tokens_map.json',
 'google/gemma-2b/tokenizer.json',
 'google/gemma-2b/tokenizer.model',
 'google/gemma-2b/tokenizer_config.json']
rasbt commented 6 months ago

This looks reasonable to me. We already import from huggingface_hub so that wouldn't add an additional dependency