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
@@ -0,0 +1,42 @@
|
||||
# systemd user unit of the ML service on a GPU host without Docker. Install it
|
||||
# as ~/.config/systemd/user/lincodex-ml.service of the service user (with
|
||||
# lingering enabled) and keep the settings and the token in the environment
|
||||
# file, mode 600; see docs/en/DEPLOY.md#ml-service-on-a-gpu-host.
|
||||
#
|
||||
# %h is the home directory of the user: the layout below is
|
||||
# %h/lincodex-ml/app/ml the ml/ directory of the release
|
||||
# %h/lincodex-ml/venv the virtualenv (make -C ml cuda-requirements)
|
||||
[Unit]
|
||||
Description=Lincodex ML embedding service
|
||||
StartLimitIntervalSec=600
|
||||
StartLimitBurst=10
|
||||
|
||||
[Service]
|
||||
Type=exec
|
||||
WorkingDirectory=%h/lincodex-ml/app/ml
|
||||
EnvironmentFile=%h/.config/lincodex-ml/ml.env
|
||||
Environment=PYTHONPATH=%h/lincodex-ml/app/ml/src
|
||||
Environment=PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
|
||||
# The models are read from local files only; nothing is downloaded.
|
||||
Environment=HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 HF_HUB_DISABLE_TELEMETRY=1 HF_HUB_DISABLE_PROGRESS_BARS=1
|
||||
# Thread pools of the CPU work around the GPU (tokenizer, pooling).
|
||||
Environment=OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 TOKENIZERS_PARALLELISM=false
|
||||
# A permanent load failure ends the process, so systemd restarts it later.
|
||||
Environment=ML_EXIT_ON_LOAD_FAILURE=true
|
||||
ExecStart=%h/lincodex-ml/venv/bin/python -m lincodex_ml.serve
|
||||
Restart=on-failure
|
||||
RestartSec=15
|
||||
TimeoutStopSec=30
|
||||
# The process with both models on CUDA keeps about 2.6 GiB resident (peak
|
||||
# 2.9 GiB); the limits keep a fault from starving the other host services.
|
||||
MemoryHigh=5G
|
||||
MemoryMax=6G
|
||||
CPUQuota=400%
|
||||
TasksMax=512
|
||||
LimitNOFILE=4096
|
||||
Nice=5
|
||||
NoNewPrivileges=yes
|
||||
UMask=0077
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
@@ -0,0 +1,25 @@
|
||||
# Settings of the ML service on a GPU host; copy to
|
||||
# ~/.config/lincodex-ml/ml.env (mode 600) and replace the placeholders. The
|
||||
# token is a secret: generate it on the host, for example
|
||||
# python3 -c 'import secrets; print(secrets.token_hex(32))'
|
||||
# and give the same value to the backend as ML_SERVICE_TOKEN.
|
||||
ML_EMBEDDER=giga,qwen3
|
||||
ML_DEVICE=cuda
|
||||
# float16 fits both models in about 2.4 GiB of VRAM; see the precision note in
|
||||
# docs/en/DEPLOY.md#ml-service-on-a-gpu-host before changing it.
|
||||
ML_DTYPE=float16
|
||||
# Allocator cap of the process; the CUDA context adds about 130 MiB.
|
||||
ML_CUDA_MEMORY_LIMIT_MB=2300
|
||||
ML_TORCH_THREADS=4
|
||||
ML_MICRO_BATCH=1
|
||||
ML_VERIFY_WEIGHTS=true
|
||||
# A private address of the host, never 0.0.0.0.
|
||||
ML_LISTEN_HOST=<private-ip>
|
||||
ML_LISTEN_PORT=<port>
|
||||
# Directories with the pinned files (a Hugging Face snapshot directory works)
|
||||
# and the lock files of the release that pin them.
|
||||
ML_GIGA_MODEL_DIR=<directory of ai-sage/Giga-Embeddings-instruct-480M-0826 at the pinned revision>
|
||||
ML_GIGA_MODEL_LOCK=<release>/ml/model/giga-embeddings-480m.lock.json
|
||||
ML_QWEN3_MODEL_DIR=<directory of Qwen/Qwen3-Embedding-0.6B at the pinned revision>
|
||||
ML_QWEN3_MODEL_LOCK=<release>/ml/model/qwen3-embedding-0.6b.lock.json
|
||||
ML_SERVICE_TOKEN=<generated on the host>
|
||||
Reference in new issue
Block a user