读见

Stanford CS312 测验讲评|µP、动量和权重衰减怎样影响训练

原题µP, Momentum & Weight Decay Predictions | Stanford CS312 Quiz Review with Tatsunori Hashimoto

约 15 分钟原文英文已翻译

视频由 YouTube 提供

推荐理由复习课适合已经有训练配方的人,先选出最可能随模型宽度或批规模改变的参数,再决定哪些设置值得重新验证。

看前速览

4 个要点

斯坦福大学教师 Tatsunori Hashimoto 结合独立实验和课堂作业,解释模型宽度、批量大小和参数化方式为何会改变最合适的训练设置。

  1. 共享模块改变了缩放方式

    深度 µP 针对随机贡献的平方根累积。共享参数的模块贡献完全相关,会线性累积。对照中,CompleteP 经过五次更新后损失最低。

  2. 学习率与权重衰减的乘积可用于估算损失变化

    热图上,学习率乘权重衰减相同的对角线对应较低损失。偏离最优乘积时,取偏离倍数的对数、平方,再乘约 0.01,可估算本次实验中的损失增加量。

  3. 批量大小会改变动量与权重衰减的作用

    批量为 8 时去掉动量,代价较小,批量为 256 时损失增加明显。批量增至 512 后,最优峰值学习率已开始趋缓,最优权重衰减仍在上升。

  4. Hyperball 的宽度缩放介于基线和 µP 之间

    Hyperball 把更新缩放到权重矩阵的 Frobenius 范数附近,最优学习率随宽度变化的指数约为负二分之一,介于 Adam 基线的宽度倒数和 µP 的近乎恒定之间。

完整摘要

Tatsunori Hashimoto 用 Stanford CS312 优化测验中的实验与课程作业对照。多个模块共享参数时,贡献完全相关并线性累积,CompleteP 在五次更新后得到最低损失。学习率与权重衰减的乘积偏离最优值时,损失惩罚大致随偏离倍数的对数平方增长。去掉动量,在批量为 8 时约增加 0.02 的验证损失,批量为 256 时约增加 0.25。讲评还对比了 almost µP 和 Hyperball 的学习率迁移,并解释了为什么在本次批量为 512 的实验中,调整权重衰减比提高峰值学习率更有效。

章节

文字稿

查看原文

简要说明Brief Description

Tatsunori Hashimoto 逐步讲解了斯坦福 CS312 优化测验的解答。他将课程作业中的预测与关于参数化、学习率、动量、权重衰减和批量大小的留出实验结果进行了比较。Tatsunori Hashimoto walks through Stanford CS312 optimization quiz solutions. He compares predictions from the course assignments with held-out experiments on parameterization, learning rate, momentum, weight decay and batch size.

目录Table of Contents

  • 优化测验复习:理清思路
    Optimization quiz review: reasoning it out
  • Q1:共享模块,深度 µP 与 CompleteP
    Q1: Shared blocks, depth µP vs CompleteP
  • Q1b:对齐以及哪种损失最低
    Q1b: Alignment and which loss is lowest
  • Q2:余弦衰减与学习率乘以权重衰减
    Q2: Cosine decay and LR times weight decay
  • Q2b:二次惩罚的经验法则
    Q2b: Quadratic penalty rule of thumb
  • Q3:外推 Hyperball 的缩放趋势
    Q3: Extrapolating Hyperball scaling trends
  • Q4:批量大小为 8 与 256 时的动量扫描
    Q4: Momentum sweep at batch 8 vs 256
  • Q5:近似 µP 与学习率迁移
    Q5: Almost µP and learning rate transfer
  • Q6:Hyperball 学习率随宽度缩放
    Q6: Hyperball learning rate scaling in width
  • Q7:大批量训练:缩放权重衰减,而非学习率
    Q7: Large batch: scale weight decay, not LR
  • 教程和加分题安排
    Tutorials and bonus question logistics

优化测验复习:理清思路Optimization quiz review: reasoning it out

好,那么我们来看看这些题的解答。我觉得这次测验可能比第一次稍微难一些,但从某些方面来说,它也挺有意思,因为你可以通过推理得出不少题目的答案——虽然不是全部,但确实有不少。OK, so we will go through the solutions. I do think this quiz was maybe a little bit more advanced than the first one, but also, in some ways, I think this quiz is a pretty interesting one because you can reason through quite a few of the answers, not all of them, but quite a few of them.

Q1:共享模块,深度 µP 与 CompletePQ1: Shared blocks, depth µP vs CompleteP

第一个问题是,在这次作业中,我们有一个深度 µP 的例子,其中包含 1,000 个不同的块。那么,如果使用 1,000 个共享参数块,会发生什么?这里有多种选择。当然,这个问题的一个重要方面是,我们关注的是比值,而不只是 RMS 原始值。接下来我会讲解答案——我们对这份作业进行过内部测试,因此我从测试中提取了一些数据,只是想向大家展示作业中至少有哪些相关信息。这项测试不涉及测验,而是完全自主地完成整份作业。至少在这个例子中,如果改变深度,你会发现,就残差 RMS 而言,深度 µP 相当稳定。The first question is, in the assignment, we had a depth µP example where we had 1,000 different blocks. Now, what happens if you do 1,000 shared-parameter blocks? And we have various options here. And of course, an important aspect of this question is we're looking at the ratio, not just the raw RMS. And the way I'm going to go through the answers is that I'm going to go through-- we have an internal playtest of the assignment. So I've taken data from the playtests that we have just to show you what relevant information at least exists in the assignment. And this playtest doesn't look at the quiz, so it's just running through the assignment completely autonomously. So at least in this example, if you vary the depth at all, you'll see that depth µP is pretty stable in terms of the residual RMS.

当然,µP 会不受控制地增长。更新 5 次后也是一样。所以你可能会觉得,深度 µP 比 CompleteP 效果更好。那么比例的答案是什么?标准版和深度版的比例答案是选项 2,而 CompleteP 的是选项 C,也就是那个——抱歉,是选项 1,也就是较小的那个。其实这里重要的是比例。所以,如果你把这 3 个都看一遍,就会发现其模式和你可能在作业中见到的相同。RMS 实际上也处于相同的排序位置。只是对于这两个,不知为什么,它们的比例非常接近。而这个的比例则小得多。你可能会问,我怎么才能知道这一点?其实你完全可以通过推理得出,因为这些东西都在做什么?µP, of course, grows uncontrollably. Same story after 5 updates. And so you might have this impression that depth µP works better than CompleteP. So what is the answer for the ratio? The ratio answer is option 2 for the standard and depth, and then option C, the one that's-- sorry, it's option 1, which is the small one, for CompleteP. And really, the important thing here is it's the ratio. So if you look at all 3, the pattern is the same as the one you might have seen in the assignments. The RMS is actually in the same ranking. It's just that for these 2, for some reason, the ratios are very similar. For this one, the ratio is much smaller. And so you might say, how am I supposed to know this? Well, this is something that you can actually reason through, because what are all these things doing?

嗯,他们会根据深度的某个幂次来缩放残差贡献。因此,凡是加到残差流中的内容,都会乘上一个常数因子。所以计算比值时,所有通过残差流传递的贡献都会抵消掉这个因子。你可以看到这一点:如果观察加到残差流中的内容,并计算它们缩放前后的比值,得到的基本上就是一个常数因子。但有一点很重要:CompleteP 一开始使用的乘数非常小,因此所有残差贡献起初都很小。相对而言,进入底部残差流的嵌入要大得多。因此会出现这样的效果:这些比值并不会持续线性衰减。Well, they're shifting the residual contribution by some power of the depth. And so they're just going to multiply whatever stuff gets added to the residual stream by a constant factor. So when you take the ratio, these things cancel out for any contributions coming through the residual stream. And so you can see this. If you look at the stuff that's being added into the residual stream and you take the ratios of that before and after, you get basically a constant factor. But an important thing is that CompleteP is starting off with a very small multiplier, so all the residual contributions are small to start with. And so relatively speaking, the embeddings that are entering the residual stream at the bottom are much larger. And therefore, you get this effect where the ratios aren't constantly and linearly decaying.

你有一个很大的固定偏移量,扰乱了这个比率。因此,CompleteP 的乘数要小得多。但实际上,这里的核心观察只是了解标准 µP 和深度 µP 的行为。如果你知道 CompleteP 会大幅削弱 RMS 的贡献,使得嵌入占据主导地位,那么你大概就能在这道测验题上得出方向正确的结论。好,接下来看看经过 5 步之后会发生什么。You have this big constant offset that messes with the ratio. And so the CompleteP one just has this much smaller multiplier. But really, the core observations here are just knowing about the behavior of standard and depth µP. And if you knew that CompleteP was really going to kill the RMS contributions, and so the embedding would dominate, you would have probably gotten somewhere directionally correct on this quiz question. OK, and so now this is what happens after 5 steps.

Q1b:对齐情况及哪种损失最低Q1b: Alignment and which loss is lowest

三种损失中哪一种最低?我其实会说,这个问题可能比其他问题更容易回答,因为它本质上是在问对齐问题。在作业中,你可能已经看到,就拟合后的验证损失而言,depth µP 的表现明显优于其他方法。原因是,如果你仔细想想,在初始化时,所有权重都可以说是随机的。我们在课上讲过,当权重是随机的,就会出现平方根缩放。如果出现平方根缩放,那么 depth µP 正好就是在校正这种平方根缩放。那 CompleteP 校正的是什么呢?CompleteP 校正的是所有东西都对齐的情况。如果所有东西都对齐,那就是复制所有模块的情况,也就是完全相关。Which one has the lowest of the 3 losses? This one, I would actually argue, is maybe easier to know about than the others because this is really a question about alignment. So in the assignment, what you might have seen is that depth µP would work significantly better in terms of the fitted validation losses than the others. And the reason for this, if you want to think about it, is, at initialization, all the weights are kind of random. And we talked about in lecture, when they're random, you got the square root scaling. And if you get square root scaling, well, depth µP is exactly correcting for that square root scaling. And what's CompleteP correcting for? Well, CompleteP is correcting for the case where everything's aligned. And if everything is aligned, well, that's the case where you copy all the modules. You have perfect correlation.

如果相关性完美,所有东西都会大致线性放大。因此,你确实需要 1/L 缩放。这正是实验中观察到的结果。最终的情况是,CompleteP 明显优于 depth µP,也优于基线,也就是这里的 0 点。这是对同一结果的另一种可视化方式。所以对于这个问题,CompleteP 是这里的最佳选择。在问题 2A 之前,两个均值相差多少?这取决于我们看的是哪一组,不过这一组大约是 0.06。这和 0.05 非常接近。是的。If you have perfect correlation, everything is going to sort of amplify linearly. And so you really want the 1/L scaling. And this is exactly what shows up in the experiment. You end up with the case where CompleteP is significantly better than depth µP as well as the baseline, which is the 0 point over here. And this is a different visualization of the same thing. So for this question, CompleteP turns out to be the best choice over here. Before question 2A, how different are the two means? It depends on which one we're looking at, but this one's about 0.06. That's so close to 0.05. Yes.

Q2:余弦衰减与学习率乘以权重衰减Q2: Cosine decay and LR times weight decay

好的,那么 Q2A 现在问的是:我们不再对学习率和权重衰减的扫描结果进行线性衰减,而是改为衰减到 0 的余弦衰减,然后进行损失排名。这与 A2 中你们应该做的内容非常接近。你们应该绘制这些二次图。从这些图中应该观察到,基本上,学习率乘以权重衰减所得的对角线是一个非常重要、需要追踪的常数。然后你们可能会看到像这样的热力图,其中对角线上的损失较低;离对角线越远,损失就越高。这道题相当直接,我们不是在试图难为你们。基本上,只要直接读出与作业中相同的关系,就能答对这道题。OK, so Q2A is now a question about, instead of doing linear decay on our sweep over learning rates and weight decays, we're just going to do cosine decay to 0, and then we're going to do loss ranking. So this is pretty close to what you should have done in A2. You should have made these quadratic plots. The observation you should have made with these plots is that essentially the diagonal, learning rate times weight decay, is a very important constant to track. And then you maybe saw a heat map like this, where essentially the diagonals are low loss. And then as you go off, you get increasingly higher losses. This is a pretty straightforward question. We're not trying to trick you. Basically, if you just read off the exact same relationship as what you had in the assignment, you would have gotten the question right.

B 和 A 的损失非常低。F 和 E 的损失相近。D 和 C 的损失较高。仔细推理一下这些项在超参数网格中的位置,就会发现这恰好对应这种块结构。只有一种排列方式比较接近。所以这就是第 2 题的答案。B and A are very low loss. F and E are similar loss. D and C are high loss. And that corresponds to exactly this kind of block structure if you reason through where this lives in the hyperparameter grid. There's only really one ordering that's anywhere close. So that's the answer for question 2.

Q2b:二次惩罚法则的经验法则Q2b: Quadratic penalty rule of thumb

B 部分是数值预测的后续问题。如果我们采用配置 C,而它并非最优配置之一,那么我们和——最优损失 2.83——相差多远?然后我们还得猜猜这个东西是什么。我觉得,这题你要么会随便猜一个,要么可能在某次作业里画过这样的图。如果你画过,那答案就会更直接一些。基本上,你可能会好奇,如果调整 LR 乘以 WD 的乘数,效果会有多糟。所以理想情况下,我们希望把它固定住。那就是 x 等于 y 的直线。那么,偏离这条直线会发生什么呢?Part B is the numerical prediction follow-up. If we have configuration C, which is not one of the optimal ones, how far off are we from-- the optimal loss is 2.83. And then we're supposed to guess what this guy is. This one, I think, you were either going to guess out of a hat or you would have maybe made a plot like this somewhere in your assignments. And if you did, this would be a more straightforward answer. Basically, you may have been curious of how much it hurts if you mess with the LR times WD multiplier. So we ideally want to keep that fixed. That's the x equals y line. Well, what happens when we deviate from that line?

而且当你画出这个图时,大致会看到一些二次项,它们的缩放量级大约是 0.01。如果你知道这一点,就会知道要取乘积的对数,计算它偏离了多少,将其平方,再乘以某个常数;这样得到的结果大致就是你要找的值。然后,这基本上就能准确预测出选项 4。结果竟然如此接近,我其实有点惊讶,但这基本上就是经验法则。你可以取其中一些二次项——如果你知道这一点,至少可以用它们的数量级——再乘以对数乘积的平方,基本上就能得到准确的预测。哪怕结果接近一些也已经很好了。And when you make this plot, you'll roughly see that there are quadratics, and they're roughly going to be on the order of something like 0.01 scaling. And if you knew that, then you would know that you take the log of the product, how far off you are, square it, and multiply by some constant, and that's going to be roughly what you're going to get. And then that basically bang-on predicts option 4. I'm actually kind of surprised by how close that ends up being, but that is basically the rule of thumb. You could have taken some of the quadratics, at least the order of magnitude if you knew this, and then multiply it by the log product squared, and you would basically get exactly the prediction. Anywhere close would have been good, too.

Q3:外推 Hyperball 的缩放趋势Q3: Extrapolating Hyperball scaling trends

好,问题 3。问题 3 又是一道非常简单的题。我们觉得应该安排一些相当简单的题。问题 3 的内容大致就是:如果把这条线延长,就能得到正确答案。所以我们想在这里说明的是,至少根据你们在作业中看到的数据,即使把缩放定律外推得很远,你们也会发现这些关系大多是线性的,或者至少 Hyperball 的关系大体上是线性的。AdamW 在外推得很远时确实会出现一些奇怪的缩放行为,但总体来说,你可以把 Hyperball 上的这条线延长。我们并不打算把这道题弄得太复杂。所以,只要按照趋势线推下去,就能得到大致的答案,也就是 0.008。而这个答案最终只会落入一个选项区间,那就是那个选项。OK, question 3. Question 3 is yet another really straightforward one. We thought that we should have some fairly straightforward ones. Question 3 is literally something like, if you extrapolated this line out, you would get the right answer. So maybe the point that we were trying to make here is that at least in the data that you will have seen in the assignment, even if you extended out your scaling laws pretty far, you will have gotten that these things are mostly linear, or at least Hyperball is mostly linear. AdamW does actually have some funky scaling once you go far out, but you can, for the most part, extend the line on Hyperball. We're not trying to be too fancy here. And so if you really just follow the trend line, you will get roughly the answer, which is 0.008. And there's only really one answer bin that that guy is going to resolve to, which is that option.

Q4:批次大小为 8 与 256 时的动量扫描Q4: Momentum sweep at batch 8 vs 256

接下来是问题 4。问题 4 是什么来着?哦,这是动量扫描。问题 4 是在两种不同的批次大小下进行动量扫描。再说一次,问题 3 和 4,我的意思是,还有问题 2,也都是直接基于作业内容展开的。问题 4 再次问的是:你在作业中是否做过某种特定的动量扫描?希望你在作业中画出的图会像这样。你会发现,批次大小为 8 时,结果通常对动量不太敏感。不仅如此,这条曲线上的最优值还会向右移。最优动量实际上非常接近 0.99;而且,批次大小为 256 时,曲线两侧的上弯也都相当陡。因此,如果你了解这些,我想你的答案应该能大致落在 1 的范围内:我们确实知道,这两种情况下 β=1 很可能都是最差的。Then we have question 4. Question 4, what was this one? Oh, this is the momentum sweep. 4 is the momentum sweep at 2 different batch sizes. Once again, so questions 3 and 4, I mean, also 2, are building pretty directly off of the assignment. Question 4, once again, is really asking, did you make a particular kind of momentum sweep in your assignment? And hopefully, in your assignment, you will have produced plots that look like this. And you'll know that batch size 8 is generally pretty insensitive to your momentum. Not only that, the optimum shifts farther to the right on this curve. The optimum momentum is actually pretty close to 0.99, and also batch 256 have pretty sharp upper bends on both sides. And so if you know this, then I think you will have gotten this answer to roughly within 1, which is we do know that probably beta 1 is the worst in both of these guys.

然后这两个数,0.9 或 0.98,你可能猜错了;但如果你仔细观察小批量情况下曲线的形状,就会知道 0.98 会更好。同样,对于这个例子,判断要容易一些,因为在大批量情况下,曲线呈现出非常明显的杯形,所以你会知道 B 很可能是使目标函数最小的那个值。最后,你可能会问:好,那如果我们在所有这些情况下都去掉动量会怎样?如果这样做,我们可以再看一遍图,至少在脑海里想象一下。我们会知道,至少对于灰色那条——或者说,黑色那条——性能不会受到太大影响。它的曲线相当平坦;而对于蓝色那条,也就是大批量的情况,性能就会受到相当大的影响。我们在课上也讨论过这一点。所以归根结底,只是要定量地选出这些数值。And then these 2, 0.9 or 0.98, you might have guessed this wrong, but if you were carefully looking at the shape of the low-batch case, you would know that 0.98 would have been better. Similarly, for this one, it's a little bit easier because in the high-batch case, it's such a big characteristic cup that you would know that B is probably the minimizer. And finally, you might ask, OK, what happens when we remove momentum in all of these? And then if we do that, we can look at the plot again, at least mentally. And we would know that at least for the gray one-- or, sorry, black one-- we would not have much of a penalty. It's a pretty flat line, whereas for the blue one, which is the high-batch case, we should really suffer quite a bit. We talked about this in lecture as well. And so really, it's just a matter of picking quantitatively what these numbers are.

至少在这里这个例子中,小批量的情况大约是 0.02,大批量的情况是 0.25。这是一个非常灾难性的数值。我确实觉得这个数值差 1 完全可以接受。但我认为这个数值,如果你看一下验证损失的范围,就会发现它确实飙升得很厉害。所以你本该预料到结果会相当糟糕。And at least in the case here, the small-batch case is around 0.02, and the large-batch case is 0.25. This is a truly catastrophic number. I do think getting this one off by 1 is a totally reasonable thing. But this one, I think, if you were looking at the validation loss ranges, this guy is really shooting up. And so you should have predicted that this would be pretty degenerate.

Q5:近似 µP 与学习率迁移Q5: Almost µP and learning rate transfer

好,第5题基本上就是 µP。说真的,第5题的关键,基本上是弄清楚 readout 在模型中起什么作用,以及 readout 对模型稳定性和行为的影响。第一个问题是在问宽度为 1,024 的模型和宽度为 512 的模型,它们的最优学习率之比是多少。我们来看看数据是否正确。对,我想你们可能会用到的相关作业数据,是这样一张图:你在改变模型宽度,观察最优峰值基础学习率,并比较 baseline 和 µP 两种情况。对于 µP,我们知道这条曲线相当平坦;对于 baseline,斜率大约是 −1。因此我们知道,近似 µP 的情况会介于两者之间。OK, question 5 is almost µP. Really, the key to question 5 is basically figuring out what the readout does in a model and also the impact of the readout just in terms of the stability and behavior of the model. So the first question is asking about the ratio between the 1,024-width model and the 512-width model's optimal learning rates. And so let's see if we have the right data. Yeah, so I think that the relevant assignment data that you might have is a plot that looks like this. You're changing your width. You're looking at optimum peak base learning rate, and you would compare them for both baseline and µP. In the case of µP, we know this guy's pretty flat. In the case of the baseline, the slope is roughly −1. And so we know almost µP is going to be somewhere in between.

如果它处在两者之间,我们觉得它应该在哪里呢?我们认为它应该在中间某处。在这个例子中,相对于网络的其余部分,读出层的贡献其实非常小;结果发现,它比课程基线更接近 µP——我的意思是,我们确实称它为“几乎是 µP”。因此,最终正确的答案是,正确的比率接近 1,因为它基本上是恒定的,变化不大。如果它接近基线,那这个比率就应该是 1/2,也就应该更接近这里。所以你可以这样推理:它接近 µP 吗?这两个数字你可能会差 1,但无论如何,根据你对 µP 和读出层行为的了解,你至少应该能猜到第 2 或第 3 项。And if it's somewhere in between, where do we really expect it to be? Well, we expect it to be somewhere in the middle. In this case, the readout is actually a very small contribution relative to the rest of the network, and it turns out to be much closer to µP-- I mean, we did call it almost µP-- than the course baseline. And so the correct answer ends up being that the right ratio is close to 1 because it basically is constant. It doesn't change very much. If we were close to baseline, then that should be 1/2, and that should be closer to here. And so you can reason through by-- is it close to µP or not? These 2 numbers, you may have gotten it off by 1, but regardless, you should be able to guess it to within, at the very least, items 2 or 3 based on your knowledge of µP and the behavior of the readouts.

如果你只差 1,问题不大,尤其是当你在这项作业中指向相关实验时。有些地方确实有些模糊。我们只是希望能对其中一些情况做更细致的区分;但总体来说,只要一阶项算对了,你就可以对自己挺有信心。好,B 部分。这基本上是同一类问题,只是换了个问法。我们只是想问,这会造成多大影响?影响很大吗?还是很小?如果我们就做同样的事,会发生什么?那么,如果我们迁移峰值学习率,我们确实知道,对于 µP——你可能已经生成了类似这样的表格——直接迁移的效果就很好。它基本上和重新调参一样好。所以,既然我们知道这一点,也知道 almost µP 基本上就像 µP 一样,我们就应该预期它造成的影响会非常小。And if you're off by 1, it's not a big deal, especially if you're pointing towards relevant experiments that you run in this assignment. Some of these are somewhat ambiguous. We just want to be able to have more fine-grained separation for some of these, but for the most part, if you get the first-order terms right, you should feel pretty good about yourself. OK, part B. This is basically the same kind of question. It's a variation of the same thing. We're just asking, how much does this hurt? Is it a lot? Is it a little? What happens if we just do the same thing? Well, so if we transfer the peak learning rate, we do know that for µP-- you might have generated a table like this-- direct transfer just does fine. It's basically as good as if we tuned it again. And so if we know that, and we know that almost µP is basically like µP, we should expect that the impact that we get is very low.

这个问题唯一要注意的是,我们实际上是在把最小化器和我们实际运行的东西进行比较。而后者并非真正最优,因此存在一点次优差距。这就是为什么我们落在选项 3 档,而不是选项 4 档。不过无论如何,最终的差距都很小,因为毕竟,almost µP 和 µP 几乎一样。你应该从作业中了解到,µP 的学习率可以直接迁移。The only thing about this question is really we're comparing the minimizer to the actual thing that we ran. And this is not actually optimal, so there is a little bit of a suboptimality gap. And that's why we're in the option 3 bin rather than the option 4. But regardless, you end up with a very small gap because, after all, almost µP is like µP. You should know from the assignment that µP, you can just directly transfer the learning rate.

Q6:Hyperball 学习率随宽度的缩放大小规律Q6: Hyperball learning rate scaling in width

好,问题 6。这题讲的是 Hyperball。接下来我们要研究 Hyperball,进行宽度扫描,并查看峰值,从而找出最佳学习率。问题是:在标准参数化下,Hyperball 的学习率缩放规律是什么?这题其实和之前一样,可以考察同一个实验。可能有两点值得关注和思考。左图还是宽度扫描:我们改变宽度,观察最优学习率。这里的关键是,基线的学习率会按宽度的倒数衰减,而 µP 的学习率则保持不变。这种缩放规律很重要。我们还知道,对齐度大约是 0.75,这意味着从某种意义上说,我们更接近完全对齐的 µP 状态,而不是平方根 n 状态。OK, question 6. This one was the Hyperball one. And so now what we're going to do is we're going to do Hyperball, and we're going to do width sweep, and we're going to do peak, and we're going to look for what the best learning rate is. So now the question is, what is the learning rate scaling of Hyperball under standard parameterization? So this one, really, once again, you would look at the same experiment in a way. There's really two things maybe that you could have looked at and thought about. So on the left, once again, we have the width sweep. We vary width. We look at the optimal learning rates. And we would see that really the key thing here is that baseline decays at 1 over the width, whereas µP stays constant. This will be important scaling. We also know that alignment is roughly around 0.75, which means that we're closer in some sense to the full aligned µP regime rather than a square root n regime.

现在,理解 Hyperball 的一种方法,是在脑海中推演一下它在做什么。Hyperball 会取得某个矩阵,将这个更新归一化,然后再将其缩放回 W 的 Frobenius 范数大小。你可以推断,就步长而言,这大致相当于乘以宽度平方根的倒数。基本上,Adam 需要将步长按 1/m 缩放。如果 Hyperball 隐式地为我们提供了类似 1/√m 的缩放,那么我们预期这两者之间的差距应该是 1/√m。事实证明,这种推理相当接近实际情况。不同随机种子的运行得出的指数大约在 −0.38 到 −0.55 之间。实际数值介于两者之间,但稳稳落在 −0.75 到 −0.25 这个区间内。Now, one way to reason about Hyperball is to mentally do the math of, what is Hyperball doing? Well, Hyperball is going to take some matrix. It's going to multiply-- it's going to normalize this update and then scale it back up to the size of the Frobenius norm of W. You can reason that this is going to be roughly 1 over the square root of width in terms of the step size. At base, Adam needed 1/m scaling for the step size. If Hyperball implicitly gives us something like 1 over square root m, well, the gap that we expect between these two should be 1 over square root m. And it turns out that this kind of reasoning is not too far off. Different seeded runs give you exponents somewhere around −0.38 to −0.55. The real number is somewhere in between, but that's comfortably in this bin of −0.75 to −0.25.

所以你可以通过推理得出这个答案,但你也可以再想一想:Hyperball 也许会起到一定的稳定作用,让结果正好落在这两者之间,这样你也能得出同样的答案。很好。B 部分的问题是:对于这个最佳采样学习率,迁移惩罚又是多少?对于 Hyperball,惩罚比之前略大一些,但我们仍然预计它会低于 Adam 的情况,也就是 0.12。最后你会落在中间某个位置,也就是 C 的范围内,介于 0.02 和 0.08 之间。说实话,我在试玩这个题目时,觉得这一题比其他题更难猜一些。我认为你只需要了解这些数值的大致量级。So you could have reasoned about this, but you could have also thought through, once again, that maybe Hyperball would have some stabilizing effect, and it would put you right in between these two, and that would have gotten you to that answer as well. Great. For part B, the question is, what is the transfer penalty, once again, for this best sampled learning rate? And for Hyperball, there is a slightly bigger penalty than before, but once again, we expect it to be less than the Adam case, which is 0.12. And you end up landing somewhere in the middle here, which is in the band of C, between 0.02 and 0.08. This one, honestly, as I was playtesting this, was a little bit harder for me to guess than the other ones. I think you just have to know the scales of some of these things.

Q7:大批量训练:调整权重衰减,而非学习率Q7: Large batch: scale weight decay, not LR

这是最后一道题,我觉得它还挺有意思的,也是这次测验中我最喜欢的一道题。现在我们要采用一个相对于这门课来说非常大的批量大小:512。更新次数会少得多,而现在我们有许多不同的技巧,可以让模型在这种相当大的批量大小下进行训练。你需要弄清楚该选择哪种方案。你可能在作业中见过这样的图。随着批量大小增大,确实存在一种缩放规律,但最优峰值学习率的缩放曲线会逐渐弯折。你不能只是一味地调高峰值学习率。即使不做作业,你也可以从带噪声的二次模型中推导出这一点:不能只是一味地调高学习率。So this is the last question, which I thought was pretty fun. This was my favorite question of the quiz. So now we're going to take, relative to the class, a really large batch size, which is 512. We have way fewer updates, and now we have lots of different tricks that we can apply to make things train under this fairly large batch size. And you have to figure out which of these recipes you're going to pick. So from the assignment, you may have seen plots that look like this. As you increase the batch size, we do have a scaling law, but the scaling law kind of bends for optimal peak learning rate. You can't just keep cranking up your peak learning rate. And you could have also just, without doing the assignment, reason about this from the noisy quadratic model. You could have known that you can't just keep cranking up your learning rate.

另一方面,你可能已经注意到,随着批量大小增大,最优权重衰减实际上也可能持续增大。基于这两个观察,你可能会说,实际上,与提高学习率相比,对于大批量训练,按比例增大权重衰减或许是更好的选择。那么我们该怎么做呢?抱歉,这里的可视化不太好。我们应该按比例增大权重衰减,也就是选择 D——事实证明这是正确的做法。也就是说,你要尽量保持最佳比例,同时增大权重衰减。很好。好,现在你可能会问,如果我保留原来的超参数,只增大批量大小,这样做会付出什么代价?我们知道,这样做的效果应该会差很多,因为这组超参数远非最优。On the other hand, you may have noticed that the optimal weight decay can, in fact, keep going up with larger batch sizes. Given these two observations, you might then say, actually, scaling weight decay might be the more preferable option for large batch relative to scaling up learning rate. So where does that leave us? Sorry, bad visualization here. That leaves us with doing weight decay scaling, which is option D-- turns out to be the right thing to do. Whereas you're going to try to keep the best ratio but then scale up the weight decay. Good. OK, and then now you might say, if I keep the original hyperparameters but then scale up the batch size, what is the penalty that I incur in doing this? Well, we do know that this should be a lot worse because this is a deeply suboptimal set of hyperparameters.

但我们必须推断情况会糟糕多少。看看这些选项,0.15 糟糕得多,和按比例线性增大批次大小一样糟。如果我们回到这里,就会看到,增大批次大小并使用预测出的学习率——我们知道这是非常糟糕的做法——会使损失增加约 0.13。这告诉我们什么呢?这说明我们的损失也许不至于那么高,但肯定会相当高。事实上,再说一次,如果你大致知道在 weight decay 与 learning rate 的乘积上偏离最优值会带来多大的惩罚,就可以这样推理:好,我偏离了 8 倍。取以 2 为底的对数,再将结果平方,因为这是二次关系,那么数量级大约是 0.01。这样一来,你得到的估算值也会恰好落在正确区间的中间。But we have to reason about how much worse. And so looking at the options, 0.15 is way worse. It's as bad as scaling the batch linearly. If we go back up to here, we see that scaling up the batch and using the predicted learning rate, which we know is a really bad thing to do, gives you a loss of around 0.13 increase. And so what does that tell us? Well, it tells us that maybe our losses are not necessarily going to be that high, but it is going to be pretty high. And in fact, once again, if you had known, roughly speaking, what the penalty is for going off the optimum on weight decay times learning rate, you could have reasoned, OK, I'm eight times off. I take the log base 2. I square that because that's the quadratic, and then rough order of magnitude is 0.01. So this would give you an estimate that also lands squarely in the middle of the correct interval.

答案是,如果你实际运行一下,结果也大致落在这个范围内。这在这道测验题里是个出人意料地稳健的经验法则,不过你也可以通过同时观察学习率和权重衰减,来推断这里的数量级。好了,以上就是答案。The answer is, if you actually run it, it's roughly in this range as well. This is a surprisingly robust rule of thumb in this quiz, but you could have reasoned about the order of magnitude here as well, mainly by looking at the learning rate and weight decay together. All right, so those are the answers.

教程和加分题安排Tutorials and bonus question logistics

最后再通知一件安排上的事。我们即将开始辅导课。请填写调查问卷,这样我们就能尽快为大家分配辅导课。到目前为止,我们还没有用到大家在作业中提交的加分题,不过我们很可能会在辅导课上使用这些题目,并以同样的方式奖励加分。这对我们来说在安排上要容易得多。One last logistical announcement. We're going to start tutorials. Please fill out the survey so we can assign them as soon as possible. Thus far, we haven't used the bonus questions that you've submitted on the homework, but we are probably going to use them in the tutorial and award bonus points in the same way. Logistically, that's a lot easier for us.

← 回到本期 · 第 20 条