Skip to content
lernexPublic

About

The Lernex inference engine: built from scratch for the Metis models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Dromos

The inference engine for Lernex's Metis models, written from scratch for them. Models: Metis-1.6 on Hugging Face. Architecture: docs/ARCHITECTURE.md. Kernel ABI: engine/cuda/kernels.h.

Install

curl -fsSL https://github.com/lernex/dromos/releases/latest/download/install.sh | sh   # Linux, macOS
irm https://github.com/lernex/dromos/releases/latest/download/install.ps1 | iex           # Windows 10 1809+ x64

Either installer picks the build for the machine (CUDA 12 on an NVIDIA GPU with a new enough driver, Metal on Apple silicon, the CPU otherwise), checks it against the release's SHA256SUMS, and puts dromos on your PATH; run it again to upgrade, or dromos update. Also pip install dromos, brew trust --formula lernex/tap/dromos && brew install lernex/tap/dromos, and docker run --gpus all -p 8080:8080 ghcr.io/lernex/dromos praxis. Where each puts things, and the flavors: docs/RELEASE.md. Then:

dromos doctor          # the backend this machine runs and what it can do
dromos run praxis      # chat in the terminal (downloads the model the first time)
dromos serve logos     # the OpenAI API on http://127.0.0.1:8080/v1

Build from source

cmake -B build -DLX_ARCHS=all -DLX_DECODE_PROGRAM=OFF && cmake --build build -j

CMake 3.28 or newer, a C++20 compiler, and the CUDA toolkit 12.8 or newer (the release is built with 12.8). LX_ARCHS names the GPUs the build runs on: all is RTX 30 / A100 up to RTX 50, H100 and B200; the default, 120a-real, is RTX 50 only and compiles fastest. -DLX_DECODE_PROGRAM=OFF leaves out the opt-in persistent decode program, as the release does: its kernel takes about 30 minutes per architecture to compile, and more than 14 GB of memory for sm_80. Without an NVIDIA GPU, -DLX_BACKEND_CUDA=OFF builds the CPU backend only; on macOS the default is the Metal backend. The binary is build/dromos.

Develop

scripts/remote.sh <slot> test        # build on the GPU server; the kernel tests and the C++ unit tests
scripts/remote.sh <slot> run ./build/dromos_tests   # the C++ tests (scheduler, digests, hub)
LX_ARCHS=all scripts/remote.sh <slot> build   # every architecture: RTX 30 / A100 up to RTX 50, H100, B200
scripts/remote.sh <slot> x 'LX_BIN=build/dromos LX_MODEL=DIR $PY -m pytest -q tests/server'   # the server, end to end
scripts/remote.sh <slot> x 'build/dromos doctor MODEL_DIR'   # the GPU, and the plan for a model
scripts/remote.sh <slot> x 'build/dromos tune MODEL_DIR --out PATH'   # time the kernel variants on this GPU

Commands: dromos run MODEL (chat), dromos serve MODEL (OpenAI API), dromos pull MODEL, dromos list, dromos bench MODEL --streams 1,8,32,64, dromos update (the latest release, for installs made from a release tarball), dromos version. MODEL is praxis, logos, metis-1.7-logos-research-preview, an alias with a format (praxis:fp8, metis-1.7-logos-research-preview:nvfp4), a folder, or owner/name on the hub.

Weights run in the format the file stores: no hidden quantization, so every speed is the speed of a named format. --weights bf16|int8|fp8|nvfp4|bf16x (run, serve, bench, eval, spec, doctor) names another: INT8 and FP8 round-to-nearest from a wider file, BF16X the lossless encoding of a BF16 one, NVFP4 only from the GPTQ NVFP4 folder, nothing wider than the file. A model decodes its BF16 tensors (every one of a BF16 model, the wide ones of a quantized model) from lossless BF16X copies when they fit (--no-bf16x turns them off), and a model that does not fit the GPU runs with its routed experts offloaded rather than in a narrower format. dromos doctor MODEL shows every format, what fits, and the decode ceiling of each.

Batched steps pick each matrix product's algorithm for the rows in the step, so a request's tokens can depend on what else is decoding beside it, as in other engines. --batch-invariant (run, serve, bench, spec) runs every row count of a product on one algorithm instead: a request gets the same bits whatever shares its steps, about 15% slower at 32 streams. dromos eval always runs this way. Speculation never changes the output in either mode.

A streamed request with "return_progress": true hears how far its prompt has been read before the first token, as llama.cpp's server says it: chunks with empty choices and "prompt_progress": {"total", "cache", "processed", "time_ms"}, where processed counts the tokens the prefix cache restored, so the new reading is processed - cache of total - cache. One comes as the request starts, one after each step that read part of the prompt (once the device has finished it), and the last says processed == total. Only such a request pays a device sync per prefill step.

A thinking reply that samples its end of turn before it has closed its reasoning goes on instead of ending there: the engine takes that token as the reasoning's end, once a reply, and the model writes its answer and ends the turn itself. Metis-1.7 Logos Research Preview does this on questions about images, where the reply would otherwise be reasoning with no content. The reply's choice then carries "reasoning_closed_by_engine": true (a stream's last chunk does), /health counts them under reasoning, and a request with "close_reasoning": false gets the reply as the model wrote it. docs/METIS17.md has what it measures.

Images

Metis-1.7 Logos Research Preview reads images. Send them as OpenAI image_url parts of a user message, as a data: URL or an http(s) URL:

dromos serve metis-1.7-logos-research-preview:nvfp4 &
curl -s http://127.0.0.1:8080/v1/chat/completions -H 'content-type: application/json' -d @- <<JSON
{"model": "metis-1.7-logos-research-preview",
 "messages": [{"role": "user", "content": [
   {"type": "image_url", "image_url": {"url": "data:image/png;base64,$(base64 < photo.png | tr -d '\n')"}},
   {"type": "text", "text": "What is in this picture?"}]}]}
JSON

PNG, JPEG, WEBP (with libwebp installed), GIF, BMP, TGA and PNM are read, up to 16 images a request (--max-images N; --no-image-urls refuses http(s) URLs). An image larger than about a megapixel is scaled down to fit, and each 32 x 32 px cell of it is one prompt token, so a 1024 x 1024 image is 1,024 tokens. In the terminal, dromos run MODEL --image photo.png attaches a file to the first message, and /image PATH attaches one to the next. How images are read, and what the tower costs in memory: docs/METIS17.md, "Images".

Prompts already read

A conversation's next request reads only what is new. Metis keeps a recurrent state that cannot be cut back, so the engine keeps whole snapshots of it at a prompt's cuts: every 512 tokens, and wherever a chat turn ends (the end of the system turn with its tools, the end of each message). Every cut depends only on the tokens before it, so a request that starts from a snapshot computes exactly what a cold read computes, bit for bit (dromos_prefix_check). Snapshots live in GPU memory, spill to host memory, and the ones a conversation picks up from are written to disk while the server is idle (--prefix-dir DIR, by default the cache's prefix/ folder, --prefix-disk GB, 4 by default, --no-prefix-disk), so a server stopped after a quiet spell, or started tomorrow, picks the conversation up where it was and a new conversation with the same instructions and tools reads none of them again. A file is read only by an engine of the same model, format, device and build.

Usage says what was restored: usage.prompt_tokens_details.cached_tokens. The engine never reads ahead on its own.

A client can ask for a conversation to be read before its next request: /v1/chat/completions with "prefill_only": true and the next request's messages, its final message empty. The answer is {"object": "prefill", "prompt_tokens", "cached_tokens", "read_tokens", "held_tokens", "time_ms"} once the conversation before that message is held. A request that arrives while the read is still going, and shares it, takes it over mid-read; one that shares nothing and finds no slot free takes its slot, so a read ahead never makes a request that answers wait.

LX_ARCH_OVERRIDE=80|86|89|90 (or --lx-arch=N on the kernel tests) makes a newer card run the code paths of an older architecture, so the fallbacks are tested on one GPU.

About

The Lernex inference engine: built from scratch for the Metis models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages