This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

MLflow Vast.ai backend

Planned MLflow Projects execution backend for Vast.ai rentals

The Python plugin connects MLflow Projects to a Vast.ai job server using gRPC. The Go job server assigns jobs to existing Vast.ai rentals. A worker on each rental runs jobs and records their outcomes.

The plugin architecture shows how the submitter, coordinator, worker, and MLflow exchange requests and data.

bazel run //projects/mlflow_vastai_backend/cmd/mlflow-vastai -- worker serve

The CLI machine parses arguments and starts the application child with a typed command. The application delegates worker commands to its worker child. worker serve starts the worker’s listener machine, and the listener uses the SQLite-backed job machine. server serve starts the job coordinator.

Export the composed application graph as DOT or build the themed SVG on Linux.

bazel run //projects/mlflow_vastai_backend/cmd/mlflow-vastai -- state-machine graph
bazel build //projects/mlflow_vastai_backend/cmd/mlflow-vastai:state_machine_svg

The SVG is at bazel-bin/projects/mlflow_vastai_backend/cmd/mlflow-vastai/state-machine.svg. Bazel builds Graphviz from pinned source. The SVG embeds the shared diagram font and uses the common theme’s light and dark palettes. The state machine page embeds the generated graph.

bazel run //projects/mlflow_vastai_backend/cmd/mlflow-vastai -- server serve \
  --state-dir /path/to/server-state --workers training,12345 \
  --tracking-uri https://mlflow.example.com --ssh-user root

Inject VAST_API_KEY for read-only rental discovery. Set MLFLOW_TRACKING_TOKEN for bearer authentication, or use MLFLOW_TRACKING_TOKEN_FILE to read a rotating bearer token on every tracking request. Use a tracking endpoint reachable from both the server and the rentals. The server accepts workloads using that configured HTTP or HTTPS tracking endpoint.

--workers lists allowed instance IDs and exact labels in preference order. If the plugin specifies a worker, its selector must match an entry. A label must identify a single existing rental. Install mlflow-vastai on the rental’s SSH account PATH and register its SSH host key with the coordinator’s account. The SSH client uses the rental worker’s default state directory.

The gRPC listener binds to 127.0.0.1:50051 by default and accepts only loopback addresses. Use the local endpoint from a trusted environment, or front it with an authenticated transport for remote access.

The server saves the selected rental before submitting a workload. It retries ambiguous submissions on that rental with the original run ID, observes jobs after clients disconnect, and publishes confirmed terminal results to MLflow.

Run worker serve as the rental’s SSH user with mlflow on PATH and the project’s training runtime installed. The worker uses that MLflow CLI and its tracking credentials to download the project snapshot. It runs the prepared entry point with MLFLOW_TRACKING_URI, MLFLOW_EXPERIMENT_ID, and MLFLOW_RUN_ID set.

Use worker --state-dir /path/to/state serve to set the state directory. The default is $XDG_STATE_HOME/mlflow-vastai or $HOME/.local/state/mlflow-vastai. An existing directory must be private to its owner. The listener keeps worker.sock, jobs.sqlite3, and per-job directories under that path. Workload output goes to stdout.log and stderr.log. Artifact download and workload errors are logged by the listener.

worker submit, worker status, and worker cancel use the same state directory. They read one binary protobuf from stdin and return a binary Job on stdout. Submission takes SubmitJobRequest. Status and cancellation take JobReference.

The listener reserves the MLflow run ID in SQLite and immediately starts preparing the workload. Status is RUNNING from acceptance through execution. Cancellation stops the local workload, and the listener records the confirmed outcome. Graceful shutdown stops active workloads and records their results. After a crash, a new listener reports unfinished jobs as unknown and preserves the original reservations.

Give the plugin a JSON backend configuration with server set to the gRPC address. Set worker to request a configured worker selector. Use TLS through an authenticated gateway or connect directly to a trusted local listener as shown here.

{
  "server": "127.0.0.1:50051",
  "worker": "training",
  "insecure": true
}
export MLFLOW_TRACKING_URI=https://mlflow.example.com
bazel run //projects/mlflow_vastai_backend:mlflow -- run /path/to/project \
  --backend vastai --backend-config /path/to/backend.json --env-manager local

Use an HTTP or HTTPS tracking endpoint reachable from the submitting machine, coordinator, and rental. The rental also needs access to the run’s artifact store.

The adapter uploads a compressed project snapshot to the MLflow run at vastai-source/project.tar.gz before submitting the job. The request carries the artifact path, rendered entry point, and MLflow tracking context. The worker needs read access to the run artifacts and a preconfigured training runtime. The snapshot uses the current contents of Git-tracked files under the project directory. Set project_files to a JSON list of additional project-relative regular files. For a project outside Git, supply the full file list this way.

If the client reports an unconfirmed submission, use the reported MLflow run ID to locate the existing job before submitting again.

This version does not stage MLproject path parameters or provision Docker, conda, or virtualenv environments.

bazel test //projects/mlflow_vastai_backend/test/e2e:plugin_test
bazel test //projects/mlflow_vastai_backend/test/e2e:worker_test
bazel test //projects/mlflow_vastai_backend/test/e2e:server_test
bazel build //projects/mlflow_vastai_backend/api/jobpb:jobpb

The plugin test uses a local gRPC fixture. The worker test uses the real CLI, Unix gRPC socket, SQLite state, and an MLflow artifact store. Refresh the project’s Python lock with bazel run //projects/mlflow_vastai_backend:uv_lock.update.

1 - Application state machines

Command dispatch, listener lifecycle, and job transitions in the MLflow Vast.ai backend

CLI, coordinator, and worker state machines

See the plugin architecture for the service boundaries and protocols.

The CLI machine enters cli-parsing and uses Cobra to parse the arguments. cli-dispatch calls the selected application method. The application calls the worker through its named methods. Each component adds its own states and child calls to the graph. Dashed arrows show those calls.

  • server serve runs the coordinator and its job machine.
  • worker serve runs the worker’s listener child machine. Its states open the listener in worker-starting, serve RPCs in worker-serving, and release resources in worker-stopping.
  • state-machine graph prints the machine definitions and their calls as one DOT graph.

worker submit, worker status, and worker cancel enter forward-rpc and send protobuf requests over the worker’s Unix socket. Bazel regenerates the diagram from the CLI when it builds this page.

The coordinator reserves an assignment before contacting the worker. Its job machine advances from reserved to active or to a recorded result. The server reconciles unresolved assignments and publishes confirmed terminal results to MLflow while their tracking runs are active.

The listener delegates submission, status, and cancellation to the job runner. The runner reserves the run ID in SQLite and starts the workload machine as soon as that transaction commits. The workload machine stages the project and runs the prepared command. The job runner signals active workloads and records their outcomes. It retries failed writes using the observed result.

The listener closes the job runner before closing SQLite. The runner stops active workloads and gives pending writes a bounded time to finish. On startup, the job runner marks interrupted jobs as unknown through the same result transition and preserves their run IDs.

2 - Plugin architecture

Submission, execution, and result tracking across MLflow and Vast.ai

MLflow Vast.ai plugin architectureMLflow Vast.ai plugin architecture

The MLflow run ID identifies the workload across the plugin, coordinator, and worker. The coordinator records its rental assignment before dispatch. The worker records the outcome before reporting it.

The worker receives the project snapshot from MLflow’s artifact store and runs the entry point on the rental. The workload logs metrics and artifacts to the run. The coordinator publishes confirmed terminal status to MLflow and retries failed updates after the submitting client disconnects.

Terraform provisions and releases rentals. The coordinator discovers existing rentals through the Vast.ai API.

See the application state machines for process lifecycles and job transitions.