File size: 2,575 Bytes
878092c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# RightNow Mini's engine: one command, an OpenAI-compatible server on one GPU.
#
#   MODEL_DIR=/path/to/model DRAFTER_DIR=/path/to/Inkling-2-Mini-DFlash2 bash engine/serve.sh
#
# What it is: vLLM (the image below, pinned by digest) with speculative decoding through a prepared copy of the
# published draft model `incoai/Inkling-2-Mini-DFlash2` (see engine/build_drafter.py for what is prepared and why).
# The model checks every drafted token. Measured speed and the token-by-token comparison with the stock engine are
# in results/speed.md.
#
# Variables: GPU (0), PORT (8000), HOST (127.0.0.1), NAME (rightnow-mini), SERVED (rightnow-mini), DRAFT=0 for no drafting.
set -eu
MODEL_DIR=${MODEL_DIR:?the folder with the model weights}
GPU=${GPU:-0}; PORT=${PORT:-8000}; HOST=${HOST:-127.0.0.1}; NAME=${NAME:-rightnow-mini}; SERVED=${SERVED:-rightnow-mini}
IMAGE=${IMAGE:-vllm/vllm-openai@sha256:3f80650e404965216b36042caca709598d4163342366d86c4247a06541eca81d}
DOCKER=${DOCKER:-docker}
HERE=$(cd "$(dirname "$0")" && pwd)
ARGS=(--model /model --served-model-name "$SERVED" --tensor-parallel-size 1 --reasoning-parser inkling
      --enable-auto-tool-choice --tool-call-parser inkling --host "$HOST" --port "$PORT")
MOUNTS=(-v "$MODEL_DIR":/model:ro)
if [ "${DRAFT:-1}" = 1 ]; then
    DRAFTER_DIR=${DRAFTER_DIR:?the folder with incoai/Inkling-2-Mini-DFlash2 (or DRAFT=0)}
    PREPARED=${PREPARED:-$DRAFTER_DIR-prepared}
    if [ ! -s "$PREPARED/model.safetensors" ]; then
        mkdir -p "$PREPARED"
        $DOCKER run --rm --entrypoint python3 -v "$MODEL_DIR":/model:ro -v "$DRAFTER_DIR":/drafter:ro -v "$PREPARED":/prepared \
            -v "$HERE":/engine:ro "$IMAGE" /engine/build_drafter.py /model /drafter /prepared
    fi
    MOUNTS+=(-v "$PREPARED":/drafter:ro)
    ARGS+=(--speculative-config '{"method":"dflash","model":"/drafter","num_speculative_tokens":7,"draft_sample_method":"probabilistic"}')
fi
$DOCKER rm -f "$NAME" >/dev/null 2>&1 || true
$DOCKER run -d --name "$NAME" --gpus "device=$GPU" --ipc=host --network host "${MOUNTS[@]}" \
    -e VLLM_NO_USAGE_STATS=1 -e DO_NOT_TRACK=1 "$IMAGE" "${ARGS[@]}" ${EXTRA:-}
echo "starting $NAME on GPU $GPU, http://$HOST:$PORT/v1 (model id: $SERVED)"
for i in $(seq 1 180); do
    if curl -s -m 3 "http://$HOST:$PORT/v1/models" | grep -q '"id"'; then echo "ready after $((i * 5)) s"; exit 0; fi
    if [ -z "$($DOCKER ps -q -f name="^$NAME$")" ]; then echo "the server exited:"; $DOCKER logs --tail 30 "$NAME" 2>&1 | cut -c1-300; exit 1; fi
    sleep 5
done
echo "not ready after 900 s"; exit 1