Lightning-AI / Lightning-AI/litgpt
Failed to load the finetuned model with `AutoModelForCausalLM.from_pretrained(name, state_dict=state_dict)`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13.7k
- Forks
- 1.5k
- Avg merge
- 15h 37m
- Merged PRs (30d)
- 1
Description
I fine-tuned llama3-8b with Lora and followed the tutorial in the repository to convert the final result into `model.pth`. However, when I try to load the fine-tuned weights into the model using `AutoModelForCausalLM.from_pretrained`, I am unable to do so correctly. Below is my test:
```python
state_dict = torch.load('out/convert/hf-llama3-instruct-esconv/model.pth')
print("state_dict: ", state_dict)
model = AutoModelForCausalLM.from_pretrained('checkpoints/meta-llama/Meta-Llama-3-8B',
device_map=device_map, torch_dtype=torch.float16,
state_dict=state_dict)
print("model.weights", model.state_dict())
```
But I found that the `state_dict` of `torch.load` doesn't equal to the `model.state_dict()`, as shown following:
torch.load:

model.state_dict()

I noticed that even though I passed the `state_dict`, `from_pretrained` still returns the weights of the model loaded by name. Did I make any mistakes in my code, and how can I solve this? Thanks!
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
Start with the repository tutorial's conversion to model.pth, then reproduce the AutoModelForCausalLM.from_pretrained call using the saved state_dict. Compare the keys and loading behavior with model.state_dict(); done means explaining whether this loading path is supported and documenting the correct way to load the converted weights.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- ai, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100