Concepts

How routing works

How a job goes from a spec to one GPU: filter, benchmark, pick the lowest verified cost per unit of work, run under a budget.

There are two levels. A route is a free decision from listed rates and stored evidence; it never launches. A job (POST /v1/jobs) builds a route, benchmarks it when needed, and runs the winner.

Filter the candidates#

Every catalog GPU with at least min_vram_gb of memory is a candidate: T4, L4, A10, L40S, A100-40GB, A100-80GB, RTX-PRO-6000, H100, H200, B200, B300. Compatibility follows the declared requirements only.

Each candidate is priced at its listed Modal rate, filtered by the capacity tiers the job allows:

task_typeAllowed tiers
training or unsetEvery tier, spot, preemptible and auction included.
inferenceOn-demand and serverless only.
inference with allow_interruptible: trueOn-demand, serverless, spot, preemptible and auction.

Note. Modal's listed GPU rate is stored as tier preemptible. An inference job without allow_interruptible: true therefore has no Modal rate and nothing to launch. The inference samples set it.

A job only considers candidates that have a listed rate and can be launched. Today only Modal launches; other providers' prices appear in the comparison only.

Route without launching#

POST /v1/routes stores a route; POST /v1/routes/preview answers the same without an account and stores nothing. Each candidate gets a runtime estimate from the best evidence available:

  1. Your comparable verified runs: same workload_class, task_type, model_id, precision, gpu_count, framework_version and input size bucket. Unset fields never match.
  2. An external public benchmark, when one matches.
  3. None: the runtime is unknown and only the ceiling (rate times timeout_seconds) is shown.

The lowest-cost policy selects the candidate with the lowest estimated cost, or the lowest rate when nothing has an estimate. max_cost_usd drops candidates whose estimate, or ceiling without an estimate, is above it. gpu names a GPU and skips the policy.

A route expires 30 days after its selected rate was checked. Launching or benchmarking an expired route answers 409 ROUTE_EXPIRED; create a new route.

Benchmark when there is no evidence#

A job benchmarks unless it can reuse measurements (below) or only one GPU fits. It picks up to max_benchmark_gpus (2 or 3, default 3) candidates, starting with the route's selection, then by estimated cost, then by hourly rate.

  • Every GPU gets the same work, seed, image, command and env.
  • Each GPU runs twice. Each run is stopped after timeout_seconds, clamped to 30 to 300 seconds.
  • The cap is rate times run time times runs, summed over GPUs. It must stay within half of budget_usd; GPUs are dropped down to 2 to fit, then the job is refused with 409 JOB_OVER_BUDGET.
  • Benchmarking needs 2 free run slots. With the default limit of 2 active runs, a job benchmarks 2 GPUs.
  • A benchmark run that fails to launch counts as a failed run of that GPU; the other GPUs still rank. The job goes on when at least 1 GPU qualifies and fails when none does.

You can also benchmark a route yourself with a quote and an explicit cap: GET /v1/routes/{id}/benchmark/quote, then POST /v1/routes/{id}/benchmark with max_cost_usd at least the quoted cap_usd and confirm: true.

Pick the lowest verified cost per unit#

A benchmark run counts only if it succeeded, did not fail its verifier and produced a throughput. A GPU qualifies with at least 2 passing runs (all of them when fewer runs were planned).

Cost per unit is priced at today's rate:

usd_per_unit = usd_per_gpu_hour x gpu_count x unit_scale / (3600 x throughput)
TaskUnitThroughput
Training (or unset)1k stepssteps per second
Inference1M tokenstokens per second

Each GPU reports the median and the min to max range of its runs. The GPU with the lowest median wins. When its range overlaps another GPU's, they are tied_with each other and the tie goes to the cheaper hourly rate.

Steady-state throughput#

Throughput leaves out the seconds that are not the job's real work. Print metric lines to stdout, one JSON object per line after the prefix:

GPU_ROUTER_METRIC {"t": 41.2, "step": 0, "loss": 3.60}
GPU_ROUTER_METRIC {"t": 44.9, "step": 2, "phase": "warmup_done"}
GPU_ROUTER_METRIC {"t": 61.0, "step": 10, "loss": 2.71}
KeyMeaning
tSeconds since the process started. Required on every line.
step or tokensCumulative steps (training) or tokens (inference) so far.
phase"warmup_done" marks the end of warmup. Without it, steady state starts at the second counted line.
lossOptional. The last one is the run's final loss.

The run is split into startup (process start to the first metric line), warmup, and steady state. Throughput is the units done during steady state divided by its span. Everything else (launch, model load, warmup, teardown) is reported as excluded_seconds and does not count against the GPU.

Without metric lines, throughput falls back to work divided by wall-clock duration and the result is marked wall_clock_only, lower confidence.

Benchmark runs receive GPU_ROUTER_MAX_STEPS (training) or GPU_ROUTER_MAX_REQUESTS (inference), default 50, and GPU_ROUTER_SEED. Read them so every GPU does the same work.

Fingerprint and 14-day reuse#

Every route has a fingerprint: the sha256 of the job's image, command, a hash of its env values, CPU, memory, inputs, output directory, workload fields and GPU count. Only runs with the same fingerprint are compared.

A new job reuses your measurements instead of benchmarking when at least 2 GPUs each have 2 or more runs of the same fingerprint from the last 14 days that succeeded, passed or skipped verification, and produced a throughput. They are priced at today's rates. The step detail says so:

Reusing 4 verified measurements of this job from the last 14 days, priced at today's rates, so no benchmark.

Changing anything in the fingerprint, including rotating a secret in env, starts a fresh benchmark. The benchmark's own GPU_ROUTER_* variables are not part of it, so benchmark and full runs share one fingerprint.

Budget caps#

budget_usd is a hard cap on GPU spend for the whole job, benchmark runs included.

  1. Before the benchmark: its cap must fit within half the budget.
  2. Before the full run: when the spec sets work_units, the projected cost on the winner must fit what is left, or the job fails with JOB_OVER_BUDGET.
  3. The full run's timeout is cut to the seconds the remaining budget buys at the winner's rate. The step says Capped at N s to stay within the budget. If that is under 30 seconds, the job fails with JOB_OVER_BUDGET.

A job stopped by its budget has budget_reached: true and sends a budget.reached webhook event. Spend counts the measured GPU cost of finished runs. Modal also bills CPU and memory, which the budget does not cover.

When a launch fails#

A job tells three failures of the full run apart.

  • It failed to start. The launch call raised (for example no capacity), or Modal reported it has no record of the run before it ever ran. Nothing runs, so the job falls back to the next GPU in the verified ranking, then the next: up to 2 fallbacks, 3 attempts in all. A GPU whose projected cost is above what is left of the budget is skipped.
  • It ran and failed. A non-zero exit after it started, its timeout, a failed verifier, or a run lost after it was seen running. That is the job's own code, so there is no fallback: the job fails with the reason.
  • Its state is unknown. The launch call timed out, the server restarted before the launch returned a provider reference, or status polls kept failing until the run was marked lost. A sandbox may still be running the full job outside the budget cap, so the job does not launch a second GPU: it fails, and its agent_prompt says to stop that sandbox in your Modal account first.

Each fallback adds a choosing step:

A10 failed to start (Launch failed: ResourceExhaustedError); falling back to L4 ($0.888 per 1k steps, next cheapest verified).

The job's fallbacks lists each GPU that failed to start, in order, with its run_id and reason. choice, run_id and run then describe the GPU that actually ran, and the last step says so: Finished and verified on L4, a fallback after A10 failed to start. Job events carry the same list in stats.fallbacks and say it in agent_prompt. Each attempt that failed to start also sends its own run.failed event with the job's job_id; its agent_prompt says to follow the job, not to start it again.

Each attempt is its own run with its own idempotency key, so a retried request never launches one twice. A launch that raised adds nothing to spend; a run Modal lost after launching counts its launched time, like any run. When every attempt fails to start, or no verified GPU is left to try, the job fails with every reason in error; when the GPUs left were all over budget it also has budget_reached: true. Only GPUs the job verified are tried, so a job with one fitting GPU and no benchmark does not fall back.

Note. A launch that timed out or was cut off by a restart counts as USD 0 in spend_usd, since its launch time was never recorded, yet a sandbox it left still bills in your Modal account. Check the Modal dashboard and stop it.

Savings#

savings compares the job's full cost, benchmarks included, with running it on the fitting GPU with the cheapest hourly rate. On a short job it can be negative: the benchmark cost more than it saved. Later runs of the same job reuse the measurements and pay no benchmark.

Next steps#