Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] If Transformers 4.46.0, use processing_class instead of tokenizer when saving #3038

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions sentence_transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,13 @@ def _save(self, output_dir: str | None = None, state_dict=None) -> None:

self.model.save_pretrained(output_dir, safe_serialization=self.args.save_safetensors)

if self.tokenizer is not None:
self.tokenizer.save_pretrained(output_dir)
# Transformers v4.46.0 changed the `tokenizer` attribute to a more general `processing_class` attribute
if parse_version(transformers_version) >= parse_version("4.46.0"):
if self.processing_class is not None:
self.processing_class.save_pretrained(output_dir)
else:
if self.tokenizer is not None:
self.tokenizer.save_pretrained(output_dir)

# Good practice: save your training arguments together with the trained model
torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME))
Expand Down