Lightning-AI / Lightning-AI/litgpt
Error loading converted litgpt checkpoints in `pytorch_model.bin` format using huggingface `AutoModelForCausalLM`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 1.5k
- Avg merge
- 15h 37m
- Merged PRs (30d)
- 1
Description
Hi, we're using the litgpt framework to train models and then would like to export them to huggingface format for continued tuning and evaluation.
The steps we're using after completing training are:
1. `scripts/convert_pretrained_checkpoint.py` to "finalize" the model
2. `scripts/convert_lit_checkpoint.py` to conform it to the huggingface saved model format
3. Load using `transformers.AutoModelForCausalLM.from_pretrained("/path/to/converted/checkpoint/dir")`
The actual load step 3. throws an error because it tries to call `torch.load(checkpoint_file, weights_only=True)` internally when it sees that no safetensors format checkpoint is available: [transformers/modeling_utils.py#L529-L535](https://github.com/huggingface/transformers/blob/main/src/transformers/modeling_utils.py#L529-L535)
This can be bypassed by setting `weights_only=False` but this is not the desired solution, rather, it would be great if there was a way to export a trained litgpt model to `model.safetensors` format directly, rather than to the `pytorch_model.bin` file format.
What do you think?
I couldn't find any mention of this hiccup within litgpt, or elsewhere really actually - the only "safetensors" related things here are on the `scripts/download.py` side for bringing hf safetensors format models _into_ litgpt.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read scripts/convert_pretrained_checkpoint.py and scripts/convert_lit_checkpoint.py first, then compare their output with the Transformers loading path linked in the issue. Confirm how the converted checkpoint is written and identify the supported export path for model.safetensors. Done means a converted LitGPT checkpoint can be loaded by AutoModelForCausalLM.from_pretrained without disabling weights-only loading.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- huggingface, python, pytorch
- Domain
- ai, machine-learning, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100