2023-04-28 17:08:41 +02:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from haystack.modeling.model.language_model import (
|
|
|
|
get_language_model,
|
|
|
|
HFLanguageModel,
|
|
|
|
HFLanguageModelNoSegmentIds,
|
|
|
|
HFLanguageModelWithPooler,
|
|
|
|
DPREncoder,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-05-08 19:05:21 +02:00
|
|
|
@pytest.mark.integration
|
2023-04-28 17:08:41 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"pretrained_model_name_or_path, lm_class",
|
|
|
|
[
|
|
|
|
("google/bert_uncased_L-2_H-128_A-2", HFLanguageModel),
|
|
|
|
("google/electra-small-generator", HFLanguageModelWithPooler),
|
|
|
|
("distilbert-base-uncased", HFLanguageModelNoSegmentIds),
|
|
|
|
("deepset/bert-small-mm_retrieval-passage_encoder", DPREncoder),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_basic_loading(pretrained_model_name_or_path, lm_class, monkeypatch):
|
|
|
|
monkeypatch.setattr(lm_class, "__init__", lambda self, *a, **k: None)
|
|
|
|
lm = get_language_model(pretrained_model_name_or_path)
|
|
|
|
assert isinstance(lm, lm_class)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_basic_loading_unknown_model():
|
2023-10-24 12:13:12 -05:00
|
|
|
with pytest.raises(RuntimeError):
|
2023-04-28 17:08:41 +02:00
|
|
|
get_language_model("model_that_doesnt_exist")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_basic_loading_with_empty_string():
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
get_language_model("")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.unit
|
|
|
|
def test_basic_loading_invalid_params():
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
get_language_model(None)
|