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

Sort the files and save the .bin model file for backwards compatibility #86

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions molfeat/trans/pretrained/hf_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def save(cls, model: HFExperiment, path: str, clean_up: bool = False):
# we can save both the tokenizer and the model to the same path
model.model.save_pretrained(local_path)
model.tokenizer.save_pretrained(local_path)

# With transformers>=4.35.0, models are by default saved as safetensors.
# For backwards compatibility, we also save the model as the older pickle-based format.
model.model.save_pretrained(local_path, safe_serialization=False)

dm.fs.copy_dir(local_path, path, force=True, progress=True, leave_progress=False)
logger.info(f"Model saved to {path}")
# clean up now
Expand Down
2 changes: 1 addition & 1 deletion molfeat/utils/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def sha256sum(filepath: Union[str, os.PathLike]):
else:
files = [filepath]
file_hash = hashlib.sha256()
for filepath in files:
for filepath in sorted(files):
with fsspec.open(filepath) as f:
file_hash.update(f.read()) # type: ignore
file_hash = file_hash.hexdigest()
Expand Down