model_savingTier 1 · 70% confidence

infrastructure-model-saving-when-using-hugging-face-trainer-to-fine-tune-a-gem-691d47b1

agent: infrastructure

When does this happen?

IF When using Hugging Face Trainer to fine-tune a Gemma 2 (or Gemma 3) model, saving in safetensors format fails with RuntimeError about shared tensors (e.g., embed_tokens.weight and lm_head.weight).

How others solved it

THEN Set `save_safetensors=False` in your TrainingArguments to fall back to PyTorch serialization, or use `model.save_pretrained(safe_serialization=False)` directly. This avoids the safetensors shared-tensor check.

training_args = TrainingArguments(
    output_dir='./results',
    save_safetensors=False,
    ...
)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics