Skip to content
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
7 changes: 6 additions & 1 deletion model2vec/persistence/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from model2vec.modelcards import get_metadata_from_readme
from model2vec.persistence.datamodels import FOLDER_LAYOUTS, Layout
from model2vec.persistence.hf import maybe_get_cached_model_path
from model2vec.persistence.utils import SilentTqdm
from model2vec.utils import SafeOpenProtocol

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -142,8 +143,12 @@ def _resolve_folder(folder_or_repo_path: Path, token: str | None, force_download
if folder := maybe_get_cached_model_path(str(folder_or_repo_path)):
return folder

# We use `tqdm_class=SilentTqdm` to disable download progress bars.
# No partial because that doesn't always work, this is safer.
folder = Path(
huggingface_hub.snapshot_download(str(folder_or_repo_path.as_posix()), repo_type="model", token=token)
huggingface_hub.snapshot_download(
str(folder_or_repo_path.as_posix()), repo_type="model", token=token, tqdm_class=SilentTqdm
)
)

return folder
Expand Down
10 changes: 10 additions & 0 deletions model2vec/persistence/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Any

from tqdm.auto import tqdm


class SilentTqdm(tqdm):
def __init__(self, *args: Any, **kwargs: Any) -> None:
"""Init a tqdm that's disabled by default."""
kwargs["disable"] = True
super().__init__(*args, **kwargs)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies = [
"safetensors",
"tokenizers>=0.20",
"tqdm",
"huggingface-hub>=1.0.0",
]

[build-system]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from model2vec.model import StaticModel
from model2vec.persistence.hf import maybe_get_cached_model_path
from model2vec.persistence.utils import SilentTqdm


def test_local_loading(mock_static_model: StaticModel) -> None:
Expand Down Expand Up @@ -96,6 +97,12 @@ def test_save_pretrained_with_weights_and_mapping(tmp_path: Path, mock_tokenizer
np.testing.assert_array_equal(loaded_model.token_mapping, mapping)


def test_silent_tqdm() -> None:
"""Test that SilentTqdm is disabled by default."""
bar = SilentTqdm(range(3))
assert bar.disable is True


def test_maybe_get_cached_model_path() -> None:
"""Test cached model path."""
model_id = "t/t"
Expand Down
2 changes: 2 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading