Skip to content

Getting started

This page takes a fleet from hosts with nothing of Narwhal's on them to a serving fleet you can watch on the dashboard. Pick a layout:

Layout Engines Routers
SSH hosts Engines on every host you list: two on one host with two GPUs or more, one on each of several One router on engine 1's host, with no failover
Kubernetes Engine pods on every GPU node of the cluster, sending KV over TCP, or over RDMA where the fleet names an RDMA resource A router pair behind HAProxy, on different nodes where the cluster has more than one

The SSH page starts from narwhal deploy init. It inspects the hosts from the release's host image and writes the whole fleet from the hosts and the model. The Kubernetes page needs no init, because the controller derives the nodes and generates the Secrets. That page starts from its layout's fleet.

Each page links its reference layout under deploy/layouts. For SSH hosts the layout is a file that init wrote. For Kubernetes it holds only the inputs that the controller cannot default, with example values.

The sections below cover the SSH hosts.

Preparing the workstation

The workstation runs narwhal deploy and keeps the run directories. It needs Python 3.11 or later, OpenSSH 8.5 or later and, on SSH hosts, cosign v3 to check the release manifest's signature:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install 'narwhal-inference==<version>'

The hosts run the images of the same release. init reads the release manifest from its GitHub release and pins its SHA-256 in spec.release, as The release manifest describes. On SSH hosts, init, plan and run also check its signature, as Verifying the release manifest describes. For a pre-release or an air-gapped deploy, copy the manifest and its bundle into one directory and give the manifest to init, plan and run with --release-manifest FILE.

Write the known-hosts file before anything connects. One way is to scan each host, then compare every fingerprint with one from a source you trust, such as the provider console:

ssh-keyscan -t ed25519 <host-a> >> ssh.known_hosts
ssh-keygen -lf ssh.known_hosts

For a host whose SSH port is not 22, scan it with ssh-keyscan -t ed25519 -p <port> <host-a>. This writes the entry in the [host]:port form that OpenSSH looks up. Write the host's destination as ssh://deploy@<host-a>:<port>, or as an alias with a Port line in your SSH config.

narwhal deploy checks every host key against this file and never adds a key. When you reach the hosts through a jump host, which spec.ssh.jump names, add its key too.

Preparing SSH hosts

The site prepares the hosts. narwhal deploy installs no packages and never runs sudo. A missing piece fails plan or the stage that needs it, and the failure names the host and the missing piece.

On every host, for the SSH user that narwhal deploy logs in as:

  • SSH access with a key or a password, through the optional jump host.
  • coreutils, including timeout, and a writable home directory.
  • Docker Engine running as root. The SSH user must reach /var/run/docker.sock, for example through membership of the docker group, and must be able to pull the release's images. Rootless Docker does not work.

On each engine host:

  • The accelerator driver and a container runtime that exposes the GPUs, with nvidia-smi or rocminfo. The images stage pulls the release's tested engine image, or checks the image that spec.engines.image names. That image must be loaded under the same image ID on every engine host.
  • The checkpoint at one path on every engine host, which init --model names. Alternatively, give init the checkpoint's hf:// or s3:// source. The model stage then copies it to every engine host, as Fetching the checkpoint describes.
  • A firewall that allows three kinds of traffic. The routers reach each engine and attestation port. The engines reach each other's KV side-channel ports and UCX port range. The hosts reach each other's spec.fabric.testPort, 5201 by default, on the fabric addresses.

A router pair needs a firewall on both router hosts. It lets each router and HAProxy reach both routers' ports, and lets clients reach the load balancer's port. It also needs:

  • Port 8470 on the witness host open to both router hosts, and to nothing else.
  • Clocks within 30 seconds of each other on the router hosts and the witness host, kept by NTP or chrony.

A router pair also needs Docker on the load balancer's host, which is the primary router's host unless spec.ssh.loadBalancer.host names another.

Writing the fleet file

narwhal deploy reads every input from one NarwhalFleet file, narwhal-fleet.yaml by default. It reads the secrets from a second file that the first file names. narwhal deploy init writes both, as SSH hosts shows. Every field that the reference does not mark required has a default. You do not write the engine topology. discover derives the engines, their GPUs, ports, fabric interface, HCA port and transport from the hosts, as Engine topology describes. Write config/fleet.yaml:

apiVersion: narwhal-inference.com/v1alpha1
kind: NarwhalFleet
metadata:
  name: fleet
spec:
  engines:
    image: sha256:<image ID>
    model:
      name: <served model name>
      treeSha256: <model_tree_sha256>
      fetch:
        source: hf://<owner>/<name>
        revision: <full commit hash>
  release:
    version: "<version>"
    manifestSha256: <SHA-256 of narwhal-release-manifest.json>
  calibration:
    inputTokens: [256, 8192, 16382]
  ssh:
    knownHosts: ssh.known_hosts
    secretsFile: narwhal-fleet-secrets.yaml
    hosts:
      - name: host-a
        destination: deploy@<host-a>
    router:
      url: http://<host address>:8000
    modelDir: /srv/models/<model>
    runDir: /home/deploy/narwhal/runs
    monitoring:
      fleetName: first-fleet

Without spec.slo.ttftS and spec.slo.tpotS, fleet-limits derives both from the measured fleet, as Deriving the targets describes. spec.ssh.runDir must exist on each engine host.

Then write the secrets file, narwhal-fleet-secrets.yaml, at mode 0600, the name init gives it. It holds the router's control token, generated once per fleet:

umask 077
printf 'routerToken: %s\n' "$(python -c 'import secrets; print(secrets.token_hex(32))')" > narwhal-fleet-secrets.yaml

narwhal deploy refuses a secrets file that is not a regular file you own, or that other users can read or write. The secrets file lists its other keys.

Engine and discovery inputs gives the default ports. To choose other ports, set spec.engines.ports, or ports in an entry of nodes. The fabric workload, profiling and calibration take the defaults that the reference lists.

The profiling and calibration lengths suit engines whose live context is 16,384 tokens. Profile engines and run preflight explains how to choose them.

The default prefill lengths in spec.profiling.prefillLens start at 1,024 tokens. Change them for prompts outside 1,024 to 12,300 tokens, for a live context shorter than the default lengths, or when profile fails with a prefill fit error, as Profiling idle engines describes.

A fleet on one host has no fabric edges to measure. Preflight checks the transfers between its engines.

The longest calibration length must leave two output tokens within each engine's live context, which Calibrating the first-token deadline works out for SGLang. If profile fails with insufficient complete-cohort intervals, shorten the decode lengths as Profiling idle engines describes.

Preflight's slo gate fails when the calibrated first-token deadline plus the margin, the slowest prefill of the longest calibrated input, and the router overhead add up to more than spec.slo.ttftS. When the first-token budget fails says what to change.

For several hosts, list them and add the standby router and the load balancer. discover places an engine on each host:

spec:
  ssh:
    hosts:
      - name: host-a
        destination: deploy@<host-a>
      - name: host-b
        destination: deploy@<host-b>
    router:
      url: http://<host-a address>:8000
    standby:
      host: host-b
      url: http://<host-b address>:8000
    loadBalancer:
      url: http://<host-a address>:8080

Each engine takes its derived share of the host's GPUs. A spec.engines.launch entry NARWHAL_GPU_IDS of 0 gives each engine the host's first GPU instead.

The pair keeps serving while the load balancer's host, the witness's host and one router host remain. This pair survives the loss of host-b but not of host-a. To survive the loss of either router host, put the load balancer on a third host with spec.ssh.loadBalancer.host. The witness follows it there. A lease file on shared storage replaces the witness, as Router pair shows, but the pair still needs the load balancer's host.

init --router-pair writes these fields on three hosts or more, as Adding a router pair shows. Add them by hand for a pair on two hosts, or when the third host logs in with a password, which init never asks for.

For KV over RDMA, discover takes the first ACTIVE HCA port that has a verbs device on each host. It also takes that port's interface, GID index and RoCE mode. To choose them yourself, name each engine's HCA port and devices, and the GID index and RoCE mode. This example has engine 1 on port 1 of mlx5_0 and engine 2 on port 1 of mlx5_1, on an InfiniBand link:

spec:
  engines:
    rdma:
      gidIndex: 0
      roceMode: infiniband
    launch:
      - name: NARWHAL_TRANSFER_TRANSPORT
        value: ucx_rdma
      - name: NARWHAL_NODE_1_TRANSFER_NET_DEVICES
        value: mlx5_0:1
      - name: NARWHAL_NODE_1_TRANSFER_DEVICES
        value: '["/dev/infiniband/uverbs0"]'
      - name: NARWHAL_NODE_2_TRANSFER_NET_DEVICES
        value: mlx5_1:1
      - name: NARWHAL_NODE_2_TRANSFER_DEVICES
        value: '["/dev/infiniband/uverbs1"]'

Fabric qualification inputs shows how to read each value from the host and how to check that the verbs device exists there. Quote JSON values such as NARWHAL_TRANSFER_DEVICES and NARWHAL_ENGINE_ARGS with single quotes, so that YAML keeps them as strings.

Checking the inputs with plan

narwhal deploy plan

plan, run, status and down read narwhal-fleet.yaml, or the file that --fleet names. They keep the run in .narwhal/runs/<fleet name>, named after spec.ssh.monitoring.fleetName, or in the directory that --run names. plan reads config.json in spec.ssh.modelDir on engine 1's host, or a copy on the workstation: the one --model names, or the tree that init fetched from spec.engines.model.fetch. From that file it estimates the first-token budget. It exits 1 when the budget cannot fit spec.slo.ttftS.

plan names every missing or malformed field and exits 2 before it touches a host. It also exits 2 when the environment sets a deployment variable such as NARWHAL_TTFT_S. The message names the field to use instead, so unset the variables of any .env file that you loaded.

plan then logs in to each host and checks what the stages need of it:

  • a rootful Docker daemon that the SSH user reaches
  • free ports, such as Grafana's 3000, which an earlier monitoring stack can hold
  • the addresses that the routers and the monitoring stack listen on
  • the checkpoint directory
  • the engine image

It prints each stage and why run would run it. It exits 1 and names each host that failed a check and what to change. On a fleet with one router it also prints Note: spec.ssh.standby is unset, so the fleet runs one router with no standby, lease or load balancer: it has no router failover.

Running the deployment

narwhal deploy run

run runs the stages from access to monitoring, through the seven gates of Deploying a fleet. In a terminal it shows them as one table with a line for each gate and the stages of the running gate. It ends with the router's address and the commands to run next. Piped to a file, it prints a line when each stage instance starts and when it passes. The first run hashes the checkpoint, starts the engines, measures the fabric, profiles and calibrates.

When a stage fails, run prints its cause, the link to the gate section that covers it and its evidence directory. In a terminal the host log and the command that resumes follow them. Piped, it prints the cause, the recovery link and the evidence directory as separate lines.

Fix the cause and run the same command again. It resumes at the failed stage and skips every stage whose result still holds. To also run the capacity trial, add --trial with a trial file, as Running the initial capacity trial describes.

Checking the fleet with status and the dashboard

narwhal deploy status

status prints each stage's state, with the failure and evidence directory of any stage that did not pass. It then checks every engine, sidecar, router, witness, HAProxy and monitoring container and fabric route that the run recorded. It exits 1 when the last run stopped at a failed stage. It exits 3 when a recorded process or route is gone or changed. In either case, run run again.

Clients send requests to spec.ssh.loadBalancer.url, or to spec.ssh.router.url on a fleet with one router. The router and HAProxy listen on the addresses in those URLs. Prometheus and Grafana listen on the primary router's host, at 127.0.0.1:9090 and 127.0.0.1:3000 by default. The workstation needs one tunnel for each address, as Tunnelling router, Prometheus, and Grafana to the workstation shows. With those tunnels open, send a completion through the router:

curl -fsS http://127.0.0.1:18000/v1/completions \
  -H 'content-type: application/json' \
  -d '{"model": "<served model name>", "prompt": "The capital of France is", "max_tokens": 16}'

The model is spec.engines.model.name, and the reply's text is in choices[0].text. On a router pair, clients use the load balancer, so also send the request to http://127.0.0.1:18080, which reaches the routers through HAProxy. Completion requests lists the fields that the router checks.

Then open http://127.0.0.1:13000/d/narwhal-router/narwhal-orchestrator. The Router tile counts the firing Narwhal page and warning alerts, so a healthy fleet shows Alerts 0. The count leaves out NarwhalWatchdog, which always fires so that a dead man's switch can tell that Prometheus evaluates the rules. A higher count means an alert fires, and the Prometheus alerts page, http://127.0.0.1:19090/alerts, names it. The dashboard's Deployment row shows each stage of the last run, the fabric margins, the attestation generations and the supervisor restarts. To deliver its alerts, set spec.ssh.monitoring.alertmanagerUrl, as Monitor describes.

Grafana and Prometheus keep their data across down, and the Fleet selector opens on the first fleet that they hold. If the dashboard shows a different fleet, with its engines at N/A and its router down, pick yours in Fleet. Or open http://127.0.0.1:13000/d/narwhal-router/narwhal-orchestrator?var-fleet=<fleet name>, with the name from spec.ssh.monitoring.fleetName.

Stopping the fleet with down

narwhal deploy down

down stops the monitoring containers, HAProxy, the routers, the sidecars and the engine containers that the run started. This includes a container whose start failed or stopped before the run recorded it. down keeps the monitoring volumes, the deployment directories on the hosts and the run directory. A later run starts the fleet again from the stages whose results no longer hold.

For a host reboot, see After a host reboot. For a new release, see Deploying a new release. For a process's logs, see Where each process logs.