And we will come back to this, uh, from week six onwards and do a lot more in the way of discussing 我们将从第六周开始回到这个话题，并以讨论的方式做更多的事情
and understanding evals. 和理解评估。
Such an important topic. 如此重要的话题。
Okay. 好的。
So back back to the project at hand. 回到手头的项目。
In our case, of course, we were very lucky that the metric that we were playing with, the metric 当然，就我们而言，我们非常幸运，我们正在使用的指标
that we had the most insight to, was the business centric metric we were working directly with that 我们最有洞察力的是我们直接使用的以业务为中心的指标
improve the performance of some code. 提高一些代码的性能。
Doesn't happen often. 不经常发生。
I got to tell you, most of the time the model metrics are quite far removed from the actual business 我必须告诉你，大多数时候模型指标与实际业务相去甚远
metric, but in our case, we were working directly with that. 公制，但在我们的例子中，我们直接使用它。
And it was about the performance of C++ with with with the same with needed to have the same output. 这是关于 C++ 的性能，并且需要具有相同的输出。
And so far Gemini 2.5 Pro is our winner. 到目前为止，Gemini 2.5 Pro 是我们的赢家。
It's time now for us to go back to the lab one more time for a harder test, to really put them through 现在是我们再次回到实验室进行更困难的测试的时候了，真正让它们通过
the their final paces and see who we will crown the final winner. 看看他们最后的步伐，看看谁能成为最终的获胜者。
And to shake it up, I've decided to change things around a bit. 为了改变现状，我决定稍微改变一下。
And rather than rather than generating C++ code and translating from Python to C++, I have changed 我没有生成 C++ 代码并从 Python 转换为 C++，而是进行了更改
it. 它。
So we'll be generating from Python to Rust code rust, which happens to be, I think. 所以我们将从 Python 生成 Rust 代码 rust，我认为这恰好是。
I think it is the most loved language. 我认为这是最受欢迎的语言。
According to the StackOverflow developer survey for ten years in a row. 根据 StackOverflow 连续十年的开发者调查。
Most loved ten years. 最喜欢十年。
Let's see if we can figure out why. 让我们看看是否能找出原因。
When we translate a hard challenge from Python to Rust, let's go to curse. 当我们将一个艰巨的挑战从 Python 转换为 Rust 时，我们就去诅咒吧。
Okay. 好的。
Back in curse, we're opening week four. 回到诅咒，我们即将开始第四周。
We're going to day five. 我们即将迎来第五天。
And here we have it. 现在我们有了它。
As a reminder, it is optional to actually execute C++ or rust. 提醒一下，实际执行 C++ 或 Rust 是可选的。
You can do either. 你可以做任何一个。
I'll set this up, this lab up for either one, or you can just run it on the C++ website from yesterday 我将对此进行设置，此实验适用于其中任何一个，或者您可以从昨天开始在 C++ 网站上运行它
or just port the code. 或者只是移植代码。
Don't bother with the running your choice. 不要为你的选择而烦恼。
Also a reminder I will use some expensive models, but you can pick your own or just run it only open 另外提醒一下，我将使用一些昂贵的模型，但您可以选择自己的模型或仅运行它
source. 来源。
It's about the task, it's not about the compilation and so on. 这是关于任务的，而不是关于编译之类的。
So as usual, some imports as usual load in some environment variables. 因此，像往常一样，一些导入照常加载到一些环境变量中。
Make sure we've got everything keeping open router on the list again as well as grok. 确保我们已经将所有保持打开状态的路由器再次放在列表中以及 grok 上。
With a queue we will get all of our client libraries initialized. 通过队列，我们​​将初始化所有客户端库。
And as before, this is the list of models that we'll use. 和以前一样，这是我们将使用的模型列表。
I'm keeping the same set as yesterday. 我保留了和昨天一样的设置。
And here are they are linked to their client libraries okay. 这是他们链接到他们的客户端库的好方法。
Let's now find out about rust. 现在我们就来了解一下关于生锈的知识。
So there's a new function in that systeminfo thing that I added in there which is called rust info. 因此，我在 systeminfo 中添加了一个新函数，称为 rust info。
And if I run that then as well as my system information, it's going to give a whole ton of information 如果我运行它以及我的系统信息，它将提供大量信息
about whether or not I have a rust tool chain installed on my computer, which I do, and then I will 关于我的计算机上是否安装了 Rust 工具链，我安装了，然后我会
run this, that will again ask Gpc5 to give me instructions for how to install rust if I don't have 运行这个，如果我没有，这将再次要求 Gpc5 给我如何安装 rust 的说明
it, so it will give you instructions and this is very optional should you wish. 它会给你指示，如果你愿意的话，这是非常可选的。
You can stick with C++. 您可以坚持使用 C++。
Stick with what we did yesterday if you don't want to mess around, it's fun. 如果你不想搞砸的话，就坚持我们昨天做的事情吧，这很有趣。
If you know the nerd in, you might be interested and might want to do this. 如果您认识这个书呆子，您可能会感兴趣并且可能想要这样做。
It's especially cool if you don't know the language, because there's something very satisfying about 如果您不懂该语言，那就特别酷，因为有一些非常令人满意的东西
seeing a model generating something which looks foreign to you. 看到一个模型生成了一些对你来说看起来很陌生的东西。
You know, it's like, okay, I don't know what this means. 你知道，就像，好吧，我不知道这意味着什么。
I'm going to see if it actually works. 我要看看它是否真的有效。
So I find that kind of cool. 所以我觉得这很酷。
Uh, and, and it has, uh, done it and it's told me that I am already set up. 呃，而且，它已经，呃，完成了，它告诉我，我已经准备好了。
I have rust toolchain, and it's told me that this is the command that I need to run, and it looks 我有 Rust 工具链，它告诉我这是我需要运行的命令，它看起来
like a pretty legit command, and I've just copied that and pasted it down here. 就像一个非常合法的命令，我刚刚复制了它并将其粘贴到这里。
But you can leave this being your C++ one from yesterday if you'd like. 但如果您愿意，可以将其保留为昨天的 C++ 版本。
As you wish. 如你所愿。
Now let's go on to the main part and I begin here I've got language equals rust. 现在让我们进入主要部分，我从这里开始，我的语言等于生锈。
And just change that to C++ if you'd like to stick with C++. 如果您想坚持使用 C++，只需将其更改为 C++。
Everything else should work exactly as yesterday all the way through. 其他一切都应该和昨天一样。
Everything in this code works for either rust or C++. 这段代码中的所有内容都适用于 Rust 或 C++。
Rust, of course, also is a compiled language, so it compiles all the way down to a native machine 当然，Rust 也是一种编译语言，因此它可以一直编译到本机机器
code, just like C++. 代码，就像C++一样。
What famously rust is something which which is considered safe in that it compiles all the way down. 著名的 Rust 是一种被认为是安全的东西，因为它可以一直编译下去。
But what C++ lets you, if you wish, do very dangerous things that can cause the machine to crash horribly 但是，如果您愿意，C++ 可以让您做非常危险的事情，从而导致机器严重崩溃
or cause buffer overflows and security risks. 或造成缓冲区溢出和安全风险。
Rust does not permit that. Rust 不允许这样做。
So so, uh, we've we've, uh, we're gonna we're gonna see how that affects performance of the code. 所以，呃，我们已经，呃，我们将看看这如何影响代码的性能。
If it does and what we're able to do. 如果确实如此以及我们能够做什么。
Let's see. 让我们来看看。
So, uh, I've got I've got this part, as I say, that that puts in the word rust, but otherwise everything 所以，呃，我已经得到了这部分，正如我所说，其中包含“生锈”一词，但除此之外一切
is exactly the same as before. 和以前一模一样。
The same system prompt. 一样的系统提示。
Your task is to convert Python code into high performance language code. 您的任务是将 Python 代码转换为高性能语言代码。
That'll be rust, of course. 当然，那会生锈。
Respond only with rust Ross code, and it needs to produce identical output in the fastest time. 仅使用 Rust Ross 代码进行响应，并且需要在最快的时间内产生相同的输出。
The same user prompt as before. 与之前相同的用户提示。
The same messages as before. 与之前相同的消息。
The same write output as before. 与之前相同的写入输出。
The same port as before. 与之前相同的端口。
Just. 只是。
I've also made sure that we wipe out any special tags for rust. 我还确保清除了所有生锈的特殊标签。
And then the run python as before, which is going to run the python version of the code and compile 然后像以前一样运行python，这将运行python版本的代码并编译
and run where. 并跑到哪里。
Now this is. 现在是这样。
So it's the same code here because uh, it's just going to take the compile command and the run command 所以这里的代码是相同的，因为呃，它只是采用编译命令和运行命令
that you've got above. 你上面有的。
Okay. 好的。
Now let's look at some python. 现在让我们看一些Python。
Okay. 好的。
So last time we had some Python code to calculate digits of pi. 上次我们有一些 Python 代码来计算 pi 的数字。
We've got something harder this time. 这次我们遇到了更难的事情。
There's quite a lot of complicated code. 有很多复杂的代码。
And I will go through it later when we, uh, see it presented nicer and talking about it presented 稍后当我们，呃，看到它呈现得更好并谈论它时，我会再讲一遍
nicer. 更好。
This is where we're going to do that. 这就是我们要做的地方。
So we now have a little gradio app that's a little bit more involved than last time. 所以我们现在有了一个比上次更复杂的小渐变应用程序。
I bring in some styles that I've got sitting in another file there. 我引入了一些位于另一个文件中的样式。
You can check out the styles if you want, but but uh, yeah, I'm not much good at CSS, and I will. 如果需要，您可以查看样式，但是，呃，是的，我不太擅长 CSS，但我会的。
I will tell you that it was, uh, an LLM that generated this CSS right here. 我会告诉你，是一个法学硕士在这里生成了这个 CSS。
Of course, that's the way to do it these days. 当然，这就是现在的做法。
Uh, so we take in some CSS, we create our user interface as before. 呃，所以我们采用一些 CSS，像以前一样创建用户界面。
It's got it's actually it's now it's now got three rows. 实际上现在已经有三行了。
The first row has the, uh, Python code and the C++ code and then the set of buttons. 第一行有，呃，Python 代码和 C++ 代码，然后是一组按钮。
And then there's the second row. 然后是第二排。
And the third row has output cells for Python output and C++ output. 第三行有用于 Python 输出和 C++ 输出的输出单元。
And the other thing I mentioned is we're using a special gradient field called a GR code. 我提到的另一件事是我们正在使用一种称为 GR 代码的特殊梯度场。
So let's see what all this looks like. 让我们看看这一切是什么样子的。
If I run this up comes the user interface. 如果我运行它，就会出现用户界面。
And it's kind of cool. 这有点酷。
We've got ourselves this, uh, this code block right here and we can see what's going on really nicely. 我们已经有了这个，呃，这个代码块，我们可以很好地看到发生了什么。
Let me zoom out a bit. 让我把镜头缩小一点。
There we go. 我们开始吧。
Zoom all the way out. 一直缩小。
We can see this is all the code we're talking about. 我们可以看到这就是我们正在讨论的所有代码。
It probably looks super tiny for you. 它对你来说可能看起来非常小。
You have to squint, but I can make it a bit bigger. 你必须眯着眼睛，但我可以把它弄大一点。
There we go. 我们开始吧。
And I can just quickly tell you what it is that we're going to be running here. 我可以快速告诉你我们将在这里运行什么。
Okay, so what is this Python code? 好的，那么这个 Python 代码是什么？
What are we challenging our model with, right. 我们用什么来挑战我们的模型，对吧。
Well, to start with, we have something here which is a pseudo random number generator. 好吧，首先，我们有一个伪随机数生成器。
It generates fake random numbers I'm not relying on on like the random library in Python, because I 它生成我不依赖的假随机数，就像 Python 中的随机库一样，因为我
want to do something that will be totally reproducible in any other programming language, but also 想要做一些可以在任何其他编程语言中完全重现的事情，而且
because the way I do this, which is with a couple of big, big numbers, and then doing something where 因为我这样做的方式是用几个很大很大的数字，然后做一些事情
you multiply, add and take the remainder. 你乘法、加法并取余数。
The way that this is done is, is using a generator function using a yield of a value. 完成此操作的方法是使用使用值的产量的生成器函数。
And that's going to be something hard for the model to understand and translate to other languages with 这对于模型来说很难理解并翻译成其他语言
different constructs. 不同的构造。
So that was a sort of cool trick to use here. 所以这是一个在这里使用的很酷的技巧。
So okay, we can generate random numbers. 好吧，我们可以生成随机数。
So what. 所以呢。
Well, I wanted the kind of kind of formula here. 嗯，我想要这里的那种公式。
That's the kind of thing you might come across maybe in a game. 这就是你可能在游戏中遇到的事情。
Uh, so maybe if you're a games programmer or games dev, this might be the sort of thing that you've 呃，也许如果您是游戏程序员或游戏开发人员，这可能是您遇到过的事情
had to do. 不得不做。
But basically I make 10,000 of these random numbers between minus ten and plus ten. 但基本上我会在负十到正十之间生成 10,000 个随机数。
And the challenge that this code solves is, all right, I've got these 10,000 random numbers. 这段代码解决的挑战是，好吧，我已经得到了这 10,000 个随机数。
Tell me if you could pick any subset of numbers in a row, you could pick the first ten numbers, the 告诉我你是否可以选择连续的数字子集，你可以选择前十个数字，
middle 30, the last 20, any subset. 中间 30 个、最后 20 个、任意子集。
Then you could add those numbers up. 然后你可以将这些数字相加。
You would get a total. 你会得到一个总数。
What is the highest total that you could get by taking any sum subarray, any any number of numbers 通过取任意总和子数组、任意数量的数字，您可以获得的最高总数是多少
in a row within this array of 10,000 numbers. 在这个由 10,000 个数字组成的数组中的一行中。
And you might say, well, hang on, why isn't it just that just keep going. 你可能会说，好吧，坚持住，为什么不继续前进呢。
Just take the whole list. 只需获取整个列表即可。
Because remember, it has negative numbers in there too. 因为请记住，它也有负数。
So you might not want to take you might you might get the best possible outcome just by taking the three 所以你可能不想采取你也许你可能会得到最好的结果只是通过采取这三个
numbers in the middle if they're all positive. 如果它们都是正数，则将其放在中间。
So it's figuring that out. 所以它正在解决这个问题。
And of course, the way to do that which is shown here, which is a pretty standard approach, is to 当然，这里展示的方法是一种非常标准的方法，那就是
loop all the way through the whole array and as your starting point. 一直循环整个数组并作为起点。
And then for each one you have like a sub loop here, which then loops to see what the end could be. 然后对于每一个，你都有一个子循环，然后循环查看最终结果是什么。
And then you add that up and find the total. 然后将其相加并得出总数。
And you have to just make double sure that you don't accidentally check everything twice, which is 而且你必须双重确保你不会意外地将所有内容检查两次，这就是
easy to do if you're not careful. 如果你不小心，很容易做到。
And so that is what this does. 这就是它的作用。
And then I say, you know what? 然后我说，你知道吗？
Let's do that 20 times. 让我们这样做 20 次。
20 times with different sets of random numbers. 使用不同组的随机数进行 20 次。
Add the whole lot up and return it. 将全部添加并返回。
So there's a lot of calculations happening there, an awful lot. 所以那里发生了大量的计算，非常多。
And it's going to be hard for the model to understand all that, to translate it and to get exactly 模型将很难理解所有这些、翻译它并准确地得到
the same output, let alone make it faster at the same time. 相同的输出，更不用说同时使其更快了。
So we will see how they all do. 所以我们将看看他们都是如何做的。