in Large-Scale Distributed Training
Kashish (Uber ML infra, ex-Google YouTube Ads) walks Demetrios through a Sherlock-Holmes-grade Petastorm bug—GPU cluster stuck at 15-20% utilization, six debugging steps, two layer…
永远是数据 IO。模型架构、量化、注意力——通通不是瓶颈。
H100 集群挂在 15-20% 利用率。RAM 实验、SSD 缓存、追踪——直到第 6 步才找到真凶。
表面是远程读慢,底下还藏着一层 PyArrow → NumPy 的隐形转换。
训练有缓冲;推理是延迟与利用率的零和博弈。
吞吐上去了,模型 AUC 反而抖动——因为你打破了 batch order 的确定性。
为什么 Claude Code on local 慢得像狗?答案是 warm start,不是模型大小。
Uber Stop Engine · marketplace matching team lead
ML infrastructure · 主攻 scalability & efficiency
Google · YouTube Ads · Core Search Ranking
"Whenever we want to scale the model,
it's never the model, which is a culprit."
无论是 Google 的 TPU 还是 Uber 的 GPU:
"These bottlenecks exist everywhere
in one form or the another, and they are solvable."
"These GPUs have become so precious, so like a scarce resource that if you are not able to feed them and you're starving the GPUs, you're not doing a good job."
"It is productivity as well."
GPU 队列里抢得头破血流,每一个 slice 都金贵。利用率掉 20%,等于五分之一的预算白烧。
"Do they have to worry about how the data is coming to the GPU?"
他们调架构、对 label、调注意力。喂饭这件事,infra 团队负责。
小模型、小数据切片。所有人都用 Parquet——列存,按理很快。
"It's not efficient to read a slice of data from that pocket tables when you only care about a few row."
读一行,先 load 一整页再 filter。CPU 全在浪费。
按模型实际访问的 slice 重新组织 disk 上的数据布局——这样能 batch read 而不是 point read。
这不是 ML 问题,是 "数据写盘的方式没考虑读模式"——经典的 software engineering 问题,但披着 ML infra 的外衣。
点读 = 浪费 CPU
batch 读 = 同样的数据,吞吐立刻翻倍
经典推荐场景:
naive 写法:每个 item 行都重复一份完整 query feature
"you have duplicate query features for each item and you're throwing it in. This is like a far blob of data you're passing and it's expensive."
优化:query 只发一次,item 打包发,
unflatten on GPU 在 forward prop 之前
"Don't duplicate, pack and unpack."
"Our models were struggling on a 100 chips at 15, 20% utilization."
利用率 15-20% = 一份硬件,烧四份钱、训四倍的时间。
"If you go to B 200, you are gonna waste it a lot. Like they are very fast … they're so hungry that they'll eat up whatever data you're passing."
GPU 越快,"喂不饱"的现象越严重——以前不是问题的,现在变成头号问题。
接下来 6 步——一个完整的工程排错故事。Kashish 在播客里第一次公开讲这套调试过程,对应的 Uber blog "a week or two" 内会发出来。
Uber 的开源分布式训练数据管线(已有,不是这次新建的)。
Producer — 从远程文件系统读 Parquet,塞进 queue
Queue — 应该一直是满的
Consumer — 切 batch、转 tensor、推给 GPU
不变的目标:queue 永远不空——GPU 才不会饿着。
"as a software engineer, you always try to remove the variables."
把 IO 完全短路——整个数据切片直接 load 进 RAM,不读盘、不读网络,直接喂 GPU。
GPU 利用率瞬间从 15-20% 跳到 85%。
"So we understood: model is correct."
模型没毛病。瓶颈一定在数据通路上。
这个 85% 之后会变成调试的"灯塔"——只要还没回到这个数,就说明真凶还没抓到。
增加 CPU 读线程数
更多并发 worker
更多缓冲
"Maybe we get lucky in life and everything works and we just move forward with the problem space, but didn't happen."
所有"通用 dataloader 调优秘籍"轮了一遍——利用率纹丝不动。
producer 端、queue 端、consumer 端,全打点。
"It's not, it's empty."
应该满的 queue 是空的。
"We are not reading the data fast enough from the pake. Loading it in queue and that's why consumer can't do shit. … So the utilization was basically very wobbly in some sense. As soon as we fast the data, it just passed through it directly to GPU."
利用率"很 wobbly":偶尔有数据时立刻冲一下,然后又 idle 等下一批。典型的 producer-bound 形态。
"These chip sets now have disk. They have SST. What if we just cache it? We don't have to make remote calls."
第一个 epoch 读到的 Parquet 落在本地 SSD,第二个 epoch 起从本地"bombard locally",不再走远程。
"Even if you have more data, whatever amount, let's say 50 terabyte or something, you can at least cache that."
至少能缓解远程 row-group 的逐次拉取。
实现简单。queue 现在真的满了。
…然后我们点了 launch。
"Nothing changed. Like the queue is full, but utilization didn't change. … this was like a despair moment for like a software engineer."
"Why did loading the data in the memory work like it? If it works, then our solution should also work because we also have a data in the queue."
两个配置都有满 queue,为什么一个能上 85% 一个不能?
发现 — 读 Parquet 出来是 PyArrow 格式:列存优化、可切片、可查询。
但 GPU 不吃 PyArrow
"GPU doesn't understand shit. … It only needs dense tensors."
PyArrow → NumPy 的转换在每次出队时做——把 RAM 实验里那 85% 的余量吃光了。
"So it was more of, how should I say, a double bottleneck."
"We can just cache the transform output. We really don't need to do transformation every time."
cache 里直接存 NumPy。queue 里出来的就是 GPU 能直接吃的 tensor 雏形。
原来的 RAM 实验同款数字回来了。
"And we were like, yeah, dude, you…"
— Demetrios: "like Sherlock Holmes over here trying to figure out what the problem is."
四次实验的对照表:
原始 — 15-20%(饿着)
RAM 全 load — 85%(理论上限)
SSD 缓存 Parquet — 没变化
NumPy 缓存 — 85%
关键 insight:第二步的"无变化"才是最值钱的信号。它告诉你存在第二层瓶颈。
"Training is more offline. You don't have to worry about a lot of things, and you have more breathing room … In serving, you are in a war between the two main variables."
选项 A — 拿到啥跑啥
batch 不满就用 padded fake data 凑齐
→ 快,但浪费算力
选项 B — 等 batch 攒满
"When you say wait enough, you're adding latency."
→ 利用率高,但延迟爆掉
Kashish 在 Ads 的选择 —— "we really need to be as fast as possible" → 选 A,烧 GPU 换毫秒
8 个线程,每个线程跑一行 forward prop 顺序进行——没法做大 batch。
"On CPUs, your cost would actually be more than GPU if you actually run those model on CPU."
代价 = 你需要跑的实例数 × 每实例成本。
"We were fine with the wasted batches still being on GPU than go on CPU."
GPU 有 batch capacity 兜底。哪怕浪费一半,单位 QPS 成本还是低于 CPU。
这条结论对很多团队是反直觉的——"小模型,CPU 不就够了?" 在大流量下,账算不过。
batch size = 1000,每行 200 features → 你需要把 1000×200 的矩阵传到 GPU 端点。
全在请求里发过来——网络成本直接付钱。
"A very big request over the wire."
GPU endpoint 从 Cassandra / Redis 拉特征——轰炸特征服务。
"Either a client pays it, or a GP endpoint pays it. … Unless you have the full matrix, you cannot run a forward product."
GPU 又被"喂不饱"——只是这次饿在 online 一侧。Online 还更难,因为需要新鲜的实时 feature,缓存价值大打折扣。
提高 Petastorm 并行度后,Kashish 发现一个奇怪的现象:
"One model is run on the same data can give you some AUC in same run, and again, on the same data can have a better AUC or worse AUC."
并行度上去了 → workers 抢 master queue 的顺序变了 → batch 里的 label 分布偏度变了 → AUC 漂移。
"The skewness in the labels affecting the model quality."
效率 ↑ 但确定性 ↓,模型质量被偷偷拐走了。
"You are hurting the model quality."
重写 queue 拓扑 — master queue 一锅炖 → per-worker queue + 预先决定任务划分
预分配 —
"We basically pre allocate everything … or pre decide everything before even we start training … such that … it's deterministic."
收益 — 同一 seed → 同一 batch order → 同一 AUC;不牺牲并行度;模型质量回来了
"Is there a place where that starts to degrade? Like did you find, hey, after a certain point you start to see losses?"
不是 loss,是no gains。
"Even if [you] specify, let's say 200 thread, it cannot allocate it. It'll just ignore it. … So whatever you specify, if you go outside the constraint or whatever the GPU is telling you, the CPU codes are telling you, it's not gonna increase it further."
作者概括:你以为给 200 个线程它就跑 200 个,其实内核内部 round-robin 你能用的核数。你只是在跟内核客气一下。
"I've just purchased the DGX Spark for my office. We ran [Ollama] on it … Quinn 3.59 B and 27 B, deep seat coder and also GPT OSS … 120 B version."
Docker 里跑 Claude Code,init 就要 10 分钟。同一台机器上 llama run 直接快。
第一直觉:网络(1 Gbit)。
但 init 也卡 10 分钟——这就奇怪了。
"It shouldn't call anyone in practice in theory. Like it's just a start prompt."
"Whenever you want to run an inference on these [GPUs], you need to send some QPS beforehand such that the memory is warm started. And if you don't do that, they would be very, very super, super slow."
"For these serving GPUs which we have, we maintain a QPS, a date or test QPS on those GPUs … with a fake data."
每个 inference GPU 一直收一股 fake QPS。生产请求来时就不是 cold start。
"So you fake it. Yes. … just throwing it at it so that it never fully shuts down."
朋友想"换个小模型"——Kashish 的回答:
"The smaller model will waste the GPU, like the capacity. … if the GPUs have capacity, then you should use a bigger model."
模型大小不是 latency 的对立面——填满 GPU 才是。
"Just my director just flagged me. I'm the expensive engineer using [Claude Code], so [my] billing numbers are just going on the top. … It's fine. It's just a few dollars."
"We are in a discount phase. It's a honeymoon period."
便宜,是因为还没到真账期。
"If actual typeface kicking, I don't know how expensive [it] would [be]."
"Like all the GPUs are getting erased from the [market]. Everyone wants it."
"I have to tell, like, think five times before you reply. … Like I'm scolding a child or something."
强迫它多 reasoning 步——主观感觉答案变好。
"I don't, I'm not familiar with Go Language. So you're changing go, I really don't have any clue. Just make the change, make it work. I'll figure it out later."
承认 vibe coding,偶尔得给 "this [Claude] guy" 一顿 scolding。
"Use voice mode to just brain dump at the beginning of a session … because it is a way to just get all of that context out of you."
打字会让你边写边压缩;语音让上下文一次倒完。
"By doing that, the agents are much more likely to … be able to search and understand what is where and what's working and what each file does."
"It's never the model, which is a culprit."
"These GPUs have become so precious … if you are not able to feed them and you're starving the GPUs, you're not doing a good job."
"It was more of, how should I say, a double bottleneck."
"Nothing changed. … this was like a despair moment for like a software engineer."
"In serving, you are in a war between the two main variables. One is latency … the second is the efficiency or utilization."
"We are in a discount phase. It's a honeymoon period."
"GPUs are very good with maths.
If we are not … passing the data, they can't do their job."
— Kashish · MLOps.community