Lesson 3 of 5 Performance Optimization for GenAI

Maximizing Foundation Model Throughput

This lesson covers token flow, batching and concurrency techniques that increase how much work a generative AI system completes per unit of time, since throughput is limited by token quotas or GPU capacity rather than CPU.

Learning outcomes

After completing this lesson, you will be able to:

  • Reduce tokens per request to increase capacity.
  • Separate bulk work from interactive traffic with batch inference.
  • Manage concurrent invocations to avoid throttling storms.

Token processing optimisation

Model quotas and GPU capacity are both consumed in tokens, so the number of requests that the same capacity can serve depends on how many tokens each request uses. Every token saved per request raises throughput. Shorter prompts, fewer retrieved chunks, prompt caching of repeated prefixes and shorter outputs all increase the number of requests served before a quota or a GPU is saturated.

On self-hosted models, the serving engine determines how many tokens per second a GPU delivers. Continuous batching keeps the GPU busy by adding new requests to a running batch as others finish, paged attention fits more concurrent requests into GPU memory, and quantisation reduces the memory and compute each token needs.

Fill in the number

Tokens and throughput

Exam skills 4.2.3

See how token savings raise the number of requests a fixed quota can serve.

Log in to try this activity Interactive activities are free with an account.

Batch inference strategies

Interactive users and bulk jobs compete for the same on-demand quota, so a large overnight job can cause throttling for users who arrive early. Work that does not need immediate results therefore moves to Bedrock batch inference, which has its own quotas separate from on-demand traffic and costs less for supported models.

Large workloads are split into several input files within the per-job limits and run as concurrent jobs, up to the account's quota for batch jobs. Scheduling batch work outside interactive peaks, and pre-computing results that users are likely to request, such as summaries of new documents, keeps on-demand capacity free for the requests that need an immediate answer.

The following diagram compares two designs for a nightly enrichment job that shares capacity with interactive users.

Separating a nightly enrichment job from interactive users. On-demand calls for 500,000 records shared the quota with users and overran into the morning. Batch inference, split into several files, has its own quotas and costs less; remaining bulk work goes through a queue with bounded concurrency.
Batch inference costs about half the on-demand price for supported models.

Concurrent invocation management

Uncontrolled concurrency causes throttling storms: many clients hit the quota, retry together and fail again. Concurrency management keeps in-flight requests at a level the quota supports: SQS queues with a fixed number of workers, Lambda reserved concurrency or event source maximum concurrency, semaphores or thread pools in application code, and token-bucket rate limiters that budget tokens per minute. Distributed Map in Step Functions sets a maximum concurrency for large fan-outs. Cross-Region inference profiles spread load across Regions, and quota increases raise the ceiling.

import asyncio
limit = asyncio.Semaphore(8)                       # at most 8 concurrent model calls

async def summarize(doc):
    async with limit:
        return await asyncio.to_thread(call_converse, doc)   # boto3 is synchronous, so run it in a thread

async def main():
    return await asyncio.gather(*(summarize(d) for d in documents))

results = asyncio.run(main())

The following table summarises throughput techniques.

TechniqueEffect on throughput
Fewer tokens per requestMore requests within the same TPM quota
Batch inference for bulk workSeparate quotas; interactive capacity freed
Queues and bounded concurrencySteady flow without throttling storms
Cross-Region inferencePooled capacity across Regions
Continuous batching (self-hosted)More tokens per second per GPU
Fix the problem

Throttling storms

Exam skills 4.2.3 · 2.4.3

Find the fix for each throughput problem.

Log in to try this activity Interactive activities are free with an account.
Worked example

Nightly enrichment competing with users

A nightly job enriches 500,000 product records with generated attributes through on-demand calls. It overruns into the morning and interactive users are throttled.

Moving the job to batch inference, split into several files, removes it from the on-demand quota and lowers its cost; any remaining on-demand bulk work goes through a queue with bounded concurrency.

Check yourself

What bounds the throughput of a foundation model?

Show answer

Tokens per minute, so saving tokens increases throughput.

Exam Tips

Remember for the exam

  • FM throughput is bounded by tokens per minute; save tokens to gain throughput.
  • Move bulk work to batch inference with its own quotas.
  • Bound concurrency with queues, reserved concurrency and rate limiters.
  • Cross-Region inference pools capacity across Regions.