Inference Cost (Inference $)

Inference cost is what it costs to serve predictions once the model is trained. It is made of compute, memory, network and platform fees, and it is usually quoted as a cost per request or per thousand tokens. Specify what the denominator counts: model invocations, successful user requests, tokens, or completed tasks. A user request that triggers retrieval and several model calls is not equivalent to one inference. Compare the same workload and quality requirement before treating a lower unit cost as an improvement.

Utilization changes allocated cost per request

For a fixed provisioned fleet over a fixed period, divide its cost by the completed request count. A different hardware rate, model size, throughput, or capacity lifetime changes the numerator, so utilization alone does not define inference cost.

For an illustrative fleet of four instances at 2.40 per hour over 720 hours, compute cost is 6,912. If each instance sustains 22 requests per second, nominal monthly capacity is 228,096,000 requests. At 200,000 requests the allocated cost is 6,912/200,000 = 0.03456 per request; at full nominal capacity it is about 0.0000303. The approximately 1,140-fold difference comes from changing the denominator while keeping this particular fleet fixed. The capacity estimate assumes steady throughput and does not establish a latency target.

A measured bill and request count can establish average cost without measuring utilization. To transfer that estimate to another workload, however, also explain traffic timing, request mix, model, and serving configuration. Idle headroom may be necessary to meet a response target; eliminating all idle capacity can increase delay or failures.

The AWS inference guide describes serving patterns with different capacity lifecycles. When idle reserved capacity is the main cost, consolidating traffic or selecting a serving mode that releases idle capacity may help. Whether this is the cheapest improvement depends on the workload, latency target and model throughput.

Batching buys cost with latency

Batching processes several examples together. It can share overhead and improve hardware use, but memory, sequence lengths, padding, and the modelโ€™s kernels limit the gain. The NumPy calculation below assumes a batch takes 9 + 1.6b milliseconds for b items. It computes throughput and compute-only cost at continuous full batches; these values are hypothetical rather than a benchmark. Throughput is b divided by the batch time, and the compute cost of one million items is 1,000,000 divided by throughput, converted to hours and multiplied by the assumed 2.40 per instance-hour. The last column divides each batch time by the single-item time of 10.6 ms.

fixed_ms, per_item_ms, rate_hour = 9.0, 1.6, 2.40
single_ms = fixed_ms + per_item_ms


def batch_metrics(b):
    lat = fixed_ms + per_item_ms * b                # processing time of one batch, ms
    rps = b / (lat / 1000)                          # items per second at full batches
    cost_1m = 1_000_000 / rps / 3600 * rate_hour    # compute cost of one million items
    return lat, rps, cost_1m, lat / single_ms


print("batch  processing ms  items/second  cost per 1M  processing ratio")
for b in (1, 2, 4, 8, 16, 32, 64):
    lat, rps, cost_1m, ratio = batch_metrics(b)
    print("%5d %14.1f %13.1f %12.2f %16.1fx" % (b, lat, rps, cost_1m, ratio))
batch  processing ms  items/second  cost per 1M  processing ratio
    1           10.6          94.3         7.07              1.0x
    2           12.2         163.9         4.07              1.2x
    4           15.4         259.7         2.57              1.5x
    8           21.8         367.0         1.82              2.1x
   16           34.6         462.4         1.44              3.3x
   32           60.2         531.6         1.25              5.7x
   64          111.4         574.5         1.16             10.5x

Going from one to sixteen reduces modeled cost per million from 7.07 to 1.44 and multiplies processing time by 3.3. At sixty-four, cost is 1.16 and processing time is 10.5 times the single-item value. These are processing times; they exclude waiting to assemble the batch and waiting behind earlier batches.

For Poisson arrivals at rate ฮป and batches filled to b with no timeout, the first item waits on average (bโˆ’1)/ฮป to fill the batch, and the average item waits (bโˆ’1)/(2ฮป). At 20 requests per second and b = 16, mean fill wait alone is 375 ms. A timeout limits fill delay but changes batch sizes and throughput. Budget network, fill, queue and processing time together.

arrival_rate = 20.0
for b in (1, 16, 64):
    print("batch %d: mean fill wait %.1f ms" % (b, (b - 1) / (2 * arrival_rate) * 1000))
batch 1: mean fill wait 0.0 ms
batch 16: mean fill wait 375.0 ms
batch 64: mean fill wait 1575.0 ms

At 20 requests per second, each item in a batch of 16 waits 375 ms on average for the batch to fill, more than ten times the 34.6 ms processing time; at 64 the 1,575 ms wait is about fourteen times the 111.4 ms processing time. Cost per item at full batches keeps falling with batch size while the wait at a given arrival rate grows linearly, so the batch size that minimizes unit cost is not the one that meets a response deadline.

The cost table and the wait calculation assume different traffic. Full batches require arrivals close to the throughput column. Twenty requests per second is only about 4% of the 462 items per second that batches of 16 sustain, so one always-on instance is mostly idle and costs 2.40/3600/20 ร— 1,000,000 โ‰ˆ 33.33 per million requests at any batch size, far above the 1.44 in the table. At about 462 requests per second, where the tableโ€™s cost holds, filling a batch of 16 takes (16โˆ’1)/(2 ร— 462.4) โ‰ˆ 16 ms on average. Low-traffic services therefore cannot get both the large-batch cost and a short wait from the same instance. They can shorten the wait with a timeout, which gives smaller batches, or reduce the idle capacity itself.

The quoted figure is not the realized one

Between the number in the pricing calculator and the number on the invoice sit a series of ordinary operational decisions, each individually defensible.

Build a cost allocation from measured components: production capacity, temporary rollout overlap, development environments included in scope, storage, network transfer, API charges, and operational labor if the estimate includes it. Count each cost once. Headroom and off-hours idleness already appear in the bill of an always-on fleet; multiplying that bill by another idle factor would count them again.

As an illustrative reconciliation, suppose production compute costs 6,912, staging and rollout capacity add 600, and storage and transfer add 300. The total is 7,812. If one million successful user requests were completed, allocated cost is 0.007812 each. Failed or retried attempts may contribute to the numerator while the denominator counts only successful requests. State whether cached responses and requests rejected before model execution are included.

Break down a difference from the estimate by actual usage, rates, and allocation scope. This helps distinguish a more expensive model from a less utilized deployment or a broader accounting boundary. Track the resulting plan against a compute budget, and verify that a proposed saving preserves required quality and service.

References


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.