AWS Lambda 现已支持 GPU 推理:每块 GPU 上的单个模型可由 48 个并发调用共享
原题AWS Lambda Now Runs GPU Inference with 48 Concurrent Invocations Sharing One Model per GPU
推荐理由AWS Lambda 允许常驻模型在托管 GPU 上服务并发事件,可据此评估推理应用是否值得省下自管基础设施的工作。
读前速览
AWS 通过托管实例为 AWS Lambda 引入 GPU 支持,使 G 系列 EC2 实例上的单个模型可由多达 48 个并发调用共享,并支持以容器映像部署和事件驱动扩缩容。
AWS Lambda 的 GPU 支持让事件函数可在 G 系列 EC2 实例上运行,并支持多达 48 个并发调用共享 GPU 内存中的同一个模型。
该功能支持以容器映像部署,并自动完成资源配置、修补和扩缩容。同一执行环境中的并发调用会共享一份模型副本,从而提高推理工作负载的资源利用效率。
AWS 提供 5 种 GPU 基础映像(CUDA、CuPy、PyTorch、vLLM、SGLang);使用 vLLM 和 SGLang 时,针对 Hugging Face 或 S3 模型源无需编写处理程序代码。
开发者可以通过 MODEL_ID 环境变量指定模型仓库,并通过更改配置切换模型。与自行管理 GPU 集群、驱动程序或设备插件相比,这简化了部署流程。
实际测试显示,L4 GPU 上的推理速度比 CPU 快 66x;在 48 个并发请求下,成功处理了 417 次调用,速度达到每秒 3,400-3,600 个 token。
早期用户报告了显著的性能提升,但 Terraform 等一些基础设施工具尚不支持新的 AcceleratorConfig 参数。新建的 AWS 账户可能没有 GPU vCPU 配额,某些实例类型需要先申请提高配额。
完整摘要
AWS 已为运行在 Lambda 托管实例上的 AWS Lambda 事件函数添加 GPU 支持,可将其作为容器映像部署到 EC2 G 系列实例(G4dn、G5、G6、G6f、Gr6、Gr6f、G6e)上。该功能支持多个并发调用共享 GPU 内存中的同一个模型(每个执行环境最多 48 个),并根据 GPU 利用率、CPU 利用率和并发数自动扩缩容。AWS 提供 5 种 GPU 基础映像,包含 CUDA、CuPy、PyTorch、vLLM 和 SGLang;定价为 EC2 按需费率加 9.75% 的管理费。实际测试显示性能显著提升,但 Terraform 等一些基础设施工具尚未完全支持新的 AcceleratorConfig 参数。
AWS 已为 AWS Lambda 添加 GPU 支持:运行在 Lambda Managed Instances 上的事件函数现在可以运行于 EC2 G 系列实例(发布时支持 G4dn、G5、G6、G6f、Gr6、Gr6f 和 G6e),以容器镜像形式部署,并可由与其他函数相同的事件源触发。该功能已在同时提供 Managed Instances 和 G 系列实例的商业区域全面推出。定价为 EC2 按需费率,加上 9.75% 的管理费,以及每百万次请求标准的 0.20 美元费用。AWS has added GPU support to AWS Lambda: Event Functions running on Lambda Managed Instances can now run on EC2 G-series instances (G4dn, G5, G6, G6f, Gr6, Gr6f and G6e at launch), deployed as container images, and triggered by the same event sources as any other function. The feature is generally available in the commercial regions where both Managed Instances and G-series instances exist. It is priced at the EC2 On-Demand rate plus a 9.75 percent management fee and the standard $0.20 per million requests.
正如 InfoQ 去年 12 月报道的那样,托管实例允许函数在客户自行选择并付费的 EC2 容量上运行,而 Lambda 负责资源配置、打补丁和扩缩容,并让多个调用共享同一个执行环境。该功能发布时尚不支持 GPU。AWS 高级专家解决方案架构师 Daniel Abib 描述了这一变化对运维人员的影响:As InfoQ reported last December, Managed Instances let a function run on EC2 capacity the customer selects and pays for, with Lambda handling provisioning, patching and scaling and several invocations sharing one execution environment. GPUs were missing at that launch. Daniel Abib, senior specialist solutions architect at AWS, describes the operator's side of the change:
构建 OCI 镜像,将函数指向该镜像,然后由 Lambda 负责资源配置、扩缩容和事件集成。无需协调 GPU 驱动程序、CUDA 版本或 AMI,也无需运维集群或设备插件。You build an OCI image, point the function at it, and let Lambda handle provisioning, scaling, and event integration. There are no GPU drivers, CUDA versions, or AMIs to reconcile, and no clusters or device plugins to operate.
容量提供程序会列出允许使用的实例类型、VPC 和 vCPU 上限;Lambda 会选择有可用容量的最新一代实例,如果较新一代容量不足,则回退到较旧一代:A capacity provider lists the allowed instance types, the VPC and a vCPU ceiling; Lambda picks the newest generation with capacity and falls back to older generations when newer ones are short:
"InstanceRequirements": {
"AllowedInstanceTypes": ["g5.2xlarge", "g6.2xlarge", "g6e.2xlarge"]
},
"CapacityProviderScalingConfig": { "ScalingMode": "Auto", "MaxVCpuCount": 96 }
该函数通过一个新的 AcceleratorConfig 块声明其 GPU 内存,该块与 memory、timeout、storage 以及每个环境的并发数并列:The function declares its GPU memory through a new AcceleratorConfig block, next to memory, timeout, storage, and a per-environment concurrency:
"MemorySize": 16384,
"Timeout": 900,
"EphemeralStorage": { "Size": 32768 },
"Environment": { "Variables": { "MODEL_ID": "Qwen/Qwen2.5-1.5B-Instruct" } },
"CapacityProviderConfig": {
"LambdaManagedInstancesCapacityProviderConfig": {
"CapacityProviderArn": "arn:aws:lambda:us-east-2:111122223333:capacity-provider:lmi-gpu-cp",
"ExecutionEnvironmentMemoryGiBPerVCpu": 4,
"PerExecutionEnvironmentMaxConcurrency": 4
}
},
"AcceleratorConfig": { "AcceleratorMemorySize": 16 }
同一环境中的并发调用共享一份驻留在 GPU 内存中的模型副本,每个环境最多支持 48 个并发调用;扩缩容会根据 GPU 利用率、CPU 利用率和并发量进行。发布一个版本时,系统会预置环境、下载权重,并在首个事件到达前预热引擎;Seekable OCI 惰性加载最多可将环境启动时间缩短 70%。Concurrent invocations in one environment share a single copy of the model in GPU memory, up to 48 per environment, and scaling follows GPU utilization, CPU utilization, and concurrency. Publishing a version provisions the environments, downloads the weights, and warms the engine before the first event arrives; Seekable OCI lazy loading can cut environment start time by up to 70 percent.
AWS 提供五种 GPU 基础镜像:仅包含 CUDA 的镜像、CuPy、PyTorch、vLLM 和 SGLang。两个推理服务器无需编写处理程序代码;MODEL_ID 变量指向 Hugging Face 或 ModelScope 仓库、S3 前缀或本地路径,更换模型只需修改配置并发布新版本:AWS ships five GPU base images: CUDA only, CuPy, PyTorch, vLLM, and SGLang. The two inference servers need no handler code; a MODEL_ID variable points to a Hugging Face or ModelScope repository, an S3 prefix, or a local path, and a model swap is a configuration change followed by a new version:
aws lambda update-function-configuration \
--function-name my-gpu-function \
--environment 'Variables={MODEL_ID=s3://amzn-s3-demo-bucket/models/Qwen2.5-1.5B-Instruct/,VLLM_LOAD_FORMAT=runai_streamer}'
限制条件列在发布公告中:容器镜像最大 32 GB,临时存储 32 GB,内存 2 到 32 GB,加速器内存 3 到 48 GB,每个容量提供程序最多 15,000 个 vCPU;异步调用和事件源映射调用的超时时间最长为 90 分钟。Abib 用一句话划清了与竞争对手的界限:那些掩盖同样工作量的无服务器 GPU 服务,“往往位于 AWS 环境之外,无法原生接入事件源、身份体系或网络。”The limits are in the launch post: container images up to 32 GB, 32 GB of ephemeral storage, 2 to 32 GB of memory, 3 to 48 GB of accelerator memory, 15,000 vCPUs per capacity provider, and a timeout of up to 90 minutes for asynchronous and event source mapping invocations. Abib draws the line against the competition in one sentence: serverless GPU services that hide the same work "often sit outside your AWS environment, with no native event sources, identity, or networking."
首批上手报告在一天内便陆续出现。Classmethod 的 Akaike 曾在 12 月发现没有任何 G 型实例获准使用后,修正了一场会议演讲;这次,他在 us-east-1 尝试了所有加速实例类型,发现 81 种中有 37 种获准使用,且全都属于 G 系列;P 系列、G7、Inferentia、Trainium,以及基于 Graviton 的 g5g 均遭拒,zip 软件包也一样。一个 PyTorch 基准测试在 L4 上的运行速度约为该实例 CPU 的 66 倍。尽管如此,Terraform 和 Cloud Control 提供程序都还不认识 AcceleratorConfig,而且新账户的 GPU vCPU 配额为零:“如果使用 g6.xlarge(4 个 vCPU)并采用默认的 3 个实例,就需要 12 个 vCPU 的配额。”一位名为 sasidhar-aws 的用户于 11 月 16 日提交的 Terraform 提供程序问题和拉取请求,以及同一用户提交的另一项拉取请求,至今仍处于未解决状态。The first hands-on reports came within a day. Classmethod's Akaike, who had corrected a conference talk in December after finding that no G-type was accepted, tried every accelerated instance type in us-east-1 and found 37 of 81 accepted, all G-family; P-family, G7, Inferentia, Trainium, and the Graviton-based g5g were refused, as were zip packages. A PyTorch benchmark ran about 66 times faster on the L4 than on the instance's CPU. Still, neither Terraform nor the Cloud Control provider knew AcceleratorConfig yet, and the GPU vCPU quota in a fresh account is zero: "if you use g6.xlarge (4 vCPU) with the default three instances, you need a quota of 12 vCPUs." A Terraform provider issue and pull request, opened on 16 November by a user named sasidhar-aws, and a pull request from the same user remain open.
第二项测试由一位以 xbill 为笔名的 AWS Community Builder 撰写:他通过 vLLM 镜像,在一台 g6.2xlarge 上运行 Gemma 4 E2B,并将 Google 的 4 位 QAT 权重和一个推测解码起草器打包进 9 GB 的镜像中。一个环境处理了全部 48 个并发请求,417 次调用也全部成功;单个请求时速度约为每秒 130 个 token,48 个请求时则达到每秒 3,400 至 3,600 个 token。瓶颈在流水线,而不在 GPU:从发布到版本处于活动状态耗时 484 秒;Lambda 拒绝了 Docker 镜像索引,直到将其作为单平台清单推送后才接受;此外,处理程序会返回完整回复,因此无法测量首个 token 的生成时间。他的结论严格限定在这一范围内:A second test, by an AWS Community Builder writing as xbill, put Gemma 4 E2B on a single g6.2xlarge through the vLLM image, with Google's 4-bit QAT weights and a speculative-decoding drafter baked into a 9 GB image. One environment served all 48 simultaneous requests and every one of 417 calls succeeded, at roughly 130 tokens a second for a single request and 3,400 to 3,600 at 48. The friction was in the pipeline rather than the GPU: 484 seconds from publish to an active version, a Docker image index that Lambda rejected until it was pushed as a single-platform manifest, and a handler that returns complete replies, so time to first token could not be measured. His verdict keeps to that scope:
对于由事件、队列或其他 AWS 服务触发的模型,Lambda GPU 函数是更简单的方案:一个镜像、一个函数,Lambda 会让服务器保持运行并路由请求。一次只有少数用户聊天时,保留草稿模型;批量负载较重时,则在不启用它的情况下部署。For a model behind events, queues or other AWS services, the Lambda GPU function is the simpler road: one image, one function, and Lambda keeps the server alive and routes the requests. Keep the drafter on for a chat with a few users at a time, and publish without it for heavy batch load.
当需要流式回复或完全控制服务器时,他会写道:“自己在 EC2 G6 上运行 vLLM。”When streamed replies or full control of the server are needed, he writes, "run vLLM on an EC2 G6 yourself."
定价模式沿用了 Managed Instances 引入的模式,GPU 的费用低于 CPU 实例类型收取的 15%。Savings Plans 和 Reserved Instances 均适用于该实例,而且不收取持续时间费用,因此只要最低环境数量大于零,实例就会持续计费。Yan Cui 在 12 月对该模式所做的分析,当时其中仍写着“GPU 实例不受支持”,同样适用于 GPU 情况:The pricing model is the one Managed Instances introduced, with a lower fee for GPUs than the 15 percent charged on CPU instance types. Savings Plans and Reserved Instances apply to the instance, and there is no duration charge, so an instance bills for as long as the minimum environment count is above zero. Yan Cui's December analysis of the model, written when it still carried the line "GPU instances are NOT supported," applies to the GPU case unchanged:
常规 Lambda 函数可以利用大型共享 EC2 实例池快速扩展。使用托管实例时,启动新的 EC2 实例需要数十秒。因此,如果流量出现大规模且难以预测的激增,这种方式并不合适。Regular Lambda functions can scale rapidly by tapping into a large, shared pool of EC2 instances. With managed instances, it takes tens of seconds to launch new EC2 instances. As such, it's not a good fit when you have large, unpredictable spikes in traffic.
托管实例目前仍只支持事件函数,因此 GPU 路径尚未延伸至 Web 函数——也就是 Lambda 今年新增的 HTTP 服务器形态;AWS 尚未说明未来是否会支持。Managed Instances still support only Event Functions, so the GPU path does not yet reach Web Functions, the HTTP-server shape Lambda gained this year, and AWS has not said whether it will.