I’m trying to fine-tune Phi 3.5 Vision using transformers
. However, I’m running into an issue trying to save the model during or after training. See below for a minimal reproducible example.
Does anyone have any pointers? This issue has been reported in a few other locations - see below.
- Saving Phi 3 vision fails due to tensor sharing · Issue #32354 · huggingface/transformers · GitHub
- Using Trainer to save a Bartforsequenceclassification model
The error suggests “saving using safe_serialization=False
”…but I’m not sure what the implications of that are.
Minimal Reproducible Example
from transformers import AutoModelForCausalLM
model_id = "microsoft/Phi-3.5-vision-instruct"
model = AutoModelForCausalLM.from_pretrained(
model_id, device_map="cuda", trust_remote_code=True, torch_dtype="auto"
)
model.save_pretrained("out", safe_serialization=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/AWSBedrockScienceModelDistillationTraining/.venv/lib/python3.12/site-packages/transformers/modeling_utils.py", line 2958, in save_pretrained
raise RuntimeError(
RuntimeError: The weights trying to be saved contained shared tensors [{'model.embed_tokens.weight', 'model.vision_embed_tokens.wte.weight'}] that are mismatching the transformers base configuration. Try saving using `safe_serialization=False` or remove this tensor sharing.