From 8f1b2a02be4da92a3401f1f20f645bde2be196a9 Mon Sep 17 00:00:00 2001 From: stephantul Date: Fri, 27 Nov 2026 10:49:39 +0100 Subject: [PATCH] fix: distill models are float32, small test fix --- model2vec/distill/distillation.py | 8 ++++---- tests/test_trainable.py | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/model2vec/distill/distillation.py b/model2vec/distill/distillation.py index 66fd06d..a7ac304 100644 --- a/model2vec/distill/distillation.py +++ b/model2vec/distill/distillation.py @@ -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, pooling: PoolingMode | str = PoolingMode.MEAN, ) -> StaticModel: """Distill a staticmodel from a sentence transformer. @@ -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: @@ -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. @@ -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. diff --git a/tests/test_trainable.py b/tests/test_trainable.py index 8160cb5..42bb736 100644 --- a/tests/test_trainable.py +++ b/tests/test_trainable.py @@ -5,6 +5,7 @@ from typing import Any, TypeVar from unittest.mock import patch +import datasets import numpy as np import pytest import torch @@ -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"):