Skip to content
Closed
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: 4 additions & 1 deletion model2vec/hf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def load_pretrained(
tokenizer_file = "tokenizer.json"
config_name = "config.json"

folder_or_repo_path = Path(folder_or_repo_path)
# This check allows users to pass other things than Path objects, e.g.,
# cloudpathlib.Anypath.
if isinstance(folder_or_repo_path, str):
folder_or_repo_path = Path(folder_or_repo_path)

local_folder = folder_or_repo_path / subfolder if subfolder else folder_or_repo_path

Expand Down
11 changes: 8 additions & 3 deletions model2vec/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,14 @@ def load_local(cls: type[StaticModel], path: PathLike) -> StaticModel:
:return: A StaticModel
:raises: ValueError if the path is not a directory.
"""
path = Path(path)
if not path.is_dir():
raise ValueError(f"Path {path} is not a directory.")
if isinstance(path, str):
path = Path(path)

if isinstance(path, Path):
# Only check if we're sure this is a path.
# It could be a cloudpathlib path, or something else.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this if statement path is always a Path. I.e., AnyPath doesn't have Path as base class, so this comment isn't true

if not path.is_dir():
raise ValueError(f"Path {path} is not a directory.")

embeddings, tokenizer, config = load_local_model(path)

Expand Down