Dwarkesh Podcast - 雷纳·波普——大型语言模型训练与服务背后的数学原理 封面

雷纳·波普——大型语言模型训练与服务背后的数学原理

Reiner Pope – The math behind how LLMs are trained and served

本集简介

与雷纳·波普进行了一个非常不同的形式的对话——一场黑板讲座,他详细讲解了前沿大语言模型的训练与部署方式。 仅凭几组方程式、公开的API价格和一些粉笔字,就能推断出实验室正在做什么,这令人震惊。 内容略显技术性,但我鼓励你坚持听完——绝对值得。 世界上能像雷纳那样全面理解AI全栈技术(从芯片设计到模型架构)的人寥寥无几。能向他学习,实在是一大幸事。 建议在YouTube上观看此视频,以便看清黑板内容。 雷纳是新芯片初创公司MatX的CEO(完整披露:我是其天使投资人)。他此前曾在谷歌工作,专注于软件效率、编译器和TPU架构。 点击此处下载转录文本的Markdown文件,以便与LLM进行对话。 我整理了一些闪卡和练习题,帮助自己巩固雷纳讲授的内容,希望对你也有帮助! 赞助商 * Jane Street 需要持续获得超低延迟的计算能力。我最近请他们的工程师克拉克为我详细讲解他们如何满足这些需求。我们的对话涵盖了从FPGA到液冷的方方面面,为我采访雷纳做了极大帮助。你可以在 janestreet.com/dwarkesh 观看完整讨论并了解Jane Street的开放职位。 * 谷歌的Gemma 4是首个让我能够断开互联网、打造完全离线“专注机器”的开源模型。这是因为Gemma足够小,可在我的笔记本上运行,同时又足够强大,真正有用。因此,为准备这次访谈,我下载了雷纳的扩展性书籍,断开Wi-Fi,用Gemma帮助我拆解内容。请访问 goo.gle/Gemma4 了解详情。 * Cursor 帮助我把关于大规模预训练中梯度流动的笔记,转化成了一段出色的动画。起初我不确定如何最好地可视化这个概念,但Cursor的Composer 2 Fast模型让我几乎能即时迭代各种想法。你可以在我的最新博客文章中查看这段动画。如果你也有需要可视化的内容,请前往 cursor.com/dwarkesh。 时间戳 (00:00:00) – 批量大小如何影响令牌成本与速度 (00:32:09) – MoE模型在GPU机架上的布局方式 (00:47:12) – 流水线并行如何跨机架分布模型层 (01:03:37) – 为何伊利亚说:“正如我们现在所知,流水线并不明智。” (01:18:59) – 由于强化学习,模型可能被过度训练至Chinchilla最优值的100倍 (01:33:02) – 从API定价推断长上下文内存成本 (02:04:02) – 神经网络与密码学之间的趋同演化 立即访问 www.dwarkesh.com/subscribe 获取Dwarkesh播客完整内容

双语字幕

仅展示文本字幕,不包含中文音频;想边听边看,请使用 Bayt 播客 App。

Speaker 0

今天我采访的是Reiner Pope,他是新锐芯片公司MatX的CEO。

Today, I'm interviewing Reiner Pope, who is CEO of MatX, which is a new chip startup.

Speaker 0

之前他在谷歌负责TPU架构,还干过不少其他项目。

Previously, he was doing TPU architecture and many other things at Google.

Speaker 0

这次的访谈形式跟我平时的不太一样。

This is a very different format from my usual interviews.

Speaker 0

今天这期更像是个黑板授课。

This is gonna be a Blackboard lecture.

Speaker 0

我们马上就开始。

We'll ring it up in a second.

Speaker 0

我们专门为了这种形式,新建了整个演播室。

We in fact built this whole new studio with specifically this format in mind.

Speaker 0

能用它来开启第一期,真的很荣幸。

And so it's a pleasure to get to inaugurate it with you.

Speaker 0

待会儿我们会聊模型架构、机器学习基础设施,还有其他好多话题。

We're gonna be talking about model architecture, ML infra, many other things.

Speaker 0

我觉得这个话题特别重要,是因为一旦你真正理解了集群里训练和推理到底是怎么运作的,很多关于AI为什么是现在这个样子、AI架构为什么这么设计、API价格为什么这么高,甚至AI进展为什么这么缓慢的问题,都会豁然开朗。

And the reason I think it's an important topic is because once you actually understand how training and inference actually work in a cluster, as we'll see a lot of things about why AI is the way it is, why AI architectures are the way they are, why API prices are the way they are, fundamentally also how why AI progress is the way it is, start making sense.

Speaker 0

你要想搞懂这些,就得深入细节,而要深入细节,非得靠黑板不可。

And you need to understand the details to get there, and you need a blackboard to understand the details.

Speaker 0

所以,Reiner,真的非常感谢你愿意来参加这次分享。

So, Reiner, thank you so much for doing this.

Speaker 1

是的。

Yeah.

Speaker 1

能来这儿我很开心。

Very happy to be here.

Speaker 0

提前打个招呼啊,这是一场满是图表和公式的讲座。

Just a heads up, this is a lecture with graphs and equations and all that stuff.

Speaker 0

所以如果你能的话,我强烈建议你用YouTube这类视频平台来看。

So if you can, I would really recommend watching it on a video platform like YouTube?

Speaker 0

好的。

Okay.

Speaker 0

坦白讲,我是MatX的天使投资人,不过这跟这个播客没啥关系。

Full disclosure, I am a angel investor in MatX, but that's unrelated to this podcast.

Speaker 0

Reiner,咱们先从这个问题开始吧。

Reiner, maybe to kick us off, I'll ask this question.

Speaker 0

现在像Claude、Codex和Cursor这些公司都推出了所谓的‘快速模式’,价格是原来的6倍,但生成速度能快2.5倍。

So we have a couple of companies like Claude and Codex and Cursor are offering something like, Fast Mode, where for six x the price, they'll give you streaming tokens at 2.5 x the speed.

Speaker 0

从技术上讲,我很好奇这背后到底发生了什么。

Mechanically, I'm curious what's going on here.

Speaker 0

为什么多花钱就能让延迟更低呢?

Why why is it the case that you can pay more to get faster latency?

Speaker 0

其次,你能一直这么提速下去吗?

And two, could you keep going?

Speaker 0

要是多花100倍的钱,速度能再快上好多倍吗?

Could you pay a 100 x more and somehow get even faster speeds or much, much faster speeds?

Speaker 0

还有第三点,能不能反过来?

And three, could you go the other way?

Speaker 0

你能不能搞个‘四倍慢速模式’?就是你愿意等上几分钟,价格还能更便宜。

Could you have something like quad code slow mode where if you are willing to wait for minutes on end, you could get even cheaper prices.

Speaker 0

这样或许能帮你更好地理解待会儿在实时共享里要做的分析。

So maybe this will help motivate the kind of analysis that you'll be doing through the live share.

Speaker 1

好。

Great.

Speaker 1

说白了,最关键的因素其实是批量大小,不过我们现在要做的,是具体量化一下这个影响到底有多大,它对延迟和成本意味着什么。

I mean, to jump to a little bit to jump to the conclusion, the big effect is batch size, but what what we're gonna do now is quantify exactly what that looks like and what its implications are on latency and cost.

Speaker 1

还会有另一个因素,你可以叫它‘推测解码’或者‘多标记预测’。

There's gonna be another effect, which is you can call it speculative decoding or multi token prediction.

Speaker 1

这个我们待会儿再聊,不过我觉得先来聊聊批量大小吧。

Can We maybe come back to that later, but I think the first thing that we'll talk through is batch size.

Speaker 1

我想先介绍两个分析的基本原则。

So what I'd like to introduce is sort of the two principles of analysis.

Speaker 1

首先,我们会用一个‘屋顶线分析’来看,怎么在一堆芯片上运行一个Transformer模型。

Firstly, we're gonna look at a roofline analysis of how we run a transformer model on a cluster of chips.

Speaker 1

我们拿一个Blackwell NVL 72集群来举例,也就是72张GPU组成的一机架。

We'll take a sort of a, let's say, a Blackwell NVL 72 cluster, so a rack of 72 GPUs.

Speaker 1

所以roofline分析就是看内存带宽和计算性能。

And so the roofline analysis means we look at memory bandwidths and and compute performance.

Speaker 1

另一方面,我们会关注模型的两个简单因素:处理权重所需的时间,以及处理上下文和KB缓存所需的时间。

And then the other side of that is that we're going to look at just two simple factors of the model, which are the time to operate on the weights and then the time to operate on the context, the KB cache.

Speaker 1

咱们直接开始吧。

So let's jump in.

Speaker 1

我们想估算一下,运行特定形状的推理任务大概需要多长时间。

What we're gonna try and do is we're gonna try and estimate the time that it takes to to run an inference of a certain shape.

Speaker 1

当然,这不可能完全精确。

Now we're not perfect here.

Speaker 1

我们没法准确预测具体耗时,所以只能做个近似。

We can't exactly predict the time, and so instead we're gonna approximate.

Speaker 1

因此,我们会说,实际耗时至少得大于或等于某个值。

And so we're gonna say that the time must be greater than or equal to a certain quantity.

Speaker 1

所以我们得考虑两个不同的方面。

And so we're gonna consider two different aspects.

Speaker 1

一个是内存读取花的时间,另一个是计算花的时间。

We're gonna look at the time for it takes to do the memory fetches, and then the time it takes to do the compute.

Speaker 1

结果你会发现,就算用个简单的模型,这招预测效果也特别强。

And it'll turn out that this actually gives us a very strong predictive power even with a simple lot.

Speaker 1

那咱们一个一个来,计算这部分到底要花多少时间?

So one by one, what is the time that it takes to do the compute?

Speaker 1

其实计算这事儿,我得干两样活。

So there are really two things I need to do in the compute.

Speaker 1

一是要把所有活跃参数都乘一遍,二是得处理注意力机制。

I need to multiply by all of the active parameters, and then I need to do some work on the attention.

Speaker 1

先说乘活跃参数这事。

So multiplying by all the active parameters.

Speaker 1

我有个固定的批量大小,模型里头还有不少活跃参数。

I have a certain batch size that I'm running, and then I've got a number of active parameters in my model.

Speaker 1

然后我就用这个除以计算吞吐量,也就是芯片的FLOPS。

And then and then I'm just gonna divide this by the compute throughput, which is the FLOPS of the chip.

Speaker 1

这属于硬件层面的问题。

So this is a hardware concern.

Speaker 1

所以这个其实已经涵盖了所有权重矩阵乘法的计算耗时。

So this this actually accounts for all of the compute time for all of the weight matrix multiplies.

Speaker 1

不过这里有个小细节要注意。

There's a little caveat here.

Speaker 1

我们之前基本没算注意力计算的时间,但一般来说,这部分时间相比起来要小得多。

We we've sort of ignored the time to do any of the attention computation, but that in general can be will be quite small in comparison to this.

Speaker 1

所以我们就先忽略它了。

So so we'll ignore this.

Speaker 0

我可能会时不时插一句,问些很基础的问题,或者澄清一些基本概念。

Maybe I'll just interrupt from time to time to ask some very naive questions or to clarify some basic points.

Speaker 0

不过对听众来说,你可不是一次只服务一个用户。

But just for the audience, you're not serving one user at a time.

Speaker 0

这里的‘批量’指的是你同时为很多用户服务。

The batch refers to the fact that you're serving many different users at the same time.

Speaker 0

对。

Yeah.

Speaker 0

这整个就叫一个批量。

And that's a whole batch.

Speaker 1

没错。

Yeah.

Speaker 1

所以我至少能稍微解释一下为什么用批量。

So I can motivate the batch at least a little bit.

Speaker 1

我们会清楚地看到,为什么批量是个这么有利的优化方式。

I mean, we will see exactly why batch is such a favorable optimization.

Speaker 1

但实际情况是,如果你不把多个用户的请求合并起来处理,成本和经济性可能会比合并处理差上千倍。

But what will turn out to be the case is that if you do not batch together many users, the costs and the economics you get can be like a thousand times worse than if you do batch many two users together.

Speaker 1

这一点我们会看得特别清楚。

And we'll be able to see that quite especially.

Speaker 1

然后是活跃参数的数量。

And then number of active parameters.

Speaker 1

比如说,DeepSeq v3 模型有大约三千七百亿个活跃参数,总参数量则是七万亿。

This is saying, if I look at, for example, a DeepSeq model, the DeepSeq v three model has about 37,000,000,000 active parameters and then 700,000,000,000 total parameters.

Speaker 1

所以我们现在只关注单个 token 激活的那些参数。

So this is we're we're focusing on just the ones that are active for a single token.

Speaker 1

明白了。

Okay.

Speaker 1

说到模型计算开销,我继续用等号表示,但所有这些情况里,这个时间至少得是这么多,可能还有一些我们没算进去的项。

So where model compute performs, I'm gonna keep writing equals, but in in all of these cases, can think of this time as being at least this much, and and maybe there'll be some terms we ignored.

Speaker 1

那在内存方面,我们需要做什么呢?

On the memory side, what do we need to do with memory?

Speaker 1

得把所有的权重都加载进来。

We we need to fetch we need to fetch all of the weights.

Speaker 1

所以得花时间加载全部参数,不只是那些活跃的。

And so there is some time to fetch all of the the total number of parameters, not just the active parameters.

Speaker 1

所以还有读取数据的等待时间。

So there's wait fetch time.

Speaker 1

另外,还有KV缓存的读取时间。

And then in addition, there's a kvcache fetch time.

Speaker 1

这个实际上跟批量大小有关。

So there is this actually depends on batch size.

Speaker 1

对于批量里的每个元素,我们都得把整个上下文长度的token都读一遍。

So for every element of the batch, we have to fetch an entire context length worth of tokens.

Speaker 1

然后每个token还有自己的大小,比如一个token占多少字节。

And then there's a size per token, so, like, bytes bytes per for for one token.

Speaker 1

所以这属于模型的一个参数。

And so this is a model parameter.

Speaker 0

咱们先回头解释一下,什么是KV缓存吧。

And maybe just back in, let's let's just explain what the KV cache is

Speaker 1

简单说一下。

real quick.

Speaker 1

对。

Yeah.

Speaker 1

当我做前向传播时,我来画一下自回归推理是怎么工作的。

So when I do a forward pass let me draw actually a how the autoregressive inference works.

Speaker 1

这是在解码阶段。

So this is during decode.

Speaker 1

假设我有一串文本标记,我会不断扩展一个张量,因为最终这些标记都是用某种嵌入维度的张量来表示的。

So if I think I have a bunch of tokens of text, I'm growing a tensor because, ultimately, the tokens are represented as some, like, tensor of in some embedding dimension.

Speaker 1

而在这个方向上,代表的是序列长度。

And then in this direction, I have the sequence length.

Speaker 1

解码的过程就是,每个标记都要经过多层大量的矩阵运算。

The work of running a decode is I I have to run each token through a through a whole bunch of matrix multiplies over a bunch of different layers.

Speaker 1

一般来说,我得对所有这些标记都做一遍这样的计算。

And I have I have in general, I'm gonna have to do that work over all of these tokens.

Speaker 1

但每一步解码,其实只是生成上面这一个新标记。

But then one step of decode is actually to produce just this one additional token up here.

Speaker 1

没错。

Yep.

Speaker 1

所以接下来要做的,就是跑一整遍前向传播,把模型里所有的权重矩阵都乘一遍。

And so what I'm gonna do there is I'm gonna run a full forwards pass of multiplying by all of the weight matrices in the entire model.

Speaker 1

然后模型里还有注意力机制,新生成的这个token会用这种方式读取所有之前的历史token。

But then I've got this attention mechanism where this token sort of it's it's like looking at all of the past tokens in this way.

Speaker 1

那它具体是在看什么东西呢?

And what is it looking at specifically?

Speaker 1

这个新token会读取模型之前生成的所有token的内部表征,我们把这个缓存区叫做键值缓存(KB cache)。

It is looking at some internal representation that the model has produced of the tokens, and we call that the KB cache.

Speaker 1

所以这个新token要去读取所有历史token的过程,就是注意力机制。

So this process of attending this this single token attending to all of the history of tokens, that's attention.

Speaker 1

这个过程的主要开销其实是内存读取,并不是矩阵乘法运算。

It is mostly dominated by memory fetches rather than than matrix multiplies.

Speaker 0

对的。

Mhmm.

Speaker 1

所以这里显示的是我们实际读取的内存总量。

So we've got the amount of memory that we're fetching, shown over here.

Speaker 1

然后呢,再除以内存带宽就行了。

And then there's, of course, just then divided by the memory bandwidth.

Speaker 1

也就是每秒多少字节的内存传输速率。

So so the memory bytes per second.

Speaker 1

实际上,这些公式已经足够让我们画出几条拟合线了。

So, in fact, these equations here are actually enough for us to now draw some fit lines.

Speaker 1

我们主要想看的是批量大小对性能的影响,还有另外一点——我们稍后单独画出上下文长度的影响。

And so the things that we'd like to look at are sensitivity to batch, and then also, which we'll draw separately, to context links.

Speaker 1

我们之前说过,最明显的权衡就是:批量大小变大,延迟会上升,但成本会下降。

So we said that the big big effects you can get is, like, some some trade off in latency versus versus cost in in batch size.

Speaker 1

那我们来把它们画出来吧。

So so let's draw them out.

Speaker 1

我觉得其实就两张图,我们重点画这两张就够了。

I think there's just really two graphs we want to draw.

Speaker 1

我们先画一下批量大小和时间的关系。

We'll first just draw batch size versus time here.

Speaker 1

看这个曲线的形状,它其实是两项相加,再加上另一项。

So when we look at the shape of this, we've got a maximum of, well, the sum and then and then another term.

Speaker 1

咱们一项一项来看,它们是怎么影响计算和内存所需时间的。

So let's look at these terms one by one and how they scale the time for compute and and memory and how they show up.

Speaker 1

先看计算时间这部分。

So let's first look at this compute time.

Speaker 1

它跟批量大小完全是线性关系,没有截距。

This is just purely linear linear in batch size with no no offset.

Speaker 1

大概就是这么个走势。

So it is some kind of like this.

Speaker 1

这个就是计算时间 t_compute。

This is this is t compute.

Speaker 1

至于内存这边,有一部分是个常数,也就是一个基础延迟,我们叫它等待取数的时间。

And then on the memory side, we've got some portion here that that is just this constant that's that is, you know, constant in some base offset here, which is the wait fetch.

Speaker 1

等待和获取数据

Wait fetch.

Speaker 1

最后是这个KB获取的部分,我们把它画成KP获取,它和批量大小成线性关系。

And then finally, have this term here, which is the KB fetch, which we're gonna draw as as there's the KP fetch, which is which are linear in batch size.

Speaker 1

所以看起来是这样的。

So it looks like that.

Speaker 1

所以这是这两部分相加,再和这一项取最大值。

So the sum of this plus this maxed with this.

Speaker 1

那我们先画出它们的和。

So let's at least first draw the sum.

Speaker 1

两个内存耗时叠加起来,曲线就变成这样了。

So the two memory times in in conjunction end up looking on this curved slope like this.

Speaker 1

对。

Mhmm.

Speaker 1

然后整体的最大值,我这儿加粗画一下。

And then we get a the overall maximum is I'll draw a little thicker here.

Speaker 1

这是这两条曲线的最大值吗?

Is it a maximum of these two curves?

Speaker 0

有道理。

Makes sense.

Speaker 1

好的。

Okay.

Speaker 1

那这到底意味着什么?

So so so what what does this mean, actually?

Speaker 1

这是一个延迟图。

So this is a latency plot.

Speaker 1

如果我增大批量大小,一开始延迟对批量大小的依赖并不明显。

So if I grow my batch size, I get initially some not very strong dependence on batch size.

Speaker 1

所以这里有个延迟的下限。

And so there's some lower bound on latency here, latency lower bound.

Speaker 1

下限。

Lower bound.

Speaker 1

所以这已经部分回答了那个问题。

So this already partially answers the question.

Speaker 1

对于固定的硬件配置,我们先这么看,之后再讨论硬件变化的情况。

For a given hardware configuration and then we can talk about varying hardware configuration.

Speaker 1

但只要硬件配置定了,延迟就有个下限——因为你得把所有参数从内存读进芯片里,这一步怎么也省不掉。

But for a given hardware configuration, there is a lower bound on latency, which is simply the I need to read all of my total parameters from from memory into the into the chips.

Speaker 1

这事儿得花一定的时间。

And that takes a certain amount of time.

Speaker 1

只要你把内存带宽用到极限,就不可能再快了。

If if I use all of my memory bandwidth, I can't do any better than that.

Speaker 0

你画的计算时间斜率和KB增长的关系,有点意思。

It seems like the way you've drawn the slopes for compute time and how the KB grows Mhmm.

Speaker 1

KB对这个影响是什么?

And what implication the KB has

Speaker 0

随着批量大小增加,对内存时间有什么影响?

on memory time that as a batch size

Speaker 1

如果这个在上面或下面呢?

What if this were above or below?

Speaker 1

或者呢?

Or

Speaker 0

对。

Yeah.

Speaker 0

这一定是必然的吗?

Or is that necessarily the case?

Speaker 0

因为如果这总是成立,那随着批量增大,计算时间就永远占主导了。

Because in by if this is always true, then as batch size grows, compute always dominates Yeah.

Speaker 0

KVN 这个说法暗示,如果你的批量足够大,内存可能根本不是问题。

KVN, which which suggests that if you have big enough batch size, maybe memory is never an issue.

Speaker 1

是的。

Yeah.

Speaker 1

这跟上下文长度关系特别大。

This is really sensitive to the context length.

Speaker 1

所以我觉得我们回头再深入探讨一下这个。

So I think we should come back and explore this.

Speaker 1

对。

Yeah.

Speaker 1

随着上下文长度变化,KB的读取时间会不断上升,这就导致系统从计算受限转向内存受限。

The there will be as you vary the context length, the KB fetch time will go up and up, and so that'll cause a transition from compute limited to memory limited.

Speaker 0

那计算时间的斜率恰好等于这个斜率,有什么特别的意义吗?

And is there something especially significant about the slope being exactly the slope of the compute time?

Speaker 1

是的。

Yeah.

Speaker 1

每次我们找到平衡点,都说明你正好拿捏得刚刚好。

Whenever we have balance points, it kind of says that you're getting it exactly right.

Speaker 1

所以在斜率完全匹配的那个上下文长度下,说明你既受计算限制,也受内存限制,对吧?

And so for the particular context length where the slopes match, that says I am equally memory bound and compute bound Right.

Speaker 1

这其实是个特别理想的状态,对。

Which is a really desirable place to Yeah.

Speaker 0

但假设这是一个特别简单的代数题,最优的上下文长度是100K,对吧?

But but suppose it's like this is a very simple algebra algebra problem, but suppose it's, you know, the the optimal is a 100 k context length Mhmm.

Speaker 0

如果你把上下文长度拉到200K,MFU会不会直接掉到一半?

And you go to 200 k context length, does your MFU go down to, like, 50%?

Speaker 0

也就是说,对MFU的影响会特别大吗?

Like, does it have a humongous impact on MFU?

Speaker 0

是的。

Yeah.

Speaker 0

就是在最优上下文长度稍微偏离一点,那个刚刚好的区间?

Like, slightly outside of context length optimal range, the goldilocks zone?

Speaker 1

没错。

That's right.

Speaker 1

在当前这个模型里,确实是这样的。

So that is true as modeled here.

Speaker 1

这里有个关键点,我假设上下文长度和内存读取时间是线性关系。

There's a key point here that I'm modeling this context length as or I'm modeling the memory fetch as linear in context length.

Speaker 1

这其实取决于模型架构。

That actually depends on model architecture.

Speaker 1

对于所有使用密集注意力的模型架构来说,确实如此。

It is true for many of the all of the model architectures with dense attention.

Speaker 1

对。

Yeah.

Speaker 1

但稀疏注意力的扩展性要好得多。

There's a sparse attention actually scales much better than that.

Speaker 0

明白了。

Got it.

Speaker 0

那实际应用中,大家都用稀疏注意力吗?

And is sparse attention what everybody uses in practice?

Speaker 0

我对稀疏注意力特别感兴趣。

I'm pretty excited about sparse attention.

Speaker 1

很难说实验室到底在用什么。

It's hard to know what the labs are using.

Speaker 1

DeepSync 发布了一种稀疏注意力机制。

DeepSync has published a sparse attention mechanism.

Speaker 1

我得提一下,DeepSeek 的一些论文里用的稀疏注意力,会在这一项里加个平方根。

I'll just put a plug in that sparse attention some of the DeepSeek papers that have published sparse attention end up putting a square root in this term.

Speaker 1

明白了。

Okay.

Speaker 1

到目前为止,我们看了延迟的问题。

So so far, we've looked at the latency.

Speaker 1

从这张图上看成本还挺难判断的。

It's kind of hard to read off cost from this.

Speaker 1

那我要是想想,成本到底指的是啥?

So if I think, what does cost mean?

Speaker 1

做一次推理,我得让 GPU 运行几毫秒,比如一毫秒、二十毫秒之类的。

I'm gonna like, to run this inference, I'm gonna use the GPU for a certain number of seconds, like one millisecond or twenty milliseconds or something like that.

Speaker 1

这时间就得按租用时长来收费。

And I have to pay the rental time for for that that time.

Speaker 1

所以,大概每小时每张GPU是两美元左右。

So, like, it's $2 an hour per GPU or something like that.

Speaker 1

这就是这次推理的成本。

So so that's the cost of this inference.

Speaker 1

但在这次推理过程中,我到底处理了多少个token?

But how much value have how many tokens have I processed during that inference?

Speaker 1

这个就是批量大小。

That is the batch size.

Speaker 1

所以我们真正想画的,其实是成本和批量大小的关系,也就是 t/b 对批量大小。

And so what we actually wanna plot is gonna be the the cost versus batch size, which is like t over b versus batch size.

Speaker 1

这才是每个token的成本。

This is the cost per token.

Speaker 1

所以我们得想象,把这三条曲线都除以 b,也就是乘上它的倒数。

So, like, we have to imagine dividing each of these three curves by by b, so multiplying by this reciprocal.

Speaker 1

这样一来,计算成本那条线原本是线性的,现在……

And so what we end up with there is the the compute curve is gonna it was linear.

Speaker 1

我们除以 b。

We divide by b.

Speaker 1

这样它就变成常数了。

That makes it a constant here.

Speaker 1

这是计算开销。

And this is t compute.

Speaker 1

KV 读取原本是线性的。

The k v fetch was linear.

Speaker 1

现在它也变成常数了。

Now it becomes a constant as well.

Speaker 1

KV 读取。

K v fetch.

Speaker 1

等待读取原本就是常数,现在除以 b 之后,就变成了双曲线形状。

And then the the wait fetch was constant, and now we've divided by b, and so it becomes this hyperbolic.

Speaker 1

对。

Mhmm.

Speaker 1

所以,我们还是要算这些项之和的最大值。

And so, again, we're gonna compute the max of the sum.

Speaker 1

这两个项加起来,会让抛物线整体上移。

So the sum of these two terms shifts the the parabola up.

Speaker 1

K V 读取和权重读取加在一起,就形成了一个更高的抛物线,大概长这样。

The sum of k b fetch and the weight fetch gives us a sort of a higher parabola that's like this.

Speaker 1

对。

Mhmm.

Speaker 1

然后我们再和这里的计算开销取最大值。

And then we're gonna take the max with the compute here.

Speaker 1

最后得到的就是我们真正关心的这个整体形状。

So we end up with this this being the overall shape that that we care about.

Speaker 1

所以,我们能看到一些极限情况下的表现。

So, again, so, like, we see some limiting behavior.

Speaker 1

当批量大小为1的时候,成本一开始非常高。

The cost initially starts very high at batch size of one.

Speaker 1

实际上,它几乎要趋于无穷大了。

Actually, like, it almost goes to infinity.

Speaker 1

因为权重读取次数太多了,又没被大批次分摊掉。

Like, it's, because we've got so many weight fetches which are not amortized over a large batch size.

Speaker 1

但随着批次变大,这些权重读取被分散到越来越多的数据上,开销就变得微乎其微,最后计算时间就成了主导成本的因素。

But then as we increase the batch size, the weight fetches become amortized over so many different batch elements that they their cost goes grows very small, and eventually, the compute time, ends up driving the cost.

Speaker 1

对。

Mhmm.

Speaker 1

所以成本其实有个下限,就是这儿这个值。

So there is a limiting, like, lower bound lower bound on cost, which is this one here.

Speaker 0

没错。

Yep.

Speaker 0

所以不管是Claude代码慢、编解码慢,还是别的啥,都得卡在这条线上。

So so Claude code slow or codec slow or whatever would just live on this line.

Speaker 0

对。

Mhmm.

Speaker 0

但这也没太大用,因为你怎么也摊不开 KV 值到更大的 batch 里。

And it wouldn't help much because you're you're not able to amortize the k v values over a much bigger batch.

Speaker 1

对。

Yeah.

Speaker 1

没错。

Yeah.

Speaker 1

每个 batch 的 KV 值都是独立的。

They're unique per batch.

Speaker 1

计算量也是每个 batch 独立的。

The compute is also unique per batch.

Speaker 1

那在把其他所有开销都摊薄之后,每个 batch 最少得干多少活?

And so what is the minimum work you can do per batch after amortizing everything else away?

Speaker 0

就是你不再受内存带宽限制的那个点,对。

So this point where you are no longer memory bandwidth bound Mhmm.

Speaker 0

那实际要多大的 batch 才能……嗯,达到这个效果?

What practically how big a batch do you need to like, yeah.

Speaker 0

批次到底有多大啊?

How big are the batches Yeah.

Speaker 0

对前沿模型来说,实际需要多大?

Practically for frontier models?

Speaker 1

其实你可以直接算出来。

You can you can just solve for that, actually.

Speaker 1

而且这个结果对模型架构没那么敏感。

And it's not even particularly sensitive to model architecture.

Speaker 1

那咱们就来算一算吧。

So let's let's go ahead and do that.

Speaker 1

我们说的是,当内存耗时等于计算耗时的时候。

So what we're talking about is we're gonna say when the memory time is equal to the compute time.

Speaker 1

这个问题的核心就是这个。

That's that that's what that question is.

Speaker 1

现在我先忽略其他因素,因为我们只关心批次大小,其实关键在于权重被分摊到多少数据上。

For now, I'm gonna discard the because we're focused on what what the batch size is, and, really, there's a question of what when the weights are amortized over the Yeah.

Speaker 1

我主要想比较权重读取时间和权重计算时间。

The the multiplies, I'm gonna focus on comparing the weight fetch time to the weight multiply time.

Speaker 1

为了简化分析,我先忽略KB读取这部分,这样能更清楚地得出结论。

I'm gonna disregard the KB fetch term just just to simplify the analysis so we can get a kind of a clean answer out.

Speaker 1

所以我们要把这一部分和那两个项等同起来。

So we're gonna equate this portion with this, with these two terms.

Speaker 1

对。

Yep.

Speaker 1

这么一写,就是总参数量除以内存带宽,等于批大小乘以激活参数量,再除以计算性能。

So writing that out, we get n, number of total parameters over memory memory bandwidth is equal to batch size times number of active parameters divided by the compute performance.

Speaker 1

你看这边,分子上全是模型参数。

So looking over here, everything on the top, these are model parameters.

Speaker 1

分母上全是硬件参数。

Everything on the bottom, these are hardware parameters.

Speaker 1

其实把它们重新整理一下,让硬件参数都在一边,会更清晰。

It it turns out to be nice to rearrange them such that we have the hardware parameters on one side.

Speaker 1

所以这就等价于,内存带宽等于批大小乘以活跃参数数量,再除以总参数数量。

So so that's this is equivalent to well, so the memory bandwidth being equal to batch size times number of active parameters divided by the number of total parameters.

Speaker 1

所以这其实是个硬件参数。

So so this is a hardware parameter.

Speaker 1

实际上,这个值最后会变成一个无量纲的常数。

Actually, the this actually ends up being a dimensionless constant.

Speaker 1

如果你从浮点运算次数的角度来看,这个东西的量纲是什么?

If you look in terms of FLOPs, what are the dimensions of this?

Speaker 1

这是每秒多少次乘法运算。

This is multiplies per second.

Speaker 1

而这是每秒多少字节,所以它根本不是无量纲的。

This is bytes per second, so that's not quite dimensionless.

Speaker 1

但你其实可以这么理解:每秒多少次FP4乘法运算,再乘上每个FP4只占半字节这个事实。

But what you do is you say, like, multiplies per second times let's say I'm doing f p four.

Speaker 1

所以我是说,每秒做多少次FP4乘法,再乘上每个FP4占半个字节这个换算关系。

So I I do, like, how many f p four multiplies per second times the fact that each one each f p four is half a byte.

Speaker 1

所以我能让这个最终变成一个无量纲的数。

And so I can actually make this end ending up being dimensionless.

Speaker 1

在大多数显卡上,这个值大概在300左右。

And and this ends up being on most GPUs around 300.

Speaker 1

差不多就是300。

Somewhere around 300.

Speaker 0

不好意思,打断一下。

And sorry.

Speaker 0

随着模型一代代更新,算力瓶颈一直在提升,这个比例有变化吗?

Has that ratio changed over time as we've from model generation to model generation where the So locks keeps increasing?

Speaker 1

这是硬件相关的参数。

Hardware parameter.

Speaker 1

硬件到底变化了多少?

To what extent has the hardware changed?

Speaker 1

从100到200再到100,FLOPS提升得可不少。

So from, like, a 100 to a 200 to b 100, the the FLOPS has increased substantially.

Speaker 1

内存带宽也大幅提升,而且一直保持得相当稳定。

The memory bandwidth has also increased substantially, and it has remained reasonably stable.

Speaker 1

对。

Yeah.

Speaker 1

这个我们也可以用同样的方式表达。

And we can we can express this one as well.

Speaker 1

这是一个稀疏度参数。

This is a sparsity parameter.

Speaker 1

没错。

Yeah.

Speaker 1

我甚至可能换种说法。

And I I might even phrase it slightly different.

Speaker 1

我们来整体算一下批处理大小。

Let's solve for batch size in total.

Speaker 1

抱歉啊。

We end up with I'm sorry.

Speaker 1

我们把这项移到另一边。

Just moving this back over to the other side.

Speaker 1

所以最终得出,批大小得比稀疏度的300倍还大。

We end up with batch size needs to be bigger than approximately 300 times sparsity.

Speaker 1

举个例子,如果我在DeepSig里激活32个专家,总共256个,那稀疏度就是八。

So, for example, if I have a 100 like, I activate in deep sig I activate 32 out of 256 experts, so this would be, like, eight for deep sig.

Speaker 1

明白了。

Got it.

Speaker 1

好的。

Okay.

Speaker 1

这其实给了你一个非常贴近实际的估算值。

So so this actually gives you a ballpark, which is, like, remarkably accurate to practice.

Speaker 1

通常大家都会比这个数再调大一点。

Generally, people will go a little bit larger than this.

Speaker 1

他们不想刚好卡在临界点上,毕竟现实中的效率没理论分析那么理想。

They don't really want to be exactly at the balance point because, real world efficiencies aren't as good as a a refinement analysis would say.

Speaker 1

但你不妨把这个数翻一倍甚至三倍。

But, like, take this and maybe double it or triple it.

Speaker 0

对。

Mhmm.

Speaker 0

明白。

Okay.

Speaker 0

所以,每批大概就是两千到三千个token。

So, basically, it's, like, 2 to 3,000 tokens per batch.

Speaker 0

不过如果你把KB缓存也算上,那确实。

But then if you included the KB cache Yes.

Speaker 0

那意味着最优的批次大小

The implication would be that the optimal batch size

Speaker 1

应该再大一点。

Should grow larger.

Speaker 1

所以我们现在要找的是计算时间和内存时间相等的那个平衡点。

So this is gonna like, we we solve for the equivalence between when compute time is equal to memory time.

Speaker 1

如果我增加更多内存带宽,比如用掉更多带宽的东西,那留给工作负载的就少了。

If I add in more memory bandwidth, like, something that consumes more memory bandwidth, then I have less available for the for the workloads.

Speaker 1

所以我得进一步提升内存带宽,相应地,批大小也得更大。

And so I need to grow the the memory bandwidth more, the the and therefore the batch size more.

Speaker 0

这看起来也太小了吧。

This seems incredibly small.

Speaker 0

这么小的批,连一条序列都撑不满。

Like, a batch this would be, like, less than one sequence.

Speaker 0

对吧?

Right?

Speaker 1

是的。

Yeah.

Speaker 1

明白了。

Okay.

Speaker 1

所以我要提醒一下,我这里说的,是每次只生成一个额外的token的情况。

So so I guess this is keep in mind that I'm talking about the number of tokens that I'm generating one more token for.

Speaker 1

所以实际上,这里有2000个不同的序列,好吧。

So so it's like it's actually 2,000 unique sequences in Okay.

Speaker 1

这个

The

Speaker 0

我们只是在说一次前向传播

We're just talking about the a single forward pass

Speaker 1

对。

Yes.

Speaker 1

在这些序列上。

On these sequences.

Speaker 0

你觉得这个批量大小是指序列的数量,而不是像

This is like the do you think of it like the batch as the number sequences rather than like

Speaker 1

没错。

That's right.

Speaker 1

好的。

Okay.

Speaker 1

太棒了。

Cool.

Speaker 1

对。

Yeah.

Speaker 0

我最近在准备面试,经常跟行业里的专家聊。

I'm prepping for interviews, I often talk to experts in the field.

Speaker 0

所以关于Reiner,我跟Jane Street的两位工程师,Clark和Axle,聊了聊。

So for Reiner, I chatted with two of Jane Street's engineers, Clark and Axle.

Speaker 0

Clark负责低延迟训练系统,他给我讲了为什么Jane Street要用FPGA,来保证纳秒级的稳定延迟。

Clark, who works on low latency training systems, walked me through why Jane Street uses FPGAs to make sure that they have predictable nanosecond latencies.

Speaker 0

你可以轻松搭建出巨大的计算网格,专门处理100兆字节的SRAM,然后在几十纳秒内返回结果,这事儿对很多人来说根本做不到。

You can just build these, like, giant grids of compute very easily that do exactly what you need to touch a 100 megabytes of SRAM and then get your response back in tens of nanoseconds very easily, and that's basically impossible on some people.

Speaker 0

他还进一步解释了为什么CPU根本没法胜任这种任务。

He then went on to explain why CPUs just wouldn't work for this kind of thing.

Speaker 0

如果你的时钟每三纳秒跳一次,那每次决策时,你其实有好几字节的数据可以用来判断。

And so if you have a clock that's going every three nanoseconds, you actually have several bytes of information at a time to make your decision.

Speaker 0

而CPU呢,你得等整个数据包都收齐了,比如1500字节这么大的包,才说:好了,包到齐了。

That's as opposed to a CPU where you'll just collect up a whole packet, you know, let's say a 1,500 byte packet, and then you say, okay, this packet's ready.

Speaker 0

来吧,CPU,该你干活了。

Here you go, CPU.

Speaker 0

现在你可以开始处理了。

You can start thinking about it now.

Speaker 0

但FPGA不一样,数据包一来,刚收到开头那部分,它就能立刻响应,不用等整个包全到。

FPGAs allow you to react to the earliest part of the packet as it arrives, rather than having to wait for the full thing.

Speaker 0

我们还聊了液冷、网络架构,还有好多别的事儿。

We also talked about liquid cooling, network design, and many other things.

Speaker 0

如果你对这些感兴趣,Jane Street现在正在招人。

If you're interested in this stuff, Jane Street is hiring.

Speaker 0

想去看看的话,去 janestreet.com/dwarcash 查他们的职位吧。

You can check out their open roles at janestreet.com/dwarcash.

Speaker 0

如果你想看完整的准备对话,我们也在那儿放了完整版。

And if you wanna watch the full prep conversation, we posted it there too.

Speaker 0

如果你用的是Frontier模型,而且真正在做推理,那肯定同时在线的用户远不止两千个吧。

If you've got a Frontier model and you are actually doing inference, surely they must have more than 2,000 concurrent users.

Speaker 0

对啊。

Yeah.

Speaker 0

因为要等整个批次填满,会不会增加延迟?

Is there any added latency from the fact that you need to have the whole batch fill up?

Speaker 0

还是说,只要用户数量够多,几乎不可能花上一百毫秒还填不满接下来的两千个位置?

Or is it if you have a reasonable amount of users, it's so unlikely that you wouldn't it it would not take you a hundred milliseconds to fill up the next 2,000 slots.

Speaker 1

是的。

Yeah.

Speaker 1

我觉得可以这么想:模型什么时候发车,就像火车什么时候开?

The the way to think about this, I guess we think think of it as like when does the train depart as a model?

Speaker 1

没错。

Yeah.

Speaker 1

比如说,我已经定了一个要使用的批量大小。

So let's say I've picked a batch size that I'm gonna run at.

Speaker 1

也许我就选这个批量大小。

Maybe I pick this batch size.

Speaker 1

顺便说一下,这个交点和这里的交点是一样的。

And by the way, this intersection point is the same intersection point here.

Speaker 1

所以我就定了这个批量大小。

So picked this batch size.

Speaker 1

我知道它大概需要二十毫秒左右,这是常见的等待时间。

I know that it's gonna take, for example, maybe it's something like twenty milliseconds is a common place to sense up landing.

Speaker 1

对。

Mhmm.

Speaker 1

我这边生成的是GPU上运行任务的时间线。

What I'm going to produce is like, so this is a timeline of what is running on the GPU.

Speaker 1

不管怎样,每二十毫秒就会启动一个新的批次。

It's gonna start a new batch every twenty milliseconds regardless.

Speaker 1

所以每个这样的时间段都是二十毫秒。

And so so each of this is 20.

展开剩余字幕(还有 480 条)
Speaker 1

这个是40。

This is 40.

Speaker 1

你可以把这想象成一列火车的发车时刻表。

You can think of this as a schedule for the train.

Speaker 1

每二十毫秒就有一趟新火车发车。

A new train departs every twenty milliseconds.

Speaker 1

所有准备好的乘客都能上车。

Any passengers who are ready board the train.

Speaker 1

如果火车坐满了,那就得等下一趟。

If the train is full, then they wait till the next train.

Speaker 1

就算火车没坐满,它也会照常发车。

If the train is not full, the train's gonna go anyway.

Speaker 1

这么说吧,关于排队延迟,最坏的情况是:请求刚错过火车,一来就发现火车刚走。

And so in terms of what that means for queuing latency, it means that the worst case is that you like, a request arrives just after the train departed.

Speaker 1

那它就得等下一趟,最多等二十毫秒,还得再等这趟火车跑完。

It has to wait for the next train, so that's up to twenty milliseconds, and then it has to wait for that train to to complete.

Speaker 1

是的。

Yeah.

Speaker 1

所以最坏情况下的延迟是四十毫秒。

And so the worst case latency is forty milliseconds.

Speaker 0

那这个‘列车毫秒’是怎么算出来的?

So how is the train milliseconds derived?

Speaker 1

说白了,这只是一个经验法则,具体来源还没完全讲清楚,不过到目前为止,我们主要关注的是内存带宽和计算时间。

I mean, rule of thumb, but where it comes from is not fully explained yet, but so far we've focused on memory bandwidth and compute time.

Speaker 1

当我们看内存时,另一个要考虑的是,我们希望充分利用现有的所有内存容量。

When we look at memory, the other consideration is that we want to use all of the memory capacity we have.

Speaker 1

所以一般来说,我们会用这些内存来存储权重或者kV值。

And so, generally, we're going to use all of that memory capacity to store the weights or the kVs.

Speaker 1

因此,我们希望在一次前向传播的时间里,能把所有内存容量都读进芯片里。

And so we just want to read, like, in the time of doing a forward pass, maybe we want to read all of the memory capacity into into the chip.

Speaker 1

所以这就等于容量除以带宽。

And so that is capacity divided by bandwidth.

Speaker 1

在很多代HBM上,这个值通常是二十毫秒。

That tends to be twenty milliseconds on on many gen different generations of HBM.

Speaker 0

单位是对的。

The units make sense.

Speaker 0

你就是用字节除以每秒字节数嘛。

You would have a byte divided by bytes per second.

Speaker 1

对。

Yeah.

Speaker 1

比如说,在Reuben这一代,大概是288GB除以20TB每秒。

So, for example, I mean, on on, I think, the Reuben generation, it is something like 288 gigabytes, divided by 20 terabytes per second.

Speaker 1

算下来大约是十五毫秒。

And this looks like it comes out to about fifteen milliseconds.

Speaker 0

我再确认一下,我理解得对不对。

Just to make sure I understand what it's saying.

Speaker 0

我的意思是,我知道单位为什么这么算,没错。

Mean, I understand how why the units can't Yeah.

Speaker 0

对的

Yeah.

Speaker 0

就是这个单位分析的逻辑嘛

The the sort of unit analysis.

Speaker 1

没错

Mhmm.

Speaker 0

不过这句话到底想表达什么?是说我们能清空、替换什么东西吗

But what is it saying is we can evacuate and replace

Speaker 1

没错,就是这样。

That's right.

Speaker 0

HBM得在这么短的时间内完成读写。

The HBM in this amount of time.

Speaker 0

我们可不想碰到两种麻烦:要么是HBM容量不够大,没法把要存的东西都写进去,或者要取的数据都读出来;要么就是我们的双向传输能力太弱,远远跟不上需求。

And so we don't wanna be in a situation where the HBM is not big enough that we're not gonna actually able to keep write everything you want to it or take everything out of it, or we don't wanna be in a situation where our ability to write back and forth is so big or sorry, so small compared.

Speaker 1

对的。

Yeah.

Speaker 1

这话其实有道理。

There's sort of truth there.

Speaker 1

咱们为啥不选个超过十五毫秒的延迟呢?

Why don't we pick a latency that is bigger than fifteen milliseconds?

Speaker 1

如果这么想的话,就意味着我有足够时间把HBM读两遍。

And if I think what that means, it means I actually have time to read the HBM, like, twice.

Speaker 1

没错。

Yep.

Speaker 1

顺便说一句,HBM的访问大部分都是读,不是写。

By the way, most of HBM accesses is reads, not writes.

Speaker 1

几乎是全读,因为权重矩阵是只读的,而KV缓存的访问也差不多,所以在大概三十毫秒内,我能把HBM读两遍。

It's like almost all reads because the weight matrices are read only, and then almost all of the KV cache accesses are So in like, let's say around thirty milliseconds, I can read all of HPM twice.

Speaker 1

但这么做的意义在哪?

But what's the point of that?

Speaker 1

我是说,我根本没必要把权重矩阵读两遍。

Like, I I don't wanna read the weight matrices twice.

Speaker 1

我不想把KB读两遍。

Don't wanna read the KBs twice.

Speaker 1

对。

Yeah.

Speaker 1

有道理。

Makes sense.

Speaker 1

这话说得

Makes a

Speaker 0

很有道理。

ton of sense.

Speaker 0

好的。

Okay.

Speaker 0

我有几个简单的问题。

So a couple of actually quick questions.

Speaker 0

第一,如果最优批量大小真的是2000左右,那这完全取决于稀疏性。

One, if it is the case that the optimal batch size is something like 2,000, and that I actually true it's totally dependent on the sparsity.

Speaker 0

这跟模型大小没关系,什么都没关系。

It's not dependent on the model size or anything.

Speaker 1

我是说,稀疏性确实跟模型大小有关,但除此之外,就只看稀疏性,跟规模没啥关系。

I mean, sparsity shows up in model size, but beyond that, it only depends on sparsity, not on scale.

Speaker 0

这结果挺有意思的。

But that's a very interesting result.

Speaker 0

这似乎引出一个问题:这种推理和批处理带来的规模经济,到底会多大程度推动集中化呢?

And that seems to imply that you can one question is how much of a push towards centralization is it that you would have these economies of scale from inference, from batching?

Speaker 0

是啊。

Yeah.

Speaker 0

但好像也没那么重要。

But it seems like it's not that big a deal.

Speaker 0

说实话,我也说不准。

Like, I don't know.

Speaker 0

同时有两千个用户,算多吗?

Two is 2,000 users at the same time a lot?

Speaker 0

看起来也不算多吧?

It doesn't seem like a lot?

Speaker 1

我们可以稍微分析一下,与其看用户数量,不如换个角度,想想每秒处理多少个词元更实际。

So we can do a bit of analysis on this, which would be actually it's like you can think of it in terms of number of users, but maybe a more productive way to think of it is in terms of number of tokens per second.

Speaker 0

对。

Mhmm.

Speaker 1

那这个批量大小,换算成每秒多少词元的话,意味着什么?

So what does this batch size mean in terms of tokens per second of this of the system?

Speaker 1

每秒词元数。

So tokens per second.

Speaker 1

每秒词元数就等于批量大小。

Tokens per second is going to be equal to the batch size.

Speaker 1

每次处理一批词元,然后每隔一段时间重复一次。

We run a batch many tokens, and then we do that every t.

Speaker 1

每隔一段时间,比如十五毫秒、二十毫秒这样的间隔。

So So every time intervals, which is, let's say, which is which is this thing is equal to the fifteen milliseconds, twenty milliseconds number.

Speaker 1

所以最终就是批量大小乘以60左右。

So this ends up being batch size itself times about 60.

Speaker 1

比如64乘以b。

So, like, 64 times b.

Speaker 1

那这就大约是2000乘以64了。

And so this ends up being around 2,000 times 64.

Speaker 1

也就是大概128万tokens每秒。

So, like, a hundred and twenty eight hundred and twenty eight k tokens per second.

Speaker 1

这样换算成更容易理解的单位了。

So this is sort of in more digestible units.

Speaker 1

光想并发用户数很难搞清楚,但一个系统的全局流量到底有多大呢?

Like, it's hard to reason about concurrent users, but what is the track global traffic for for a system?

Speaker 1

你看一些厂商的公告,有时候他们会吹嘘自己有多少流量。

When you look at some of the announcements, sometimes the API providers will will brag about how much traffic they have.

Speaker 1

我记得去年Gemini发布时,他们说全球每秒处理的tokens高达数亿。

The the the numbers that I've remembered from some announcements of Gemini last year were in the hundreds of millions of tokens per second worldwide.

Speaker 1

是的

Yeah.

Speaker 1

所以,这大概是那个量的千分之一。

So so about a like, this is one thousandth of that printer.

Speaker 1

Gemini。

Gemini.

Speaker 1

是的

Yeah.

Speaker 0

但Gemini体量这么大,所以它的千分之一已经相当可观了。

But, I mean, Gemini is big, so I think that's actually one thousandth of Gemini is a lot.

Speaker 0

对。

Yeah.

Speaker 0

要想在规模上具备竞争力,你得能

To to actually become, like to be competitive at scale, you need to be

Speaker 1

提供至少Gemini千分之一的服务能力。

able to serve at least one thousandth of Gemini.

Speaker 0

是的。

Yeah.

Speaker 0

这挺有意思的。

That's interesting.

Speaker 0

不错。

Cool.

Speaker 0

好的。

Okay.

Speaker 0

稀疏度越高,所需的计算量就越少。

So the more sparsity you have, the less compute you need.

Speaker 0

而且看起来,随着批量变大,计算能力确实成了瓶颈,对。

And it does seem that as batch sizes get bigger, compute ends up being the bottleneck Mhmm.

Speaker 0

根据这项分析。

According to this analysis.

Speaker 0

那问题来了,稀疏度能推进到什么程度?

So then the question is, how far can you take sparsity?

Speaker 0

也就是说,随着稀疏率上升,活跃参数占总参数的比例越来越低,模型的性能会下降多少?

That is to say, as the sparsity ratio increases, as you have fewer and fewer active parameters relative to total parameters, how much is performance of the model degrading?

Speaker 0

而且这种性能下降的速度,会不会比你靠提高稀疏度节省的计算资源还要快?

And is it degrading faster than your saving compute by increasing the sparsity factor?

Speaker 1

是的。

Yeah.

Speaker 1

你是说模型的性能,而不是运行速度吧?

So perform equality of the of the model, you you mean, rather than speed of the model.

Speaker 1

对。

Yeah.

Speaker 1

没错。

Yeah.

Speaker 1

可惜我们没法从理论上给出确切答案。

So, unfortunately, we're not able to answer that analytically.

Speaker 1

这其实是个得靠实验来验证的模型质量的问题。

That's that is an empirical question of model quality.

Speaker 1

我所能做的就是找篇论文,用实证数据来回答这个问题。

Best I can do is pull up a paper and answer that empirically.

Speaker 1

对。

Yeah.

Speaker 0

好的。

Okay.

Speaker 0

我们现在就看这篇论文吗?

Should we follow the paper now?

Speaker 0

还是说

Or is that

Speaker 1

有道理,没错。

makes sense yeah.

Speaker 1

这篇论文叫《路由语言模型的统一定律》。

So this paper, this is Unified Laws for Routed Language Models.

Speaker 1

虽然这篇论文有点老了,但他们做了一件很重要的事:研究了当稀疏度不断提高时,模型质量会受到什么影响。

It's a somewhat old paper by this stage, but one of the things that they did is looked at, if I keep increasing sparsity, what is the model quality impact?

Speaker 1

这个结果对专家混合的具体配置特别敏感。

This answer is very sensitive to the actual choice of mixture of experts.

Speaker 1

专家混合这个方法早就有了,历史很长。

Mixture of experts has been around for a really long time.

Speaker 1

我记得可能早在2017年就有了。

I think it was maybe even back in 2017.

Speaker 1

但后面的技术手段变化太大了。

But the tech techniques have changed a lot.

Speaker 1

DeepSeq的专家混合方式,彻底改变了它的运作机制。

DeepSeq mixture of experts was was a big change in how it worked.

Speaker 1

之前还有些老论文,比如G-Shard和Switch Transformer。

There have been older papers which are G Shard switch transformer.

Speaker 1

所以实际的实验结果,全看用的是哪一套方法。

So the actual empirical results are gonna depend on all of that.

Speaker 1

但你看这里展示的早期方法,如果保持活跃参数数量不变,只增加稀疏度——他们这儿叫专家数量——模型效果反而越来越好。

But on one of the older techniques that is shown here, you can see if I hold constant the number of active parameters at a certain size, and then I increase the sparsity, which they call expert count here, The quality keeps increasing.

Speaker 1

如果你想象从13亿密集模型那里画一条水平线过去,就会发现,比如在这个情况下,64个专家、3.7亿激活参数的模型,表现和13亿的密集模型一样好。

And then if you imagine drawing a horizontal line from 1.3 b dense across, you end up seeing that, for example, in this case, the 64 expert, three seventy million activated parameters model is as good as a dense 1,300,000,000 model.

Speaker 0

所以说,某种程度上,你根本不需要把总参数量增加一百倍,就能达到激活参数增加十倍的效果,这回报其实没那么夸张。

So, some sense, it's actually not amazing returns where you need to increase total parameters a hundredfold to get to the equivalent of 10 x as many active parameters.

Speaker 1

是的。

Yeah.

Speaker 1

实际上甚至更明显。

Mean, actually, even more so.

Speaker 1

是的。

Yeah.

Speaker 1

参数量增加这么多,但性能提升却只有一点点。

It's a huge increase in parameter count for a modest increase in

Speaker 0

对。

Yeah.

Speaker 0

那在这种情况下,具体是多少来着?

So in this case, it's what what is it?

Speaker 0

四倍?

Four x?

Speaker 1

六十四倍换四倍。

64 x for four x.

Speaker 0

对啊。

Yeah.

Speaker 0

虽然说,增加稀疏度确实能节省计算时间,乍一看这买卖挺划算的。

So while it is while it is true, I guess, that the you get this benefit of being able to economize on your compute time if you increase sparsity, naively, would seem like, oh, that's a trade off worth making.

Speaker 0

但你每把稀疏度翻一倍,这个数值反而降两倍,那个却涨八倍。

But if this this you're decreasing this by two x and then having this go up by eight x every time you double sparsity.

Speaker 1

这到底是好是坏啊?

So is that good or bad, actually?

Speaker 1

从内存角度看,别忘了,你每次都在把内存读取量翻倍,而这部分本来是靠批量摊薄的。

Even from a memory point of view, keep in mind, you are doubling this portion of the memory fetches, which is amortized by batch.

Speaker 1

所以干脆直接加大批量就行。

And so just just keep running a larger batch size.

Speaker 1

从我们这里做的分析来看,这完全是赚到了。

From the point of view of the analysis we've done here, this is pure win.

Speaker 1

继续这么做。

Keep doing it.

Speaker 1

直到你用光了所有可用用户为止,就一直做下去。

Keep doing it until you run out of available users, basically.

Speaker 1

对。

Mhmm.

Speaker 1

所以实际上,如果你想用稀疏模型,或者你用户很多,就可以用更稀疏的模型。

So there's actually this equivalence between if I want to go sparse, or if I have a lot of users, I can go to a much sparser model.

Speaker 1

从这个角度看,这个权衡是合理的。

So from that point of view, it's it's a reasonable trade off.

Speaker 1

另一个问题是它也会占用内存容量,我们刚才只讨论了内存带宽,但它确实也会消耗内存。

The other trade off that shows up here is that it also consumes memory capacity, which we we we've only reasoned about memory bandwidth here, but it also So consumes memory

Speaker 0

让我确认一下我有没有理解对。

let me just make sure I understood.

Speaker 0

你是说我们希望减少计算时间,对吧?

You're saying we want bigger we we want to spend less time computing.

Speaker 0

所以我们要增加稀疏性。

Therefore, we do more sparsity.

Speaker 0

为了实现这个,我们需要更大的批量,对的。

To make that work, we need bigger batch sizes Mhmm.

Speaker 0

这就意味着我们需要更多的内存容量。

Which means we need more memory capacity.

Speaker 0

没错。

Yeah.

Speaker 0

所以为了实现更高的稀疏性。

So To have more sparsity.

Speaker 1

没错。

Yeah.

Speaker 1

那咱们不妨趁这个机会聊聊,专家混合层在实际的GPU集群上一般是怎么部署的。

So, I mean, maybe this would be a good point to actually talk about how a Mixture of Experts layer is typically laid out on on a, like, on a rack of GPUs or something.

Speaker 1

是的

Yeah.

Speaker 1

对

Yeah.

Speaker 1

有道理

Makes sense.

Speaker 0

嗯

Yeah.

Speaker 0

我们刚才说到哪儿了?

Where were we?

Speaker 1

稀疏专家混合模型

Sparse Mixture of Experts.

Speaker 1

没错

Yes.

Speaker 1

也许可以聊聊怎么在GPU上部署这个结构

Maybe how we lay that on out on a GPU.

Speaker 1

对。

Yep.

Speaker 1

咱们先聚焦在专家混合层上,画个图看看它长什么样。

So let's zoom in on the Mixture of Experts layer first and and and sort of draw what that looks like.

Speaker 1

通常我们会有一个路由层,这个没错。

So we typically will have a some kind of a router layer Mhmm.

Speaker 1

它负责决定把每个词元分发给哪个专家。

Which is making the decision of where we route the experts the the tokens to.

Speaker 1

所以会有词元输入进来。

So we get tokens coming in here.

Speaker 1

它们经过路由层,然后被送到一堆不同的专家那里。

They go through a router layer, and then we have a bunch of different experts.

Speaker 1

我多画几个,好对齐一下。

I'll draw draw a few more to line some up.

Speaker 1

路由层会决定把词元派给哪些专家,但只会选其中一小部分,比如三十二个里选一个。

And then the router will make a decision on which experts am I gonna route to, and it'll be a small fraction of them, maybe one in 32.

Speaker 1

所以它可能会决定把任务交给这个专家,也可能交给这个,还有这个。

So maybe it'll make a decision to route to this one, maybe this one, and maybe this one.

Speaker 1

这些专家本身呢,其实就是普通的MLP。

These experts so these each expert itself is a normal MLP.

Speaker 1

它有个上层投影,接着是个非线性激活,再下来是下层投影。

It has a up projection and then a down projection and a nonlinearity in between.

Speaker 1

最后呢,我们再做一遍反过来的操作。

And then finally, we sort of do the inverse operation.

Speaker 1

之前是把数据分发出去,现在就要收回来,加总在一起。

So where we were broadcasting things out here, we're gonna bring them back in and sum them up.

Speaker 1

就像这样把它们收回来。

So bringing them in like this.

Speaker 1

最后,还有残差连接,原始的token也会直接走这条路,然后加到MoE层的输出上。

And then finally, we have our residual connections that the token is also passed through here, and it gets added to the result of the MoE layer.

Speaker 1

所以,这就是一个标准的MoE层。

So so this is a normal MoE layer.

Speaker 1

我想聊聊这个结构是怎么映射到GPU机架上的,以及这对通信意味着什么。

What I want to talk through is how this is mapped to a, like, a GPU rack and what this means for communication.

Speaker 1

因为我觉得这会开始暴露出我们速度上的瓶颈。

Because I think this will will start to show some of the the limits of how fast we can go.

Speaker 1

没错。

Yeah.

Speaker 1

所以目前的标准做法——也是最优解——是用专家并行。

So the standard practice here, and it it is the best solution, is to use expert parallelism.

Speaker 1

也就是说,不同的专家分配到不同的GPU上。

So that means different experts go on different GPUs.

Speaker 1

比如DeepSeq模型,它有256个专家。

So if we take something like a DeepSeq model, they have 256 experts.

Speaker 1

假设我们要在Rockwell机架上跑这个模型。

Let's say we want to run that on a Rockwell rack.

Speaker 1

这个机架一共有72块GPU。

So there are 72 GPUs.

Speaker 1

我们遇到一个整除问题。

We have a divisibility problem.

Speaker 1

这不是2的幂次。

This is not a power of two.

Speaker 1

所以咱们干脆点,就用64个好了。

So we'll just, like, simplify and say we're only gonna use 64 of them.

Speaker 1

剩下的八个直接忽略掉。

Just ignore the other eight.

Speaker 1

没啥大不了的。

It's not a big deal.

Speaker 1

这样每块GPU上分配四个专家。

And so we we have four experts per GP.

Speaker 1

很简单吧。

Very simple.

Speaker 1

为了图示清楚,咱们就假设每块GPU放两个专家。

For the sake of the diagram, I'll actually just say, let's let's say we have two experts per GPU.

Speaker 1

所以我们最后就把这些作为GPU的分界线。

So we we end up just putting these are the GPU boundaries.

Speaker 1

每两个专家都放在单独的GPU上。

Every pair of experts is on its own GPU.

Speaker 1

然后我们来看看通信开销。

And then we can look at the communication cost.

Speaker 1

有些专家模型存在这里,还有一些token集中存放在中央。

We had some experts stored there's some tokens stored centrally here.

Speaker 1

这些token会被分发到所有的专家那里。

They get routed to all of these experts.

Speaker 1

所以这里会产生一些通信开销。

And so there's some communication cost paid here.

Speaker 1

输出端也有同样的通信开销。

There's the same communication costs paid on the output.

Speaker 1

我们希望这种开销不会成为瓶颈。

And then the hope is that this does not become communication limited.

Speaker 1

那这里的流量模式是怎样的呢?

Now, what is the traffic pattern here?

Speaker 1

这里的流量模式是,任何一块GPU都可能跟其他任意一块GPU通信,具体取决于模型的决策。

The traffic pattern here is that any GPU, in fact, will be talking to any other GPU depending on the decisions made by the model.

Speaker 1

所以这是一种全对全的通信模式。

So this is an all to all traffic pattern.

Speaker 0

你刚才说任何GPU,意思是……对,没错。

So when you say any GPU in the pretense, Yeah.

Speaker 0

这个路由组件不止一块GPU吧?

The router is more than one GPU?

Speaker 1

是的。

Yeah.

Speaker 1

我画的时候只画了一个路由模块。

The route so I I drew this as one router.

Speaker 1

但实际上,你会有好多份这样的路由模块。

In reality, you would actually have many copies of the router.

Speaker 1

实际上,有多少个GPU,就有多少个路由器。

And so you would have as as many routers as as GPUs, in fact.

Speaker 0

就跟进入的流量一样。

As the incoming traffic.

Speaker 1

对。

Yeah.

Speaker 1

这里是64个GPU。

So, these are 64 GPUs.

Speaker 1

这里是64个GPU。

These are 64 GPUs.

Speaker 1

其实都是同一组GPU。

It's actually the same GPUs.

Speaker 1

我们只是画成分开的,因为它们承担的职责不一样。

We just draw them as separate because they're serving different purposes.

Speaker 1

所以这时候,任何一个GPU都可以跟其他任意一个GPU通信。

So at this point, any GPU can be sending to any any other GPU.

Speaker 1

所以这种全互联的通信模式,正好契合了MoE模型实际需要的通信方式,而Blackwell机架的配置正是为此设计的。

So this all to all pattern of communication that shows up and how how the Blackwell racks are configured is a is a perfect fit for the the communication pattern that the MoE actually wants to do.

Speaker 1

不过,如果你想着,也许一个机架太慢了,想用两个机架,那就会遇到一个问题——比如你在外头划了一道机架边界。

However, if you think, maybe I want to do like, maybe one rack is too slow and I want to do two racks, then I have this challenge that, like, maybe I've got some sort of rack boundary drawn outside here like this.

Speaker 1

这样一来,两个机架里的所有GPU之间,就不再是全互联的通信了。

And I no longer, in fact, have all to all communication between all the GPUs in two racks.

Speaker 1

于是,机架之间的通信就成了一个很大的瓶颈。

And so the rack to rack communication ends up being a substantial bottleneck.

Speaker 1

所以核心问题在于:一个机架的规模,实际上就决定了你能部署的专家层的大小。

So this sort of like, the fundamental thing here is that one rack is actually the bounds the size of an expert layer you can do.

Speaker 1

这也正是推动我们不断扩展互联范围的原因之一。

And so this has been part of what's been driving towards larger and larger interconnect domains.

Speaker 0

是的。

Yeah.

Speaker 0

但在我们继续之前,也许你该先解释一下,到底什么叫做‘机架’。

But before we it may be worth you explaining what exactly a rack is.

Speaker 0

对的。

Mhmm.

Speaker 0

机架内和机架间的带宽差异

The differences in bandwidth between a rack and within a rack

Speaker 1

没错。

Yeah.

Speaker 0

机架内是全互联,机架外就不是了,这个区别挺关键的。

And the all to all versus not all to all nature of communication within versus outside.

Speaker 1

对。

Yeah.

Speaker 1

这一点上,NVIDIA、谷歌,还有我们自己,做法其实差别挺大的。

And and this is a place where it starts to be very different, in fact, between NVIDIA, for example, and Google, and then others, including us.

Speaker 1

一般来说,机架就是一个物理结构。

The so generally, a rack is a it is a physical structure.

Speaker 1

大概几米高,一两米宽,具体看配置,里面通常能放64个GPU或者XPUs。

It it's a few meters tall, a meter or two wide, depends on configuration, and it stores some number of GPUs or XPUs, which is typically about 64.

Speaker 1

这种尺寸的限制主要来自供电、重量和散热能力。

The the cons what constraints it being a certain size is power delivery, weight, and cooling ability.

Speaker 1

很多时候,机架就是做成这么大,因为物理条件就这么摆着。

It ends up being about this size in in many cases because of these physical constraints.

Speaker 1

所以当我部署一个数据中心时,比如,一个数据中心可能有成千上万个这样的机架。

So then when I deploy a data center, like, I've got a data center may have thousands of these racks.

Speaker 1

我这儿有一个高高的机架。

So I've got one of these tall racks.

Speaker 1

里面装了一堆GPU之类的设备。

It's got a bunch of GPUs in it and so on.

Speaker 1

然后我再把另一个机架挨着放上去。

And then I put another rack next up.

Speaker 0

你这话听着也太简单了吧。

You make it sound so easy.

Speaker 1

对。

Yeah.

Speaker 1

我就直接把它们塞进去了。

I I just, like, dropped them in.

Speaker 1

在英伟达的方案里,他们把显卡放在机架外侧,而把交换机放在机架内侧。

In NVIDIA's case, the the communication topology is actually they put the GPUs on on the outside of the rack, and then they put these switches on the inside of the rack.

Speaker 1

所以实际上,这里面有一组交换机。

So what this ends up being is that there's a set of switches in here.

Speaker 1

这些就是NV交换机。

These are the NV switches.

Speaker 0

对。

Mhmm.

Speaker 1

然后他们拉了一大堆线缆。

And then they run a bunch of cables.

Speaker 1

每一块显卡都有一根线连到中间的交换机。

Every single GPU has cables going going to the switches in the middle.

Speaker 1

每块显卡都连到中间的交换机,而交换机又连着所有显卡。

So every GPU goes to switches in the middle, and then the switches have connections to all the GPUs.

Speaker 1

所以所有的GPU之间通信,最多只需要两跳:先到交换机,再跳到目标GPU。

So all of the GPUs can talk to all the other GPUs in in just, like, two hops, going to switch, going to the other GPU.

Speaker 1

但当我需要把数据传出机架时,就得走另一条路了。

Now when I want to leave the rack, I end up going via a different path.

Speaker 1

GPU还有一条慢得多的连接通道,速度大概是前者的八分之一,我在这儿画的绿色线,就是NVLink。

The GPUs have also a much slower connectivity, which is typically about eight times slower, which is so so the green that I drew here in GPU cases is the NVLink.

Speaker 1

更广义地说,这叫‘扩展上行网络’。

More generally, it's called the scale up network.

Speaker 1

这就是扩展上行网络。

This is the scale up network.

Speaker 1

通常你还会有一个‘扩展出域网络’,用来连到数据中心的交换机。

You will typically also have a scale out network, which allows you to connect to, like, some data center switch.

Speaker 1

就是数据中心交换机。

So data center switch.

Speaker 1

然后所有GPU都会通过某种方式连到某个数据中心交换机上。

And then all of the GPUs will have some connectivity up to some data center switch somewhere.

Speaker 1

对。

Mhmm.

Speaker 1

但这个就是所谓的扩展网络,速度大概慢八倍,说白了就是挺慢的。

But this is this is about times like, this is the scale out, and it tends to be about about eight times slower in in bad words.

Speaker 1

所以如果你要把专家混合层跨两个机架部署,问题就来了——这边一半的GPU得跟那边的GPU通信。

So the challenge, if you want to, for example, lay out a mixture of expert layer across two racks, is that half of the GPUs here are gonna be wanting talk to the GPUs here.

Speaker 1

平均来看,当我看这些GPU上的token要往哪儿走时,有一半的token其实只想在机架内部走。

And so, like, half of the like, just on average, like, when I look at where the tokens on on these GPUs want to go, half of the tokens are gonna wanna go inside the rack.

Speaker 1

这没问题。

That's great.

Speaker 1

它们可以用高速的机架内互联网络。

They can use the the fast scale up network.

Speaker 1

但另一半的token得跨机架去另一个机架,这就麻烦了。

But half the tokens are gonna want to leave the rack and go to the other rack, and that's not as good.

Speaker 1

它们只能用慢得多的网络。

They're gonna need to use a much slower network.

Speaker 1

所以这成了全连接模式的瓶颈。

And so that becomes the bottleneck on on the all to all pattern.

Speaker 1

另一种做法是,干脆在这儿放个大交换机,把两个机架全都连到一个更大的交换机上。

A different choice would be, well, why don't I, like, have a big switch here and sort of, like and connect everything to some big switching like, much bigger switch that actually combines the two racks together.

Speaker 1

这方面的想法不少,但一般来说,之所以用分层交换结构而不是一个大交换机,就是为了避免线缆太拥挤。

There are many ideas in this direction, but in general, it becomes the reason you have this sort of hierarchy of switches rather than one big switch is to manage the cabling congestion.

Speaker 1

你得布大量的线。

You just need to run a large number of cables.

Speaker 0

不好意思。

Sorry.

Speaker 0

你刚才问的,是不是就是为什么不用更大的高速互联?

Is this is that question you just asked basically, why isn't it a bigger scale up?

Speaker 1

是的。

Yeah.

Speaker 1

没错。

Exactly.

Speaker 1

那为啥不直接搞上百万个芯片,直接往上堆呢?

Why not why not just, like, have, like, a million chips and scale up or something like that?

Speaker 0

到底是什么变了,让英伟达从Hopper的8个,到Blackwell的72个,现在Reuben据说要到……我不太确定。

What has changed that has allowed NVIDIA to go from Hopper was eight, then Blackwell is 72, and now Reuben will be I don't know.

Speaker 0

五百个?

Is it 500?

Speaker 1

五百多吧。

500 and something.

Speaker 0

对。

Yeah.

Speaker 0

到底是什么让这一切成为可能?

What what has allowed that to happen?

Speaker 1

从Hopper到Blackwell,最主要的就是决定把封装形式从托盘改成机架,就是把原来那种托盘换成机架。

So from Hopper to to Blackwell is is mostly just the decision to switch from trays as the form factor, one of these as a tray, just just switching to racks as the form factor.

Speaker 1

这是个产品决策。

That's a product decision.

Speaker 1

其实那里并没有什么重大的技术障碍。

It's there wasn't a substantial technical barrier there.

Speaker 1

从64个直接跳到500个左右,中间确实有点詹森式算法的成分,但至少真有四倍的提升,这来自更复杂、更难搞的机架设计。

Switching from from the, like, 64 to to 500 or so, there's a bit of Jensen math there, but there is at least a a genuine four x increase, which is coming from a much more complicated and difficult rack design.

Speaker 1

所以这其实是全新的物理设计,要塞进更多线缆。

And so that that is actually, like, new new physical design to run more cables.

Speaker 0

线缆的复杂性就在于得搞清楚哪根线连到哪,哪个信号走哪条路。

And the cable complication is just the the the the cost figuring out which cable hops to which or, like, which signal

Speaker 1

对。

Yeah.

Speaker 1

咱们不妨仔细看看这线缆密度的问题。

I mean, it's let's sort of zoom in on this and look at the the wire density.

Speaker 1

我再画一次这个图,这次画个更清楚、更大的版本,方便咱们分析。

I'll draw this diagram just once more so we have a bit of a cleaner version to work with, I mean, a larger version.

Speaker 1

假设中间放一些交换机。

Let's say have some switches in the middle.

Speaker 1

对。

Yep.

Speaker 1

我先在每边放两个GPU,或者每边放两块GPU托盘。

And let's say I'm gonna have initially, I'm gonna start with just two GPUs on each side or two two trays of GPUs on each side.

Speaker 1

假设每块托盘要引出两条线。

And let's say maybe each tray wants to have two cables coming out of it.

Speaker 1

所以我得布一些垂直的线,像这样连到交换机上。

So I get some kind of I I physically run vertical cables that look like this running onto the switches.

Speaker 1

如果我想把机架里的GPU数量翻倍,那线缆密度也得翻一倍。

Now if I wanna double the number of GPUs in a rack, I need to run, like, literally twice the density of cables.

Speaker 1

所以这些线也得布上去。

So I need to run, yeah, these as well.

Speaker 0

这个问题可能有点傻。

Extremely naive question.

Speaker 0

是的。

Yeah.

Speaker 0

但如果你看看实际的数据中心

But if you look at a physical data center

Speaker 1

对的

Mhmm.

Speaker 0

感觉机架里面空间挺大的

It seems like there's a lot of space within a rack.

Speaker 0

我不太确定

I don't know.

Speaker 0

那些线缆看起来特别粗,而且

Just like the cables are, like, really big and

Speaker 1

没错

Yeah.

Speaker 1

机架外面其实是有空间的

So there is space outside the rack.

Speaker 1

但机架里面呢,这些机架越来越紧凑,空间几乎被塞满了

Inside the rack like, these racks are, like I mean, as they become more optimized, these racks are very tight.

Speaker 1

所以说吧。

So Yeah.

Speaker 1

从托盘到机架,再到机架背板,连接器的密度越来越高,背板本身的密度也特别高。

There's connector density going from from from the tray into the rack and the rack's backplane, and then the backplane itself has a has a really high density.

Speaker 1

明白了。

Alright.

Speaker 1

还有其他一些物理限制,比如电缆的弯曲半径。

There are other physical constraints, including, like, bend radius of cables.

Speaker 1

你可不想把它弄断,等等。

Like, you don't wanna snap them and so on.

Speaker 0

对。

Yep.

Speaker 0

好的。

Okay.

Speaker 0

所以实际上就是得留出足够的物理空间来布线

So it's literally the physical space to put a cable

Speaker 1

是的

Yeah.

Speaker 0

这确实是个限制

That's constraining

Speaker 1

没错

it.

Speaker 1

是的

Yeah.

Speaker 0

我完全没想到

I had no idea.

Speaker 0

挺有意思的

Interesting.

Speaker 0

真没想到,机架这么大,怎么就不能多塞点线呢?

That seems surprising that, like, how about the rack is so big, and they're just, like we can't just stuff more cables in there.

Speaker 1

是啊

Yeah.

Speaker 1

所以啊,机架设计真不是我的专长。

So, I mean, rack design is not my expertise.

Speaker 1

但当我跟人聊的时候,问他们现在面临哪些限制,其实都是在权衡几个关键的物理因素:比如,你最想优化的是什么?

But, like, when I talk to to folks and what are the constraints they're up against, it's it's a combination of so what are the big physical things you're optimizing for?

Speaker 1

空间、机架的重量。

Space, weight of the rack.

Speaker 1

机架其实特别重,所以得有足够的顶部金属支撑,不然会变形塌下来。

Like, it's actually really heavy, and so, like, you need enough metal top to not sag and fall.

Speaker 1

但你要是加更多金属,重量又上去了,接着就是功耗和散热的问题。

But then you add more metal and it's heavier, and then power and cooling.

Speaker 1

所以这些因素全在互相拉扯,现代机架的设计已经把所有这些物理极限都推到极致了。

And so all of those are competing for like, modern racks are pushing all of those to very extreme physical limits.

Speaker 0

深度工作本质上就是让人不舒服的。

Deep work is, by its nature, quite aversive.

Speaker 0

所以像 Slack 和邮件这种看起来像工作的事,反而成了逃避的借口。

So even things which seem like work, like Slack and email, can be easy ways to distract yourself.

Speaker 0

我经常真想把互联网直接关了。

So I often wish that I could just turn the Internet off.

Speaker 0

但要是我准备面试,就算手头有论文和书,还是能靠大模型来回讨论,把概念理清楚,再顺藤摸瓜查后续内容,特别管用。

But if I'm prepping for an interview, even if I have the papers and books on hand, it's still super useful to be able to do a back and forth on the LLMs so I can break down concepts and research follow ups.

Speaker 0

谷歌新出的Gemma 4,是第一个让我能完全离线、专心做事的开源模型。

Google's new Gemma four is the first open model that allows me to have this kind of fully disconnected focus machine.

Speaker 0

它够小,能在我的笔记本上跑,但又够强,真能派上用场。

It's small enough to run on my laptop, but good enough to actually be useful.

Speaker 0

所以为了准备这期节目,我下载了Reiner的《Scaling》这本书,然后断了网。

So to prep for this episode, I downloaded Reiner's scaling book and shut off the Internet.

Speaker 0

我靠Gemma帮我理解内容、回答问题,特别顺手。

I was able to have Gemma help me understand and answer my questions.

Speaker 0

如果你想找个能跑在笔记本甚至手机上的本地大模型,真该试试Gemma 4。

If you want an LLM that you can run locally on your laptop or even your phone, you should check out Gemma four.

Speaker 0

GPT-4是啥时候发布的来着?

When was GPT four released again?

Speaker 0

是2022年还是2023年?

It was 2022 or 2023?

Speaker 1

2023年。

'3.

Speaker 1

对,就是2023年。

'3.

Speaker 1

明白了。

Okay.

Speaker 0

据说它的参数超过了万亿级别。

And it was rumored to be over 1,000,000,000,000 parameters.

Speaker 0

但直到最近这半年,才陆续有模型的参数量明显超过三年前发布的产品。

And it seems like only now and within the last six months have models been getting released that are significantly more parameters than a model released three years ago.

Speaker 1

是的。

Yeah.

Speaker 0

按理说这中间早就该有规模上的突破了,可我们其实是在等足够多内存的服务器,好装下五万亿参数的模型,外加它的KV缓存——得撑得住大量用户、长序列的请求,要是做强化学习,情况也差不多,得把所有待处理任务的缓存都存下来。

When supposedly there should have been this scaling in the meantime, is the reason that we were just waiting for racks with enough memory to hold the 5,000,000,000,000 parameter model along with its k b cache for enough, you know, users for a full for a lot of sequences or RL if you're doing RL, kind of a similar consideration of actually holding the KBChash for all the the the the batch of problems you're trying to solve.

Speaker 0

你看Hopper架构,当时用八张Hopper,到2022年总共也就640GB显存。

So if you look at, like, Hopper, you had eight Hoppers, and I think the that's 640 gigabytes as of 2022.

Speaker 0

对。

Yeah.

Speaker 0

直到Blackwell终于上线了,那是啥时候?2020年?

With Blackwall finally, which was deployed, what, 2020

Speaker 1

最近才出的。

Very recently.

Speaker 1

可能是去年吧。

Maybe last year.

Speaker 0

去年?

Last year?

Speaker 0

对。

Yeah.

Speaker 0

这才终于有了能撑起十到二十TB显存的规模。

You finally have a scale a up with on the order of, like, ten, twenty terabytes Mhmm.

Speaker 0

这足够支撑一个五万亿参数的模型加上KBCh了。

Which is enough for, like, a five t model plus KBCh.

Speaker 1

对。

Yeah.

Speaker 1

在更大规模的互联域里部署,简直是重大突破。

Deploying in in larger scale up domains is a huge unlock.

Speaker 1

没错。

Yeah.

Speaker 1

我这儿画的是英伟达Blackwell的部署架构。

I mean, I've drawn here the sort of NVIDIA Blackwell deployment.

Speaker 1

谷歌的部署其实早就有了超大规模的互联域,

The Google deployment has actually had very large scale up domains for

Speaker 0

这也解释了为什么Gemini看起来领先了。

And that that also explains why Gemini was seemed to be ahead.

Speaker 0

比如Gemini 2.5是真成功了,还是只是它的预训练比其他实验室持续得更久?

Like, was Gemini 2.5 was a successful or it just seems like Gemini has that successful pre train for longer than some of the other labs.

Speaker 1

我没在现场,不太确定有多少优势是来自成功提升了稀疏率,这确实有可能。

I not having been there at the time, I'm not sure how much is coming from, like, successfully deploying higher sparsity ratios, which which could be.

Speaker 1

也可能是,毕竟在模型设计上还有很多细节,比如专家混合到底该怎么搞。

It could also be I mean, there's a whole bunch of actual modeling things of, like, specifically, how do you do the mixture of experts?

Speaker 1

我们看到DeepSeek的专家混合模型就提到,真正突破点在于激活更多专家,但每个专家更精细。

We've seen the DeepSeek like, the DeepSeek mixture of experts has said, actually, activate more experts, but finer grained experts was a big innovation.

Speaker 1

我确信模型架构和训练数据上还有很多其他创新。

I'm sure that there are many other innovations on the model architecture as well as on the training data.

Speaker 1

这些因素混在一起,真的很难分得清谁贡献更大。

It's kind of hard to disentangle all of them.

Speaker 1

但就目前来看,能激活的参数量受限于算力成本,而总参数量则受限于扩展规模。

But what shows up in terms of the limits of what you can do, The the active parameters, as we saw, is limited by the compute cost, and then the total parameters is limited by the scale up size.

Speaker 0

对。

Yep.

Speaker 0

当你在单个扩展域内运行时,这个限制是特别影响前向传播、反向传播,还是预填充和解码阶段?

When you're operating within a single scale up domain, is that a consideration specifically for either forward or backward or specifically for pre fill versus decode?

Speaker 0

还是说,无论什么情况,最好都保持在同一个规模内?

Or is it is it preferred to always be within a scale up?

Speaker 0

对。

Yeah.

Speaker 0

不管你是做预训练、RL生成,还是给用户做推理,都一样?

Whatever kind of workload you have, whether you're doing a pre training run or whether you're doing RL generation or whether you're doing inference for users?

Speaker 1

是的。

Yeah.

Speaker 1

这问题真有意思。

Really interesting.

Speaker 1

那这么说吧。

So okay.

Speaker 1

要回答这个问题,我们得聊聊通信模式——之前我们谈过专家混合的通信模式。

So to answer that question, we're gonna need to talk about the communication patterns that so we've talked about the mixture of expert communication pattern.

Speaker 1

那就是全连接通信。

That is this all to all.

Speaker 1

就是全连接。

There's all to all.

Speaker 1

全连接。

All to all.

Speaker 1

全连接特别依赖完全互联,也就是我们刚才说的,最好都在同一个机架里。

All to all very strongly favors full connectivity, which what we've kind of just shown here, and it favors being within one rack.

Speaker 1

除了专家并行,还有别的并行方式。

There are other kinds of parallelism besides expert parallelism, which which we just showed here.

Speaker 1

文献里常见的是张量并行。

In the literature is tensor parallelism.

Speaker 1

现在趋势是专家模块越来越小,这种模式已经没那么重要了,可以忽略。

This is with the trend towards smaller experts, this has become much less relevant, so we can ignore that.

Speaker 1

不过我们还有另外两种方式:数据并行和流水线并行。

But the other two things that we have available are data parallelism and pipeline parallelism.

Speaker 1

它们反而更适合跨多个机架来部署。

And they are actually much they can be a much better fit for using multiple racks.

Speaker 1

那我们先专门聊聊流水线并行。

So let's focus on pipeline parallelism specifically.

Speaker 1

这只是一个 MoE 层。

This is one layer of MoE.

Speaker 1

上面我还要再加一百多层。

I'm gonna have, like, a 100 more layers up above.

Speaker 1

比如在这里,我完全可以换到另一个机架上。

I could decide at this point, for example, to move to a different rack change rack.

Speaker 1

那这样会不会变成通信瓶颈?

Now, is that gonna become a communication bottleneck?

Speaker 1

我们其实可以算出什么时候会变成瓶颈。

So we can actually just solve for when this becomes a communication bottleneck.

Speaker 1

不过在算之前,咱们先画个图,理一理数据流的路径。

But before we do that algebraically, like, let's just sort of visualize it out and and sketch the path.

Speaker 1

我们会有一堆这样的 MoE 层,这边一个,那边一个,就这么继续下去。

So we're gonna have a bunch this is another MoE layer, and we're gonna have another MoE layer here, and so on.

Speaker 1

所以假设我在这儿换机架,然后过几层之后,我又在这儿换一次机架。

So let's say I change rack here, and then some number of layers later, I change rack here as well.

Speaker 1

我们判断这种换机架的地方会不会成为通信瓶颈的方法,就是把横向扩展的带宽需求和纵向扩展的带宽需求做个对比。

So our our our methodology that we're gonna use to determine whether we have a communication bottleneck in this, like, in this point where we change rack is we're gonna compare the this this is the scale out scale out bandwidth requirements to the scale up bandwidth requirements.

Speaker 1

对。

Mhmm.

Speaker 1

咱们来试试看。

So let's try this.

Speaker 1

关键点在于,这儿的跨机架传输量大得多。

And and, I mean, the the hint is gonna be that there's a lot more transcends here.

Speaker 1

这边要传好多东西,而那边就只传一个。

Like, we're sending many things here, whereas we're only sending one thing here.

Speaker 1

而且可能还要反复这么干。

And then we're also maybe doing it many times.

Speaker 1

这才是真正造成区别的地方。

That's so that's going to be the what makes the difference.

Speaker 0

我能猜一下吗?

Can I try to guess?

Speaker 0

对。

Yeah.

Speaker 0

就是好奇看看我有没有真懂。

Just out of curiosity to see if I'm actually understanding.

Speaker 0

你好像把批量大小发到机架里了?

It seems like you're sending, like, batch size into the rack.

Speaker 0

是这里吗?

In here?

Speaker 0

没错。

Yes.

Speaker 0

但机架内部的通信量大概是批量大小乘以GPU数量。

But the communication within a rack is sort of batch size times number of GPUs.

Speaker 1

对。

Yeah.

Speaker 1

所以是实际激活的GPU数量。

So number of activated GPUs.

Speaker 1

对吧?

Right?

Speaker 1

我根本就没往这个GPU发数据。

So, like, I I don't send to this GPU at all.

Speaker 1

对吧?

Right?

Speaker 1

所以在这个图里,数据量从一变成了三倍,直接爆炸了。

So there's an explosion from one to, like, three times larger here in in this diagram.

Speaker 1

是的。

Yeah.

Speaker 1

关键是,我根本没必要往这个GPU发数据,这就省了不少东西。

The key thing is that I I didn't even need to send to this GPU at all, and so that's a big saving.

Speaker 0

明白了。

I see.

Speaker 0

对。

Yeah.

Speaker 1

好的。

Okay.

Speaker 1

那我们来聊聊,扩展性能的瓶颈到底有多大?是向上扩展比横向扩展慢多少?

So we're gonna talk through sort of how much more what is the slowdown of to what extent is scale up a bottleneck over scale over scale out?

Speaker 1

我们直接来看向上扩展所花时间与横向扩展所花时间的比值。

So we will directly jump to the ratio of the time spent on scale up, time on scale up, over the time spent on scale out.

Speaker 1

这就是我们今天要讨论的指标。

This is this is the quantity we're talking about.

Speaker 1

首先,一般来说,向上扩展的速度是横向扩展的八倍左右。

And the first consideration is that the scale up is, like scale up is is eight times faster than scale out, generally.

Speaker 1

所以,如果带宽一样的话,理论上这个比值应该是八分之一,这完全是带宽带来的差异。

And so at a baseline, if the bandwidths were the same, we would have this one one over eight, which is coming from bandwidth bandwidth.

Speaker 1

但实际中,我们传输的数据量还会进一步扩大。

But then we have some amount of expansion in in in how much data we're sending.

Speaker 1

所以如果有一个token进来,是这样的。

So if one token comes in here, Mhmm.

Speaker 1

那么在这个深度稀疏模型里,这个token会被分发给大约32个专家,或者16个专家。

Then this one token gets routed to in the deep sea case, it'll get routed to maybe 32 experts or or 16 experts.

Speaker 1

它会被分配到一定数量的专家那里。

It gets routed to some number of experts.

Speaker 1

这就是被激活的专家数量,被激活的专家数量。

So this is the number of activated experts, number of activated experts.

Speaker 1

而且这个情况在多个不同层上也会重复发生。

And then it also this this same thing applies on multiple different layers.

Speaker 1

比如我可能要跑两层。

So maybe I'm gonna run two layers.

Speaker 1

所以每个阶段的层数也会乘上一个倍数。

So there's also multiple times number of layers per stage.

Speaker 0

然后整个计算还得再乘以二,因为

And just need to multiply the whole thing by two for the

Speaker 1

对于最优情况来说。

For the the optimal.

Speaker 1

对。

Yeah.

Speaker 1

没错。

Yes.

Speaker 1

是的。

Yes.

Speaker 1

还有一个两倍的因子。

And there's a factor of two.

Speaker 1

谢谢。

Thank you.

Speaker 1

我们希望扩容所需的时间比扩展所需的时间更长,因为扩容才是更关键、更宝贵的资源。

So what we would like is the for the scale up time to be greater than the scale out time, because, like, the scale up time is the more important and precious resource.

Speaker 1

所以我们希望这个数值至少大于或等于一。

And so we just we want this one we would like this number to be greater than or equal to one.

Speaker 1

这其实没那么难。

And this really doesn't seem hard.

Speaker 1

咱们只需要克服一个8倍的差距,也就是说,这三个因素的乘积得大于8。

Like, we've we've there's just a factor of eight that we need to overcome, so we need the product of these three things to be bigger than eight.

Speaker 1

通常情况下,我们会有相当多的激活专家。

Typically, we have a fairly large number of activated experts.

Speaker 1

光是这个数字本身就能到8。

It could be eight by itself.

Speaker 1

然后我们可以大幅增加每阶段的层数,直到满足这个条件。

And then we can increase the number of layers per stage a lot until until we satisfy this.

Speaker 0

明白了。

I see.

Speaker 1

所以最终的效果就是,我可以整个流水线都用机架来搭,一个机架负责一层,接着换下一个机架做下一层,再换下一个。

So what this ends up looking like is that I can, in fact, have an entire pipeline of racks where one rack does one layer, and then I move on to the next rack, and I do another layer, and then I move on to the next rack.

Speaker 1

我还能再加一层。

I can do another layer.

Speaker 0

我觉得特别有意思的是,实际效果最好的并行策略,居然跟硬件架构长得一模一样。

It's interesting to me that the best parallelism strategy in practice ends up being one which physically resembles the actual architecture.

Speaker 0

根本不是什么天马行空的脑洞设计。

It's not some galaxy brain thing.

Speaker 0

你懂的吧?

You know?

Speaker 0

就是,咱们有专家模块,

It's like, oh, we have experts.

Speaker 0

那就把它们分别放到不同的GPU上。

We're gonna put them on g different GPUs.

Speaker 0

咱们有不同层,

Oh, we have different layers.

Speaker 0

那就把它们分到不同的机架上。

We're gonna put them on different racks.

Speaker 0

我觉得这挺有意思的,物理结构和

Isn't that I feel like that's interesting that the physical and

Speaker 1

模型架构和实际的划分方式完全对得上。

The the the model architecture matches like, the the the cutting matches the model architecture.

Speaker 0

是的。

Yeah.

Speaker 0

没错。

Exactly.

Speaker 0

对。

Yeah.

Speaker 0

本来搞成张量并行那一套乱七八糟的也行,但没那么干。

I mean, it could have been something wackier with tensor parallelism and whatever.

Speaker 1

对。

Yeah.

Speaker 1

我觉得可以这么理解,就是说——

So, I mean, I think a way to think of it is I mean, okay.

Speaker 1

从那种‘银河脑洞’的角度来看,模型扩展到底有哪些不同的维度?

The Galaxy Brain way to think of it is, like, what are all the different dimensions in which a model is scaled up?

Speaker 1

所以它是通过增加层数来扩展的。

And so there is it is scaled up by layers.

Speaker 1

它是通过模型的维度来扩展的。

It is scaled up by the, like, demodel dimension.

Speaker 1

它是通过DFF维度来扩展的。

It is scaled up by the DFF dimension.

Speaker 1

它是通过专家数量来扩展的。

It is scaled up by the number of experts.

Speaker 1

这些参数中的每一个,你都可以选择沿着它们做切分。

Every single one of those numbers, you can choose to cut along.

Speaker 1

只要这些数值足够大,沿着它们切分就会变得划算。

And if those numbers are big enough, it eventually becomes profitable to cut along there.

Speaker 1

是的。

Yeah.

Speaker 1

我们已经选了其中两个。

And we have selected two of them.

Speaker 1

另外两个,按常规模型的规模来看,根本赚不到钱。

The other two, in the way typical models are typically sized, are not profitable.

Speaker 0

有人提到伊利亚说过,现在别搞流水线并行。

So there's talk about Ilya where he says, today, know not to do pipeline parallelism.

Speaker 0

霍拉斯给我们这群人做过一场讲座,我真讨厌这种像医生随口说的话。

And Horace gave my friends and me, I hate that it's something like a doctor's quote.

Speaker 0

但他跟我们讲了各种并行方式,说流水线并行的问题在于,除了那些空泡,还会带来一堆架构上的限制。

But he gave us a lecture on these different kinds of parallelisms, and he said, the problem with pipeline parallelism is that it other than the bubbles, constrain it creates these architectural constraints.

Speaker 0

对。

Yes.

Speaker 0

比如Kimmy,它的残差连接会回头关注好几层之前的输出什么的。

On like, Kimmy, for example, has these residuals where attention attends to the A fewer back or something.

Speaker 0

没错。

Yeah.

Speaker 0

所以这种结构在实际实现上就特别麻烦。

Layers a few back and so that it becomes hard to implement in this way.

Speaker 1

是的。

Yeah.

Speaker 1

所以我们其实都没说清楚,流水线到底能带来什么实际好处。

So and I guess we didn't really fully articulate even what is the benefit that we're getting from pipelining.

Speaker 1

对。

Yeah.

Speaker 1

这些复杂性确实是实实在在的。

And so these complexities are real.

Speaker 1

流水线太折腾人了。

Pipelining is a massive hassle.

Speaker 1

但它确实有些好处。

It's but it does give you some benefits.

Speaker 1

你可以自己权衡一下,这些好处值不值得付出这些代价。

And then you can then decide whether those benefits are worth the costs.

Speaker 1

最明显的好处是在推理阶段,但训练阶段可能收益更大。

Biggest benefit that shows up so it has some benefits in inference, maybe bigger benefits in training.

关于 Bayt 播客

Bayt 提供中文+原文双语音频和字幕,帮助你打破语言障碍,轻松听懂全球优质播客。

继续浏览更多播客