通过 AWS Lambda 提供 Qwen 服务,为了乐趣与 80 倍负利润
Serving Qwen via AWS Lambdas for fun and 80x negative profit

原始链接: https://noahbuilt.it/writing/qwen-on-5600-lambdas

作者测试了 AWS Lambda 是否能对自托管决策模型进行推理,方法是将 H2O-Lightning(一个 Qwen3.5-4B 微调模型)拆分为 32 层。在 3 GB Lambda 限制下,每一层/块成为一个 Lambda 任务,扇出为约 5600 次调用。流水线可行:任务像阶梯一样等待依赖,数学运算也成功。但性能和成本很差:读取约 4000 个 token 耗时 17 秒,每百万 token 成本 8.40 美元,比托管的 Gemini Decision 1 模型每百万 0.10 美元高出 80 倍以上。结论:模型工程是可触及的,但基于 CPU 的 Lambda 推理缺乏 GPU 效率和成本套利。

Hacker News 上的一个帖子讨论了一个通过 AWS Lambda 提供 Qwen 服务的实验,描述为有趣但亏损 80 倍。评论者建议调整 Lambda 内存/CPU、使用 Graviton/ARM 以及更新的托管 GPU 实例;作者指出优化使其成本降低/速度提升约 3 倍,但 GPU 实例可能是下一个杠杆。其他人称赞该实验并建议使用 Cloudflare Workers,不过有人说那里只能运行极小的量化模型,且 WebGPU 支持已被移除。作者使用了 4B 模型,从 ContractNLI 采样评测,并每四分钟通过 ping 保持约 100 个函数处于热启动状态。评论者指出更小的模型和冷启动问题。有人指出将一次模型调用拆分到 5600 个 Lambda 上,理论上可以在没有大型机器/GPU 的情况下运行任意大的开放模型,并询问扩散模型是否因非串行 token 生成而更合适。总体:创意十足但不经济,指出了优化和 GPU 方向。
相关文章

原文

Who needs a GPU?

In my work at Bevyl I was really impressed by the performance and cost characteristics of AWS Lambdas. They can massively distribute and fan out CPU-bound work, which is amazing for things like ffmpeg on long videos.

So I was curious if it was possible to run inference on self-hosted models using Lambdas. It was a random idea built on a hunch, and I like to prove such ideas right or wrong by building. In this case I was very wrong, but it was a good lesson!

I picked H2O-Lightning, a fine-tune of Qwen3.5-4B, because I wanted a small model built for decisions. I figured if this architecture had any legs, only doing decision models (a single forward pass) is the move. A decision model reads a document and answers a question about it by picking one option.

Fanning out

So the trick, if it's possible, would be fanning out. I was inspired how Remotion uses massively parallelized Lambdas to render videos.

I wanted to prove this was possible to do, so I kept a constraint of a 3 GB limit for Lambdas. The whole model is 9.3 GB, so it does not fit in one. But it has 32 layers of about 225 MB each, and one layer fits. That gave me one Lambda job per layer per block of tokens.

Think of the Lambda as a simple idempotent API. A job reads inputs from S3, does the math, and writes one object back.

x = load(f"{doc}/{layer - 1}/{block}")
memory = load(f"{doc}/{layer}/{block - 1}")

y, memory = model.layers[layer](x, memory)

s3.put_object(
    Key=f"{doc}/{layer}/{block}",
    Body=pack(y, memory),
)

Each job waits on the layer above for the same block and on its own previous block. Each layer starts one step after the layer above it, like a staircase 32 layers deep.

92% of the work parallelizes, 8% is serial

hoped it couldbe done hereactually done herelayer 1layer 2layer 3layer 4layer 5waiting its turntime
Parallel but not.

I'm proud of the win: splitting a model call across 5,600 Lambdas is kinda wild.

One request, 32 layers, 5,600 Lambda invocations

Lambda job that has to run in orderLambda job that can run any timePoint at a job to follow its block.

0 s5 s10 s15 sseconds after the read startslayer 1layer 8layer 16layer 24layer 32

Win: the math worked; I had split a model call into 5,600 Lambda invocations.
Fail: 17 seconds to read ~4k tokens.

The bill

If it was 40x slower but 50% cheaper, that'd be interesting.

Reading a 4,000-token document takes 17 seconds and costs 3.4 cents. That works out to $8.40 per million tokens. Google sells a hosted decision model, Gemini Decision 1, for $0.10 per million tokens, so the same read costs 0.04 cents there. Mine is more than 80 times more expensive.

More than 80 times the price of a hosted decision model

$0.10$1$10dollars per million tokens readtarget: comparable pricingGemini Decision 1, hosted$0.10mine, on Lambda$8.40

Takeaways

Model engineering is not so hard in 2026!

I'm a dumb application developer, but I was able to play with model layers and transformers API pretty easily! With good devex, it feels like open models are just another API at this point.

I need a GPU

Learned this the hard way but a very powerful lesson! One layer over a few thousand tokens is a big matrix multiply, which is what GPUs are built for. My goal was to learn anyway so it's a good lesson.

Freedom ain't free

CPU still costs dollars, there's no arbitrage here.

联系我们 contact @ memedata.com