feat(ml): fuse two embedding models and protect the ML service with a token

This commit is contained in:
shira committed 2026-10-11 14:40:52 +03:00
1 parent bc00d6901f
commit b24e5ff906
63 files changed
+2287 -276

No files matched your search

+15 -9
View File
@@ -1,7 +1,9 @@
"""Parity of the real model with the research vectors.
"""Parity of the real Giga model with the research vectors.
Marked slow: it needs the pinned weights in ML_MODEL_DIR (fetch them with
`make -C ml model-fetch`) and runs only with `make -C ml test-model`.
Marked slow: it needs the pinned weights in ML_GIGA_MODEL_DIR (fetch them with
`make -C ml model-fetch`) and runs only with `make -C ml test-model`. The
files are verified against the checked-in lock file. ML_TEST_DEVICE=cuda runs
it on the GPU in float32.
"""
import json
@@ -13,8 +15,10 @@ import pytest
from lincodex_ml.inference.embedder import InputKind
GOLDEN = Path(__file__).resolve().parent / "data" / "giga_golden.json"
# CPU float32 against the research CUDA float32 run; measured differences are
ROOT = Path(__file__).resolve().parents[1]
GOLDEN = ROOT / "tests" / "data" / "giga_golden.json"
LOCK = ROOT / "model" / "giga-embeddings-480m.lock.json"
# float32 against the research CUDA float32 run; measured differences are
# below 1e-6 per component.
MAX_COMPONENT_DIFFERENCE = 1e-4
@@ -23,17 +27,19 @@ pytestmark = pytest.mark.slow
@pytest.fixture(scope="module")
def model_dir() -> Path:
raw = os.environ.get("ML_MODEL_DIR", "")
raw = os.environ.get("ML_GIGA_MODEL_DIR", "")
if not raw:
pytest.skip("ML_MODEL_DIR is not set")
pytest.skip("ML_GIGA_MODEL_DIR is not set")
return Path(raw)
def test_real_model_reproduces_the_research_vectors_deterministically(model_dir: Path) -> None:
from lincodex_ml.inference.giga import GigaEmbedder, configure_torch
from lincodex_ml.inference.giga import GigaEmbedder
from lincodex_ml.inference.torch_support import configure_torch, prepare_device
configure_torch(4)
embedder = GigaEmbedder(model_dir, max_tokens=1024, verify_weights=True)
device = prepare_device(os.environ.get("ML_TEST_DEVICE", "cpu"), 0)
embedder = GigaEmbedder(model_dir, LOCK, max_tokens=1024, verify_weights=True, device=device)
golden = json.loads(GOLDEN.read_text(encoding="utf-8"))
assert embedder.info.model_id == golden["model"]
assert embedder.info.revision == golden["revision"]