Run Reef in production ====================== The deployment file that runs on one host also runs in production. For production you choose where each part runs: the processes, the state, the training, the serving, the task sandboxes, and the agents that connect. .. figure:: ../assets/production-choices-light.svg :alt: What you choose for production. Agents, apps and coding agents call Reef. Reef's seven services run in one process or one process each. Serving runs on SGLang or vLLM on your GPUs, on an upstream provider or on Tinker's sampler. Training runs on Slime on your GPUs, on Tinker, on Spindle on Modal or on your own backend. Task sandboxes run on Docker, E2B or Modal. Every service reads and writes the state: records and work queues in SQLite or PostgreSQL, versions in a Git LFS repository, and files on a disk that the hosts share. Each choice is one section of this page: .. list-table:: :header-rows: 1 * - You choose - Options - Set with * - `The processes <#split-the-services>`__ - One process, or one process for each service - ``reef serve --service NAME`` * - `The state <#keep-the-state>`__ - SQLite on one host, or PostgreSQL; a Git LFS repository, local or on Hugging Face - ``storage`` * - `The training <#train>`__ - Slime on your GPUs, Tinker, Spindle on Modal, or your own backend - ``training.backend`` * - `The serving <#serve>`__ - SGLang or vLLM on your GPUs, a remote GPU host, Tinker's sampler, or an upstream provider - ``inference`` * - `The task sandboxes <#run-tasks-in-sandboxes>`__ - Docker, E2B or Modal - ``environment`` of an evaluation, ``evolution.executor`` * - `The agents `__ - Any OpenAI-compatible client, ``reef-client``, or a coding agent - The client's base URL * - `Access and monitoring <#secure-and-observe>`__ - Tokens, a proxy for TLS, logs, Weights & Biases, OpenTelemetry - ``reef.tokens``, ``observability`` `On AWS and Google Cloud <#on-aws-and-google-cloud>`__ says which cloud service fills each part. `Production interfaces <../developer-guide/production-interfaces.rst>`__ gives the contract of each part: what is built in, what the tests cover, and the base class of a class of your own. Before you start ---------------- Run the loop once on one host: `Use Reef `__. Choose the state before the first training job: a change of backend later does not move the data. From one host to production --------------------------- Start from the deployment file that runs on one host, such as the one of the ``minimal`` recipe (`serve.yaml <../../recipes/minimal/examples/slime/serve.yaml>`__) from `Use Reef `__. The ``recipe``, ``inference`` and ``training`` sections stay as they are. Three things change: .. code:: yaml reef: # Listen for other hosts. Reef refuses a public address without a token. host: 0.0.0.0 tokens: - ${REEF_TOKEN} storage: # The records and the work queues, for every service. record-backend: postgres record-database-url: ${REEF_RECORD_DATABASE_URL} # The versions and the files, on a disk that every host mounts. artifact-repository: /mnt/reef/artifacts.git agent-record-dir: /mnt/reef/agent-record activation: # Hold each new version back until you choose it. module: never Then start one process for each service, with the same file: .. code:: bash reef serve -c deploy.yaml --service control --reef.port 8900 reef serve -c deploy.yaml --service inference --reef.port 8902 reef serve -c deploy.yaml --service samples --reef.port 8903 reef serve -c deploy.yaml --service training --reef.port 8904 Check each process with ``curl -f http://:/healthz``. Model calls go to the inference process, and scenarios and reports go to control (`Route the requests <#route-the-requests>`__). The sections below give each choice in full. What we ran: the loop of `Use Reef `__ on one host with two GPUs, SQLite and a local repository. The settings of this section are checked by a test to be settings of Reef; a deployment on several hosts was not run for this page. Split the services ------------------ ``reef serve`` runs the seven `services <../reference/services.rst>`__ in one process. To scale a service, or to keep inference up while control restarts, run one process for each service: .. code:: bash reef serve -c deploy.yaml --service control --reef.port 8900 reef serve -c deploy.yaml --service inference --reef.port 8902 Every process needs the same Reef version, the same deployment file, the same ``REEF_TOKEN``, and the shared state of the next section. Each process has its own port, ``storage.artifact-work-dir`` and ``storage.artifact-cache-dir``. .. list-table:: :header-rows: 1 * - Service - How many - Needs * - control - One active, and standbys that take over - The state * - inference - Any number; one of them starts the engines - The GPUs, or the address of the engines * - samples - Any number - The state * - training - ``training.max-jobs`` jobs for each process - The training backend's credentials, and write access to the checkpoints * - evaluation - ``evaluation.max-sandboxes`` sandboxes for each process - The sandbox provider's credentials * - data, harness - Any number - The state The control, samples, training and inference processes also need the recipe's package. To check it, ``curl -f`` the ``/healthz`` of each process, and read ``GET /reef/status`` on control. The two parts below say where each request goes, and what a restart of each service does. Route the requests ~~~~~~~~~~~~~~~~~~ Send each request to the service that lists its route (`Services <../reference/services.rst#the-services>`__). Only inference answers model requests: - Set ``harness.inference-url`` to an inference address that harness clients reach. - For a composite recipe, set ``reef.served-url`` to an inference address that the other services reach. ``reef-client harness connect`` also lists and creates scenarios, so point it at control. Other harness clients can call the harness service. Keep engine addresses private. After 30 seconds without control, a data write returns ``synced: false`` and a harness import returns 503; both stay queued, and sending the same files again waits for the first import. Restart a service ~~~~~~~~~~~~~~~~~ - **Control:** inference and queued work continue; new work and data sync wait. A standby takes over. Send control traffic to the instance that answers ``/healthz``. To upgrade, start the new standby before you stop the active one. - **Inference:** when another replica takes over the engines, it starts them again, local and remote, and requests in flight end. Poll `startup status <../reference/http-api-inference.rst#get-reef-scenarios-scenario-inference-status>`__ before you send traffic. Restart inference after a reset of the coordination store. - **Training:** jobs wait and consume no samples. Tinker and Spindle imports return 503 after 60 seconds. - **Evaluation:** with ``evaluation.on-stop: finish``, set ``evaluation.finish-timeout-s`` below the supervisor's kill deadline. A forced kill uses up an attempt, and the retry waits for the lease to expire. To check a restart, read ``GET /reef/status`` on control. Keep the state -------------- On one host the defaults work: SQLite and a local Git repository under ``.reef/``. Several hosts share three things. **Records and work queues: PostgreSQL.** Any PostgreSQL that the hosts reach works. The role must create schemas: .. code:: bash uv pip install 'reef-infra[postgres]' .. code:: yaml storage: record-backend: postgres record-database-url: ${REEF_RECORD_DATABASE_URL} To check it, start Reef: it creates the schemas ``reef_records``, ``reef_records_coordination`` and ``reef_data``. **Versions: a Git LFS repository.** The default is a local repository. Hosts can share it on a disk where file locks work, such as NFS. Or keep the versions in a Hugging Face repository: .. code:: yaml storage: artifact-backend: module: reef.artifact.git_lfs:GitLFSRepositoryBackendFactory config: repository: https://huggingface.co/org/my-versions refs: branches-and-tags token_env: HF_TOKEN **Files: a shared disk.** Every service must reach the task files and the job directories under ``storage.agent-record-dir``, and the training host must reach the checkpoints. For another kind of storage, such as an object store, write a plugin: ``storage.artifact-backend``, ``storage.segment-backend`` and ``storage.task-file-backend`` each take a ``package.module:ClassName``. The parts below cover the data store, the retention of records, the backup and the upgrade. Isolate the data store ~~~~~~~~~~~~~~~~~~~~~~ The data store holds the data items (records, trajectories, tasks, artifacts). Deployments with different record schemas still share ``reef_data``. To isolate one: .. code:: yaml storage: data-store: module: reef.storage.sql.data:PostgresDataStore config: database_url: ${REEF_DATA_DATABASE_URL} schema: reef_data_acme Every service must also reach the task files and either the segment files or ``/job-directories``; across hosts, use shared-store plugins. Once content is in segments, keep ``storage.segment-backend`` set, or Reef cannot read it. To check it, read an uploaded item through a service on another host. Record retention ~~~~~~~~~~~~~~~~ ``storage.agent-record-retention-max-bytes`` caps record bodies, not disk use: indexes and delayed cleanup take more, and SQLite does not shrink its file. Reef skips a pending report whose records were removed and logs a warning; keep backups for longer retention. To check it, the ``pipeline`` object of ``/reef/status`` counts evicted records. Back up a deployment ~~~~~~~~~~~~~~~~~~~~ With all writers stopped, copy: - the scenario, data and coordination databases, custom schemas included; - the artifact repository with its Git LFS objects, or the plugin's storage; - the task files, segment files and job directories; - the training checkpoints, the backend ``state-dir`` and the harness ``evolution.state_dir``. Working copies and caches can be rebuilt. Tinker artifacts also need their remote checkpoints and service. Upgrade from a Reef that wrote older formats ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Back up first. The data store upgrades in one transaction, and older Reef versions then refuse it. A data store or PostgreSQL record schema newer than this version fails without changes. This version reads only ``reef-commit/9`` and ``reef-scenario/8`` commits and scenario metadata, with no migration: for older formats, use a new deployment directory or schema and create the scenarios again. Reef leaves the old data. To check it, read ``/reef/status``. Train ----- ``training.backend`` selects where the jobs train. The recipe stays the same. .. list-table:: :header-rows: 1 * - Backend - Trains - Install - Credentials * - ``slime`` (default) - All parameters or LoRA, on your GPUs - The `Reef GPU image <../getting-started/installation.rst#build-the-gpu-image-for-weight-training>`__ - None * - ``tinker`` - LoRA, on the Tinker service; the Reef host needs no GPU - ``reef-infra[tinker]`` - ``TINKER_API_KEY`` * - ``spindle_full`` - All parameters, on a Spindle engine that you deploy on Modal - ``reef-infra[tinker]`` and ``reef-infra[modal]`` - The Spindle key in ``TINKER_API_KEY``, ``MODAL_TOKEN_ID``, ``MODAL_TOKEN_SECRET``, ``HF_TOKEN`` **Slime on your GPUs.** Slime trains on a Ray cluster: the one that Reef starts on this host, or yours at ``training.ray-address``. The training GPUs and the serving GPUs are separate: .. code:: yaml inference: num-gpus: 4 training: backend: slime options: actor-num-gpus-per-node: 4 num-gpus-per-node: 8 global-batch-size: 32 Slime trains one scenario for each deployment, and every weight recipe that ships trains on it. `Train model weights `__ has the GPU image and the checkpoint settings. **Tinker.** Give the key and a directory that the deployment keeps: .. code:: yaml training: backend: tinker options: state-dir: /var/lib/reef/tinker lora-rank: 32 Tinker's sampler serves the model: text chat only, with no tool calls. Tinker trains the ``sft`` algorithm and TTT-Discover. `Train with Tinker <#train-with-tinker>`__ has the limits, and the Spindle deployment. **Your own backend.** ``training.backend`` also takes the ``package.module:ClassName`` of a ``TrainingDeployment`` (`Training backends <../developer-guide/production-interfaces.rst#training-backend>`__). Train with Tinker ~~~~~~~~~~~~~~~~~ Tinker trains a LoRA adapter on its own service, so the Reef host needs no GPU. You need a Tinker API key in ``TINKER_API_KEY`` and the extra ``reef-infra[tinker]``. **Run the smoke test.** .. code:: bash uv pip install -e '.[tinker]' export TINKER_API_KEY="..." export REEF_TOKEN=reef-local export REEF_TINKER_STATE_DIR="$PWD/work/tinker-smoke" reef serve -c tutorials/tinker/serve.yaml # when /healthz answers, in another terminal with the same environment: python tutorials/tinker/smoke.py The paid test trains one step on synthetic rewards; run it once per new state directory. It prints ``Committed one Tinker update`` on success. See the `example <../../tutorials/tinker/README.md>`__. **Configure a deployment.** Set ``training.backend: tinker``, a Tinker model, and a persistent ``training.options.state-dir`` for this deployment alone (`training settings <../reference/configuration-settings.rst#training>`__). Tinker then serves one training scenario; to serve more, serve on SGLang (below). - The Tinker sampler takes text messages on ``/v1/chat/completions`` only. Tools, multimodal content, other routes, several outputs and unknown options return 400. - A stream arrives as one SSE reply when the answer is complete. - With no token limit, the answer can fill the context window (1024 tokens when the service states none). A prompt that fills the window returns 400 ``context_length_exceeded``. - Use one chat template for training and serving: a sample that does not render or fit does not train. - Tinker trains ``sft`` and `TTT-Discover <../../recipes/tttd/README.md>`__. SAO, SDFT, SDPO, OPD and OpenClaw-RL need Slime. To check it, ``GET /reef/scenarios/{scenario}/artifacts`` lists a new artifact after a job. **Jobs, checkpoints and recovery.** A new scenario serves the base model. A job restores weights and optimizer state, saves at its end, and saves every ``recipe.config.job_parameters.save_interval`` optimizer steps when set. The next job, and a restart, continue from the last save, served or not (`train-from `__ changes this). An artifact references a remote checkpoint: keep the account, project, service and checkpoints. Reef never deletes them and rejects checkpoints of another service. An API call with an unknown result can cost credits or leave a checkpoint that no artifact names. **Serve on SGLang.** .. code:: yaml inference: model-path: Qwen/Qwen3-8B backend: sglang num-gpus: 2 max-loaded-adapters: 2 training: backend: tinker options: state-dir: /var/lib/reef/tinker lora-rank: 32 Reef converts each checkpoint to a PEFT adapter. Give one adapter slot per scenario, plus one for an update. Match the base model, tokenizer and chat template; SGLang must support ``lm_head`` adapters. Spindle checkpoints cannot serve this way, and only stub-engine tests cover this setup. To check it, poll ``inference/status`` until ``state`` is ``ready``. **Serve from a remote GPU host.** On a GPU host with Reef and SGLang, run ``python -m reef.inference.remote --port 8000`` with ``REEF_REMOTE_CONTROL_TOKEN`` and ``REEF_REMOTE_INFERENCE_TOKEN`` set to two different values. Set the same variables on the Reef host, and ``inference.remote.url`` (prefer HTTPS). The control token can start model code and replace weights. One runtime controls the component, and stopping it stops the engines. Reef checks the component every 30 seconds and reloads adapters after a restart. **Train all parameters on Spindle.** Deploy a `Spindle `__ full-parameter engine for the exact base revision, install ``reef-infra[modal]``, and supply Modal credentials, the Spindle key in ``TINKER_API_KEY`` and an ``HF_TOKEN`` that reads the base: .. code:: yaml inference: model-path: org/model training: backend: spindle_full options: state-dir: /var/lib/reef/spindle-full base-url: https://--spindle-server.modal.run base: hf://org/model@0123456789abcdef0123456789abcdef01234567 release-repo: org/model-releases modal-environment: spindle learning-rate: 1.0e-6 Each checkpoint exports weights, tokenizer and templates to a new release commit. Spindle serves it by default, and Reef's engines can load it. An import must match the base or hold a full-parameter manifest of the same service; other weights return 400. Use one engine and scenario per base. Each job pays for GPU startup and export. The `training settings <../reference/configuration-settings.rst#training>`__ describe each key, ``score-centering`` included. Serve ----- .. list-table:: :header-rows: 1 * - The model serves on - Set - Note * - SGLang or vLLM on this host's GPUs - ``inference.backend: sglang`` or ``vllm``, ``inference.num-gpus`` - The default is SGLang. vLLM serves full weights only. * - A GPU host that you run - ``inference.remote.url`` - The host runs ``python -m reef.inference.remote``. Two tokens protect it. * - Tinker's sampler - ``training.backend: tinker`` - The default with Tinker. ``inference.backend: sglang`` serves the adapters on your GPUs instead; Reef's tests cover that only with a stub engine. * - An upstream provider - ``inference.upstream-url``, ``inference.upstream-model`` - For a recipe that trains no weights: Reef records the calls, or evolves a harness. * - Your own runtime - ``inference.serving: package.module:Factory`` - `Serving runtimes <../developer-guide/production-interfaces.rst#serving-runtime>`__ A new version loads into the running engine. Poll ``GET /reef/scenarios/{scenario}/inference/status`` until ``state`` is ``ready`` before you send traffic after a restart. `Inference settings <../reference/configuration-inference.rst>`__ has the keys of each row. Run tasks in sandboxes ---------------------- Reef runs a task in a sandbox in two places: an evaluation of a version, and the evaluation runs of a harness recipe. .. list-table:: :header-rows: 1 * - Provider - Install - Credentials - Note * - Docker - A running Docker daemon - None - The default of an evaluation * - E2B - ``reef-infra[e2b]`` - ``E2B_API_KEY`` - Starts the task's own image. A task with several Compose services needs an AgentENV deployment. * - Modal - ``reef-infra[modal]`` - ``MODAL_TOKEN_ID``, ``MODAL_TOKEN_SECRET`` - A sandbox lives 24 hours at most **An evaluation** names its provider in the request: .. code:: bash curl -fsS -H "Authorization: Bearer $REEF_TOKEN" -H 'Content-Type: application/json' \ "$REEF_URL/reef/scenarios/demo/evaluations" \ -d '{"artifact_id": "", "harness": {"name": "terminus-2"}, "environment": "e2b"}' The evaluation service runs ``evaluation.max-sandboxes`` sandboxes at once (4 by default). Set it to the provider's quota divided by the number of evaluation processes. With the activation rule ``evaluated``, a version serves when its evaluation reaches ``min_mean_score`` (`Evaluation <../reference/http-api-evaluation.rst>`__). **A harness recipe** names its provider in the deployment file: ``recipe.config.evolution.executor`` takes ``local``, ``sandbox``, ``e2b`` or ``modal``. E2B and Modal refuse ``egress_hosts`` and ``limits`` (`Harness settings <../reference/configuration-harness.rst>`__). For another provider, write a ``RemoteExecutor`` (`Sandboxes <../developer-guide/production-interfaces.rst#sandbox>`__). Connect an agent ---------------- An agent uses Reef as its model endpoint: any OpenAI-compatible client, the Python ``reef-client``, or a coding agent such as Claude Code, Codex, OpenCode or pi. `Connect an agent `__ gives each way, the adapters, and how to write an adapter. Secure and observe ------------------ - **Tokens.** Set ``reef.tokens``. Every token opens every route, and several tokens let you change one without downtime. Reef refuses to listen on a public address without a token. Put a gateway in front of Reef for per-user permissions. - **TLS.** Reef serves HTTP. Put a proxy that ends TLS in front of it. - **Browser consoles.** ``reef.console-origins`` lists the origins that may call Reef. - **Status and logs.** ``GET /reef/status`` on control gives each scenario's state. Each process writes ``/.log``. - **Metrics and traces.** ``observability.wandb`` sends metrics to Weights & Biases (``reef-infra[wandb]``). ``observability.tracing`` sends the records as OpenTelemetry traces, message content included (``reef-infra[opentelemetry]``). See `Observability <../reference/configuration-observability.rst>`__. On AWS and Google Cloud ----------------------- Reef uses standard parts, so it runs on either cloud. The table says which service fills each part. Reef's own code for a cloud is the S3 reader and writer only. .. list-table:: :header-rows: 1 * - Reef needs - On AWS - On Google Cloud - In Reef * - Hosts with GPUs, for Slime and the engines - EC2 GPU instances - Compute Engine GPU instances - The Reef GPU image runs on any host with NVIDIA GPUs * - PostgreSQL - RDS for PostgreSQL - Cloud SQL for PostgreSQL - ``storage.record-database-url`` * - A disk that the hosts share - EFS - Filestore - An NFS mount. A FUSE mount of an object store does not work for the Git repository. * - A place for the versions - The shared disk, or Hugging Face - The shared disk, or Hugging Face - ``storage.artifact-backend``. An S3 or GCS backend is a plugin that you write. * - Imports and exports of data - ``s3://`` URIs, with ``reef-infra[s3]`` - Not built in - `Data upload <../reference/http-api-data-upload.rst>`__ * - Task sandboxes - Docker on the hosts, or E2B or Modal - Docker on the hosts, or E2B or Modal - `Run tasks in sandboxes <#run-tasks-in-sandboxes>`__ Reef ships no Kubernetes chart. Each service is one ``reef serve --service NAME`` process with ``/healthz``, so a process manager or an orchestrator of your choice runs them. Before you go live ------------------ #. The state is on PostgreSQL and a repository that every host reaches. #. ``reef.tokens`` is set, and a proxy ends TLS. #. Each process answers ``/healthz``, and ``GET /reef/status`` shows no ``error``. #. A test scenario went through the whole loop: `Use Reef `__, steps 2 to 5. #. You stopped the writers and copied the state once (`backup <#back-up-a-deployment>`__). Next steps ---------- - `Operate a deployment `__: choose what serves, train from a version, recover after a restart. - `Troubleshooting `__: what to read when a step fails. - `Services <../reference/services.rst>`__: each service's routes and work queues.