Skip to content

Commit

Permalink
Merge pull request #86 from datamol-io/fix/checksum
Browse files Browse the repository at this point in the history
Sort the files and save the .bin model file for backwards compatibility
  • Loading branch information
maclandrol committed Nov 11, 2023
2 parents 97855c6 + 72e3fca commit f8579b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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

0 comments on commit f8579b3

Please sign in to comment.