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
8 changes: 4 additions & 4 deletions model2vec/distill/distillation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def distill_from_model(
pca_dims: PCADimType = 256,
sif_coefficient: float | None = 1e-4,
token_remove_pattern: str | None = r"\[unused\d+\]",
quantize_to: DType | str = DType.Float16,
quantize_to: DType | str = DType.Float32,
Comment thread
stephantul marked this conversation as resolved.
Resolved
pooling: PoolingMode | str = PoolingMode.MEAN,
) -> StaticModel:
"""Distill a staticmodel from a sentence transformer.
Expand Down Expand Up @@ -120,7 +120,7 @@ def random_init(
dim: int = 256,
sif_coefficient: float | None = 1e-4,
token_remove_pattern: str | None = r"\[unused\d+\]",
quantize_to: DType | str = DType.Float16,
quantize_to: DType | str = DType.Float32,
seed: int = 42,
trust_remote_code: bool = False,
) -> StaticModel:
Expand Down Expand Up @@ -163,7 +163,7 @@ def init_from_tokenizer(
dim: int = 256,
sif_coefficient: float | None = 1e-4,
token_remove_pattern: str | None = r"\[unused\d+\]",
quantize_to: DType | str = DType.Float16,
quantize_to: DType | str = DType.Float32,
seed: int = 42,
) -> StaticModel:
"""Create a staticmodel with random embeddings from a tokenizer.
Expand Down Expand Up @@ -327,7 +327,7 @@ def distill(
sif_coefficient: float | None = 1e-4,
token_remove_pattern: str | None = r"\[unused\d+\]",
trust_remote_code: bool = False,
quantize_to: DType | str = DType.Float16,
quantize_to: DType | str = DType.Float32,
pooling: PoolingMode | str = PoolingMode.MEAN,
) -> StaticModel:
"""Distill a staticmodel from a sentence transformer.
Expand Down
6 changes: 5 additions & 1 deletion tests/test_trainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, TypeVar
from unittest.mock import patch

import datasets
import numpy as np
import pytest
import torch
Expand Down Expand Up @@ -1759,8 +1760,11 @@ def test_regressor_fit_on_fixed_size_vector_column(mock_vectors: np.ndarray, moc
assert model.out_dim == 2


def test_fit_rejects_iterable_datasets(mock_vectors: np.ndarray, mock_tokenizer: Tokenizer) -> None:
def test_fit_rejects_iterable_datasets(
mock_vectors: np.ndarray, mock_tokenizer: Tokenizer, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Iterable datasets and their columns have no length, and are rejected."""
monkeypatch.setattr(datasets.config, "TORCH_AVAILABLE", False)
iterable = Dataset.from_dict({"text": _TRAIN_TEXTS, "label": ["a", "b"] * 4}).to_iterable_dataset()
model = StaticModelForClassification(vectors=torch.from_numpy(mock_vectors).float(), tokenizer=mock_tokenizer)
with pytest.raises(ValueError, match="X comes from an iterable"):
Expand Down
Loading