huggingface / huggingface/setfit
Model checkpoints saved during the training are unusable
- Dominant language
- Jupyter Notebook
- Stars
- 2.8k
- Forks
- 267
- Avg merge
- 36m
- Merged PRs (30d)
- 5
Description
Step 1: Train a model:
```
model_name = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
model = SetFitModel.from_pretrained(
model_name,
multi_target_strategy="multi-output",
use_differentiable_head=True,
head_params={"out_features": len(id2label)},
)
args = TrainingArguments(
output_dir=MODEL_DIR,
batch_size=32,
num_epochs=20,
evaluation_strategy='epoch',
save_strategy='epoch',
save_total_limit=4,
sampling_strategy='unique',
)
args.eval_strategy = args.evaluation_strategy
trainer = Trainer(
model=model,
args=args,
train_dataset=dataset["train"],
eval_dataset=dataset["validation"],
metric=batch_multi_label_metric,
)
trainer.train()
```
Step 2: Save the model explicitly. The examples in docs always do it, but there's no clear communication that this is **absolutely necessary** and, in fact, **the only way** to use the model later:
```
model.save_pretrained(MODEL_DIR / "explicit_save")
```
Step 3: Try to load from the latest checkpoint
```
checkpoint_model = SetFitModel.from_pretrained(
MODEL_DIR / "step_26560",
)
```
Without any warning, this model will not perform well, because the classifier (head) weights have not been loaded or even saved in the first place. If we compare this model's head with the one we saved explicitly, the difference is obvious:
```
explicit_model = SetFitModel.from_pretrained(
MODEL_DIR / "explicit_save",
)
checkpoint_head_weights = next(checkpoint_model.model_head.named_parameters())[1]
explicit_head_weights = next(explicit_model.model_head.named_parameters())[1]
fig1 = px.line(checkpoint_head_weights.detach().numpy().ravel())
fig2 = px.line(explicit_head_weights.detach().numpy().ravel())
```


So if I didn't mess something up, my proposal would be to ether make this behavior clear to the user, or better to fix it so that the checkpoints would be usable.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.