AWS Builder Center
Serverless inference for decision models with AWS Lambda

Serverless inference for decision models with AWS Lambda

An evaluation of AWS Lambda as a serverless inference service for decision models using SnapStart to reduce cold starts. We compare both startup paths and discuss the trade-off between first-request latency and the cost of keeping a snapshot cached.

Serverless inference for decision models with AWS Lambda

Hosting a language model often means keeping inference capacity ready to serve the next request. In these cases, dedicated endpoints and continuously running containers provide predictable performance, but their idle capacity can be difficult to justify for an application that makes occasional decisions throughout the day.
Decision models (also called System One Models) create the opportunity to use a different compute pattern. Their task is to evaluate a limited set of alternatives, such as choosing a workflow or determining whether a request needs review. Their streamlined architecture makes them lightweight and fast, enabling you to serve decisions without a dedicated GPU endpoint.
In this post, we explore AWS Lambda as a compute platform for decision models. In particular, we ran a 3-billion-parameter model with 4-bit quantization on CPU and used AWS Lambda SnapStart to reduce the delay of starting a new execution environment. The approach combines on-demand inference compute with a snapshot of the initialized model, allowing the service to scale to zero while minimizing cold starts to meet real-time inference requirements.

Why decision models change the hosting requirements?

We know that a generative model produces an answer one token at a time. A decision model can instead score predefined alternatives and return a compact result, removing the autoregressive text-generation loop. Instead of sampling across an entire vocabulary of tens of thousands of tokens, it projects the final representation directly onto a fixed classification head to output calibrated probabilities.
This narrower task changes what the infrastructure needs to provide. Without the high memory overhead of a continuous KV cache or the massive parallelism required for multi-token generation, the serving stack no longer depends on dedicated, GPU-accelerated instances. Compute demands shift from heavy, sustained GPU workloads to lightweight, bounded matrix operations. Consequently, the decision model can comfortably fit in an AWS Lambda instance and execute entirely on CPU.
Dedicated inference endpoints (sync/async) and persistent container services remain useful for sustained traffic, GPU acceleration, and demanding latency targets. Batch compute can release capacity between jobs, but waiting for a new job environment is often unsuitable for an interactive request. The opportunity here is a small decision service whose traffic is intermittent and whose latency budget allows CPU inference measured in seconds.

Technical implementation

The service packages a CPU inference engine and quantized model weights in a container image. Lambda loads the model during environment initialization and returns the probabilities associated with a decision. There is no call to an external model endpoint and no model download in the application’s request path.
We use llama.cpp as the inference engine, with a thin Python handler around it. The engine remains loaded when Lambda reuses an execution environment, so subsequent requests can proceed directly to scoring, while Lambda automatically provisions additional environments as concurrency scales.
The main obstacle appears when a new environment is required. Packaging the weights in the image removes a separate application download, but the model still needs to be read and initialized. That work can take considerably longer than the decision itself, making this initial latency a critical bottleneck.

Solution?

 Lambda SnapStart  changes how new execution environments start. When a function version is published, Lambda initializes an environment and captures an encrypted snapshot of its memory and disk state. Subsequent environments can resume from that snapshot instead of repeating initialization.
For model inference, the useful state includes the loaded weights and initialized inference engine. Before snapshot capture, our implementation loads the model, starts the engine, and performs a small priming inference. After restoration, it refreshes environment-specific identifiers and local client state, then checks that the preserved engine is healthy.
Three flows show model preparation before snapshot capture, restoration followed by CPU inference in

This distinction matters: enabling SnapStart alone does not help work that is deferred until the request handler runs. The model must be initialized before the snapshot is taken. AWS has demonstrated this principle for  CPU inference on Lambda , and  SnapStart support for container images  makes it applicable to this packaging approach.
SnapStart reduces startup overhead; it does not remove restoration time or accelerate the inference computation itself.

What we measured

We compared two configurations of the same service: ordinary on-demand initialization and SnapStart restoration. Both used the same model, container image, inference settings, and Lambda compute configuration (10 GB, x86).
The experiment comprised approximately 200 direct Lambda invocations using 12 unique synthetic English inputs spanning 100–400 input tokens. Each configuration received a burst of 12 concurrent requests, verified to use 12 distinct new execution environments, followed by 72 warm requests at concurrency three. The warm phase repeated the same inputs six times in a fixed shuffled order.
We measured first-request latency from the calling SDK through receipt of the response. It therefore includes startup or restoration, inference, and transport. This is more representative of the caller’s wait than an initialization metric alone: in our on-demand implementation, model loading happens inside the handler and is not included in Lambda’s runtime  Init Duration .

Results

Mean latency
On-demand initialization
With SnapStart
First request in a new environment
37.27 seconds
6.06 seconds
Warm request
3.39 seconds
3.43 seconds
SnapStart reduced mean first-request latency by 83.7% in this experiment. The median also improved, from 20.45 to 5.69 seconds. This matters because several slow on-demand starts raised the mean: the observed first-request range was 17.15–74.88 seconds without SnapStart, compared with 4.28–8.79 seconds with it.
Individual first-request and warm-request latencies for ordinary on-demand initialization and SnapSt

Warm performance remained essentially unchanged. The inference engine’s scoring API averaged approximately 3.32 seconds in both configurations. Shorter inputs took less time than longer ones, reinforcing that input processing remains a cost even when the model generates no output tokens.
For reference, these tests used  LiquidAI d1-3B , in its Q4_K_M GGUF quantization.
The startup sample is small. We ran the on-demand configuration first and SnapStart second, without independently controlling AWS platform caches or client-network variation. These measurements demonstrate the behavior of this configuration and input range; they do not establish a latency guarantee or performance for longer inputs.

Cost follows requests, with a snapshot trade-off

Lambda avoids reserving a continuously running inference instance. Execution charges follow allocated memory and billed duration, making the pattern worth evaluating for workloads with idle periods. The memory setting also determines CPU allocation, so selecting it only from the size of the model weights can sacrifice inference speed. See  Lambda’s memory configuration guidance .
SnapStart adds an economic trade-off. Although inference compute can scale to zero, maintaining the snapshot has a caching charge, and creating an environment from it incurs a restoration charge. Scale-to-zero compute therefore does not mean a zero idle bill. The relevant dimensions are described in  AWS Lambda pricing .
As an illustration, using Milan list prices, 30,000 requests over 30 days, a hypothetical 10% new-environment rate, and one continuously cached 10 GB snapshot yields approximately $89 per month with SnapStart, compared with $39 without it, using the measured billed durations. These estimates exclude image storage, logging, data transfer, snapshot preparation and maintenance initialization, discounts, and taxes. They are a cost model, not a measured bill or a comparison with other hosting services.
In that scenario, the snapshot buys a substantial reduction in startup latency at a higher total cost. Request volume, the frequency of new environments, and the chosen memory allocation determine whether that trade-off fits the application.

Where this approach fits

This architecture is ideal when a workflow maps directly to a decision model’s native primitives, such as choice or score in a closed candidate space, rather than open-ended text generation. At the same time, the model must fit comfortably within AWS Lambda’s 10 GB memory limit while meeting the required accuracy benchmarks. This pattern delivers maximum value for sporadic or unpredictable traffic with extended idle periods, where scaling to zero prevents paying for unused capacity and eliminates the overhead of maintaining an always-on compute cluster.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article