Lightning-AI / Lightning-AI/litgpt

Error loading converted litgpt checkpoints in `pytorch_model.bin` format using huggingface `AutoModelForCausalLM`

Open
#1,086 7 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.