solvers.ServingCapacityModel
solvers.ServingCapacityModel()Sizes an LLM serving deployment from a QPS and tail-latency target.
The model deliberately composes existing first-order pieces: ServingModel for TTFT/ITL, ContinuousBatchingModel for per-replica token capacity, and TailLatencyModel for queueing pressure. It is a capacity planner, not a request-level scheduler.
Methods
| Name | Description |
|---|---|
| solve | Return the minimum replica count that satisfies the target P99. |
solve
solvers.ServingCapacityModel.solve(
model,
hardware,
qps,
target_p99_latency_ms,
max_seq_len=2048,
mean_request_tokens=None,
output_tokens=128,
max_batch_size=32,
precision='fp16',
efficiency=0.5,
max_replicas=1024,
service_time_cv=1.0,
)Return the minimum replica count that satisfies the target P99.
Composes three first-order models and then scans replica counts upward (1, 2, …) until the estimated request P99 meets the target:
ContinuousBatchingModelsizes the per-replica active batch and token throughput under the memory wall, using paged allocation over the request-length distribution;ServingModel(at that batch and the mean request length) gives TTFT/ITL, so the base request latency isTTFT + ITL * output_tokens;TailLatencyModel(M/M/c) adds the P99 queue wait at each candidate replica count.
Estimated P99 = base request latency + P99 queue wait. Per-replica QPS capacity = token throughput / output_tokens.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| model | TransformerWorkload | The model being served. | required |
| hardware | HardwareNode | The per-replica accelerator. | required |
| qps | float | Target aggregate arrival rate in queries per second (> 0). | required |
| target_p99_latency_ms | float | End-to-end P99 latency target in milliseconds. | required |
| max_seq_len | int | Longest context a request may reach, prompt plus generated tokens. | 2048 |
| mean_request_tokens | float | Mean KV tokens a request fills, in (0, max_seq_len]. None means every request fills max_seq_len. Shorter requests raise paged concurrency in ContinuousBatchingModel. |
None |
| output_tokens | int | Generated tokens per request; converts token throughput to QPS. | 128 |
| max_batch_size | int | Cap on concurrent requests per replica. | 32 |
| precision | str | Numerical precision for weights and KV cache. | 'fp16' |
| efficiency | float | Software efficiency factor in (0, 1]. | 0.5 |
| max_replicas | int | Search cap; reported as the requirement when infeasible. | 1024 |
| service_time_cv | float | Coefficient of variation of service time (1.0 = M/M/c). | 1.0 |
Returns
| Name | Type | Description |
|---|---|---|
| ServingCapacityResult | Replica count, capacity/utilization, latency decomposition, and the limiting bottleneck (‘Memory’, ‘Capacity’, ‘Tail Latency’, ‘Base Latency’, or ‘Feasible’). |
See Also
ContinuousBatchingModel.solve : Paged per-replica token capacity. ServingModel.solve : Request prefill and decode time. TailLatencyModel.solve : Queue-wait approximation.
Notes
Equation: request_time = TTFT + output_tokens*ITL; replica capacity is paged token throughput/output_tokens. Candidate P99 adds the queue wait to request_time and accepts the first replica count meeting the SLA.
Assumptions: identical replicas, capped exponential request lengths, Poisson arrivals, and the service-variability approximation in TailLatencyModel. Mean request length sets fixed-context decode cost. Excludes: routing overhead, growing decode contexts, admission transients, and runtime workspace. Feasibility is conditional on these assumptions; reaching max_replicas without meeting the SLA returns feasible=False.
References
Derivation: divide a token budget by tokens per request to obtain QPS, then compose independent request service and queue-wait estimates.
Examples
>>> from mlsysim import Hardware, Models
>>> from mlsysim.solvers import ServingCapacityModel
>>> r = ServingCapacityModel().solve(Models.Language.Llama3_8B, Hardware.Cloud.H100,
... qps=1, target_p99_latency_ms=100000, max_replicas=2)
>>> bool(r.feasible and r.required_replicas >= 1)
True