Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Modal 8 min read Case study mediumAdept

Linear programming for fun and profit

Modal provisions GPU and CPU capacity across multiple clouds with a "resource solver" that formulates demand, prices, availability and per-instance limits as a linear program. It solves that program with Google's GLOP simplex solver from OR-Tools and outputs a delta of instances to spin up or down. Cheap preprocessing heuristics, such as pruning instance types, keep solves to fractions of a second rather than minutes, trading a little optimality for predictable scaling latency. Background workers make the actual cloud requests and feed observed capacity-limit failures back into later solves. The approach lets Modal exploit price arbitrage, such as H200s priced below H100s, and saves millions per year.

Assumes: linear programming basicscloud instance provisioning

Related posts

  • A linear programming approach for optimizing features in ML models

    Meta Engineering mediumAdept

    Choosing which ML features to admit under limited infrastructure capacity can be framed as an integer linear program that maximizes model gain subject to per-service capacity constraints. Greedy picks by gain, or by gain per unit of storage, fall short once features consume several resources (storage, memory, CPU) and optional compression trades gain for capacity in another service. Meta's ads ranking team encodes these constraints with boolean selection variables in CVXPY. The same model is rerun across capacity values to quantify the marginal return on investing in each service and to map substitution tradeoffs between services, replacing a manual feature-approval process.

  • How to price serverless GPUs

    Modal easyNovice

    Whether serverless or reserved GPUs are cheaper comes down to one comparison: the ratio of reserved to serverless cost equals the reservation discount multiplied by the workload's peak-to-average demand ratio, so serverless wins whenever peak-to-average exceeds the discount. Reservations must be sized for peak demand over the whole contract, while serverless bills only for actual use. Modal reports typical discounts of 2-5x against peak-to-average ratios of 5-10x for inference, training and agentic workloads, and 10-100x for burst load above a reserved baseline. The model's assumptions are also examined: perfect demand prediction, instant autoscaling, all-or-none strategies and GPU cost as the only factor.

  • How we achieved truly serverless GPUs

    Modal mediumAdept

    Modal cuts GPU inference replica cold starts from roughly 2,000 seconds to about 50 seconds, a 40x speedup, by attacking each stage of spin-up. A solver-managed buffer of idle, health-checked GPUs, allocated with Google's GLOP linear program, takes instance provisioning out of the hot path. ImageFS, a libfuse filesystem, serves container images lazily from a tiered content-addressed cache, and CPU and CUDA checkpoint/restore skip host- and device-side initialization. The motivation is GPU Allocation Utilization: spiky inference demand leaves fixed allocations at 10-20% use, and fast autoscaling raises utilization and quality of service together.

  • Outgrowing Lambda Functions, Not Lambda | Honeycomb

    Honeycomb mediumAdept

    Honeycomb moved most of its S3-backed query mapper compute from Lambda Functions to AWS Lambda Managed Instances, eventually cutting query costs 40-56%, though the switchover itself was easy and the savings came from months of tuning. Lambda Functions had grown 5-8x more expensive per core-millisecond than EC2 because of an older Graviton mix and GB-second billing for network-bound waiting on S3. Agent-driven MCP queries also turned spiky load into a steady baseline. LMI is about 7.5x cheaper per CPU-second, but it bills for the whole fleet, so it only breaks even above roughly 12.5-14% utilization. Getting there required 16-way multi-concurrency, changes to GC, memory shedding and telemetry, capping the bang-bang autoscaler's max fleet size, and retry-then-spill routing plus query batching.

  • The future of AI needs more flexible GPU capacity

    Modal easyNovice

    Inference and many other GPU workloads are highly volatile: Poisson noise, daily and weekly cycles, viral spikes and bursty batch jobs, which pushes fixed-reservation GPU clusters below 50% utilization. A service at 1 req/s with 10s requests needs 12-15 GPUs rather than 10 just to absorb noise. Utilization improves through demand pooling across tenants (provision for the peak of the sum, not the sum of peaks), supply pooling across regions, GPU types and clouds, fast container and model startup, and shifting latency-insensitive work to off-peak hours. GPU spend is expected to skew toward inference served from on-demand, serverless capacity, with long-term reservations no longer the default.

The quest for software engineering knowledge.

Look:
Layout: