feat(ml): fuse two embedding models and protect the ML service with a token
This commit is contained in:
1 parent
bc00d6901f
commit
b24e5ff906
63 files changed
+2287
-276
No files matched your search
+24
-10
@@ -1,10 +1,15 @@
|
||||
.DEFAULT_GOAL := help
|
||||
UV ?= uv
|
||||
API_PREPARED ?= 0
|
||||
# Local directory of the pinned model weights for test-model and run.
|
||||
ML_MODEL_DIR ?= $(HOME)/.cache/lincodex-ml/giga-480m
|
||||
MODEL_LOCK := model/giga-embeddings-480m.lock.json
|
||||
.PHONY: help install generate check-generated check-pydantic-compat build run fmt fmt-check lint lint-fix typecheck test test-contract test-model model-fetch check verify
|
||||
# Local directories of the pinned model weights for test-model and run.
|
||||
ML_GIGA_MODEL_DIR ?= $(HOME)/.cache/lincodex-ml/giga-480m
|
||||
ML_QWEN3_MODEL_DIR ?= $(HOME)/.cache/lincodex-ml/qwen3-0.6b
|
||||
GIGA_LOCK := model/giga-embeddings-480m.lock.json
|
||||
QWEN3_LOCK := model/qwen3-embedding-0.6b.lock.json
|
||||
# Where cuda-requirements writes the runtime requirements of a CUDA host.
|
||||
CUDA_REQUIREMENTS ?= dist/requirements-cuda.txt
|
||||
CUDA_TORCH_LOCAL ?= cu128
|
||||
.PHONY: help install generate check-generated check-pydantic-compat build run fmt fmt-check lint lint-fix typecheck test test-contract test-model model-fetch cuda-requirements check verify
|
||||
|
||||
help: ## Show available ML service commands.
|
||||
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z0-9_-]+:.*## / {printf "%-14s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
@@ -28,8 +33,8 @@ check-pydantic-compat: ## Generate Pydantic models from the OpenAPI 3.2 compatib
|
||||
build: ## Build the service wheel.
|
||||
$(UV) build
|
||||
|
||||
run: ## Run the operational API on port 8000.
|
||||
$(UV) run uvicorn lincodex_ml.main:app --host 0.0.0.0 --port 8000
|
||||
run: ## Run the operational API on 127.0.0.1:8000 (ML_LISTEN_HOST and ML_LISTEN_PORT change it).
|
||||
$(UV) run python -m lincodex_ml.serve
|
||||
|
||||
fmt: ## Format Python source.
|
||||
$(UV) run ruff format src tests scripts
|
||||
@@ -52,11 +57,20 @@ test: ## Run service tests.
|
||||
test-contract: ## Check implementation against the shared OpenAPI contract.
|
||||
$(UV) run pytest tests/test_contract.py
|
||||
|
||||
model-fetch: ## Download the pinned model files into ML_MODEL_DIR and verify their SHA-256 (about 1 GB).
|
||||
$(UV) run python -m lincodex_ml.model_files fetch --lock $(MODEL_LOCK) --out "$(ML_MODEL_DIR)"
|
||||
model-fetch: ## Download the pinned files of both models into ML_GIGA_MODEL_DIR and ML_QWEN3_MODEL_DIR and verify their SHA-256 (about 2.2 GB).
|
||||
$(UV) run python -m lincodex_ml.model_files fetch --lock $(GIGA_LOCK) --out "$(ML_GIGA_MODEL_DIR)"
|
||||
$(UV) run python -m lincodex_ml.model_files fetch --lock $(QWEN3_LOCK) --out "$(ML_QWEN3_MODEL_DIR)"
|
||||
|
||||
test-model: ## Run the slow parity test of the real model against the research vectors (needs model-fetch).
|
||||
ML_MODEL_DIR="$(ML_MODEL_DIR)" $(UV) run pytest -m slow -p no:cacheprovider tests/test_giga_model.py
|
||||
test-model: ## Run the slow parity tests of both real models against the research vectors (needs model-fetch; ML_TEST_DEVICE=cuda on a GPU).
|
||||
ML_GIGA_MODEL_DIR="$(ML_GIGA_MODEL_DIR)" ML_QWEN3_MODEL_DIR="$(ML_QWEN3_MODEL_DIR)" $(UV) run pytest -m slow -p no:cacheprovider tests/test_giga_model.py tests/test_qwen3_model.py
|
||||
|
||||
cuda-requirements: ## Write the locked runtime requirements with the CUDA build of the locked torch version to CUDA_REQUIREMENTS (for a GPU host).
|
||||
@mkdir -p "$(dir $(CUDA_REQUIREMENTS))"
|
||||
@version=$$($(UV) export --frozen --no-dev --no-hashes --no-emit-project --format requirements.txt | sed -n 's/^torch==\([0-9.]*\).*/\1/p' | head -n 1) && \
|
||||
test -n "$$version" && \
|
||||
$(UV) export --frozen --no-dev --no-hashes --no-emit-project --format requirements.txt | grep -v '^torch==' > "$(CUDA_REQUIREMENTS)" && \
|
||||
printf 'torch==%s+%s\n' "$$version" "$(CUDA_TORCH_LOCAL)" >> "$(CUDA_REQUIREMENTS)" && \
|
||||
printf 'wrote %s (torch %s+%s)\n' "$(CUDA_REQUIREMENTS)" "$$version" "$(CUDA_TORCH_LOCAL)"
|
||||
|
||||
check: ## Run formatting, lint, type, tests, and package build.
|
||||
$(MAKE) fmt-check lint typecheck test build
|
||||
|
||||
Reference in new issue
Block a user