
Advice for beginners in AI: How to learn and what to build | Lex Fridman Podcast
给 AI 初学者的建议:如何学习及构建什么 | Lex Fridman
50 分钟阅读Podcasts
【学习金律】Lex Fridman 对话 AI 专家:新手如何在 AI 浪潮中构建核心竞争力? 面对日新月异的技术,新手该如何入手?精选顶级工程师建议,探讨项目驱动学习与“建立直觉”的进阶路径。强调在 AI 时代,你的“品味”和“提问深度”将比纯编码能力更重要。 🎙️ 访谈人物介绍 Andrej Karpathy 等多位 AI 专家。 关键词:AI 学习、初学者建议、技术路径、Lex Fridman。
章节 1:AI学习的最佳路径——从零构建与逆向工程
📝 本节摘要:
本章节探讨了AI初学者掌握大语言模型(LLM)核心原理的最佳学习策略。嘉宾建议从零开始编写代码(From Scratch),而非直接使用复杂的现有库(如Hugging Face)。
核心观点包括:
1. 学习目标的设定:自建模型不是为了替代ChatGPT,而是为了通过“手写”理解预训练、微调及注意力机制的内部运作。
2. 避免过早追求规模:大规模模型涉及参数分片(Sharding)和多GPU管理,复杂度呈指数级上升,初学者应专注于单GPU模型。
3. Hugging Face的局限性:虽然它是行业标准,但其代码库为了兼容性而过度封装,逻辑交织,不适合用于学习底层原理。
4. “逆向工程”法:推荐通过阅读模型配置文件(Config File),复现架构,并尝试加载开源的预训练权重(Pre-trained Weights)。如果你写的代码能跑通别人的权重并输出一致结果,这就是最好的“可验证奖励”。
[原文] [Lex Fridman]: if we could take at this point a bit of a tangent and talk about education and learning if you're somebody listening to this who's a smart person interested in programming interested in AI so I presume building something from scratch is a good beginning so can you just take me through like what you would recommend people do
[译文] [Lex Fridman]: 如果我们此刻能稍微偏离一下主题,谈谈教育和学习。如果你是正在收听节目的聪明人,对编程感兴趣,对AI感兴趣,我假设从零开始构建一些东西是一个很好的开端,那么你能否带我了解一下你会推荐人们怎么做?
[原文] [Guest]: so I would personally start like you said uh implementing a simple model from scratch that you can run on your computer the goal is not if you build a model from scratch to have like something you use every day for your personal projects like it's not going to be your personal assistant replacing an existing openweight model or CHPD it's to see what exactly goes into the LLM what exactly comes out of the LLM how the pre-training works in that sense on your own computer preferably um and then you learn about the pre-training the supervised fine-tuning the attention mechanism you get a solid understanding of how things work
[译文] [Guest]: 我个人会像你说的那样开始,呃,从零实现一个可以在你自己电脑上运行的简单模型。如果你从零构建一个模型,目标并不是要拥有一个你每天用于个人项目的东西,比如它不会成为替代现有开放权重模型或ChatGPT的个人助手;其目的是为了看看究竟什么进入了LLM(大语言模型),究竟什么从LLM出来,以及预训练是如何工作的,最好是在你自己的电脑上进行。嗯,然后你会学习预训练、监督微调(SFT)、注意力机制,从而对这些东西是如何工作的有一个扎实的理解。
[原文] [Guest]: but at some point you will reach a limit because small models can only do so much and the problem with learning about LLMs at scale is I would say it's exponentially more complex to make a larger model because it's not that the model just becomes larger you have to now think about sharding your parameters across multiple GPUs you even for the KV cache there are multiple ways you can implement it one is just to understand how it works just to grow the cache let's it's like a cache you grow step by step by let's say concataining lists um growing it but then that wouldn't be optimal in GPUs you wouldn't do that you would pre-allocate a tensor and then fill it in but that adds again another 20 30 line lines of code and for each thing you add so much code,
[译文] [Guest]: 但在某种程度上你会遇到瓶颈,因为小模型能做的事情有限。而且学习大规模LLM的问题在于,我会说构建一个更大的模型在复杂度上是指数级增加的。因为不仅仅是模型变大了,你现在必须考虑在多个GPU之间对参数进行分片(Sharding)。甚至对于KV缓存(KV Cache),你也有多种实现方式。一种方式只是为了理解它是如何工作的,即逐步增长缓存——假设它像一个你通过连接列表逐步增长的缓存——但在GPU上这并不是最优的,你不会那样做。你会预先分配一个张量(Tensor),然后填充它,但这又增加了20到30行代码,每增加一样东西都会增加大量代码。,
[原文] [Guest]: and I think the trick with a book is basically to understand how the LLM works it's not going to be your production level LLM but once you have that you can understand the production level LM so you're trying to always build an LLM that's going to fit on one GPU yes the most of them I have they I have some bonus materials on some models i think one of or two of them they may require multiple GPUs but the goal is to have it on one GPU and the beautiful thing is also you can selfverify it's almost like RLVR when you code these from scratch you can take uh an existing model from the hugging face transformer library,
[译文] [Guest]: 我认为写书(或学习)的诀窍基本上是理解LLM是如何工作的,它不会成为你的生产级LLM,但一旦你掌握了它,你就能理解生产级的LM。所以你要尝试始终构建一个能放入单个GPU的LLM。是的,我拥有的大部分模型——我在某些模型上有一些补充材料,我想其中一两个可能需要多个GPU——但目标是将其放在一个GPU上。这样做美妙之处在于你可以自我验证,这几乎就像RLVR(基于规则的验证奖励)。当你从零开始编写代码时,你可以从Hugging Face Transformer库中取出一个现有的模型。,
[原文] [Guest]: um so the hugging face transformer library is great but if you want to learn about LMS I think that's not the best place to start because the code is so complex because it has to full it has to fit so many use cases also some people use it in production it has to be sophisticated and it's really intertwined and really hard it's not linear to read it was started as a fine-tuning library and then it grew to be like the standard representation of every model architecture and the way this loaded so hugging face is like the default place to get a model and transformers is the software that enables it so people can easily load a model and do something basic with it,
[译文] [Guest]: 嗯,Hugging Face Transformer库很棒,但如果你想学习大语言模型,我认为那不是最好的起点。因为代码太复杂了,它必须满足太多的用例,还有些人在生产环境中使用它,所以它必须很复杂,而且它是真正交织在一起的,非常难读,并非线性的。它最初是作为一个微调库开始的,然后成长为每个模型架构的标准表示形式以及加载方式。所以Hugging Face就像是获取模型的默认场所,而Transformers是使其能够运行的软件,让人们可以轻松加载模型并用它做一些基本操作。,
[原文] [Guest]: and all frontier labs that have open weight models have a hugging phase transformers version of it like from deepseek to GPTOSs so it's like the canonical weight that you can load there but again also even transformers the library is not used in production people use then sglang or vlm and it adds another layer of complexity we should say that the transformers library has like 400 models so it's a one library that tries to implement a lot of LLMs and so you have a huge code base basically it's like huge it's like it's I don't know maybe millions hundreds of thousands of lines of code and find it's like understanding the part that you want to understand is finding the needle in the haststack
[译文] [Guest]: 所有拥有开放权重模型的前沿实验室都有其Hugging Face Transformers版本,比如从DeepSeek到其他GPT类操作系统,所以它就像是你可以在那里加载的标准权重。但同样,即使是Transformers这个库也不常用于生产环境,人们会使用sglang或vllm,这又增加了一层复杂性。我们应该说Transformers库大概有400个模型,所以这是一个试图实现大量LLM的单一库。因此你面对的是一个巨大的代码库,基本上它是巨大的,我不知道,可能有数百万或数十万行代码。要在其中找到你想理解的部分,就像大海捞针一样。
[原文] [Guest]: but what's beautiful about it is you have a working implementation and so you can work backwards from it what I would recommend doing or what I also do is if I want to understand for example how almost 3 is implemented I would look at the weights in the model hub the config file and then you can see oh they used so many layers they use let's say group query attention or multi head attention in that case then you see all the components in like a human readable I don't know 100 lines of config file,
[译文] [Guest]: 但它的美妙之处在于你有一个可工作的实现,所以你可以从它倒推(Work backwards)。我会推荐的做法,或者我自己做的,就是假如我想理解——比如Llama 3是如何实现的——我会查看模型中心(Model Hub)里的权重和配置文件(Config File)。然后你会看到,哦,他们用了这么多层,他们用了比如分组查询注意力(Group Query Attention)或者多头注意力(Multi Head Attention)。在这种情况下,你会在一个大概100行的人类可读的配置文件中看到所有组件。,
[原文] [Guest]: and then you start let's say with your GPD2 model and add these things you know and the cool thing here is you can then load the pre-trained weights and see if they work in your model and you want to match the same output that you get with a transformer model and then you can use that as a basically as a verifiable reward to make your architecture correct and then it's kind of sometimes it takes me a day to with almost three the challenge was the rope for the position embeddings they had a yarn extension and there was some custom uh scaling there and I couldn't quite match the these things and in this struggle you kind of understand things but the cool thing is at the end you know you have it correct because you can unit test it you can check against the reference implementation
[译文] [Guest]: 然后你从,比如说你的GPT-2模型开始,把你所知道的这些东西加进去。这里最酷的事情是,你可以加载预训练的权重,看看它们是否在你的模型中工作。你要争取匹配你从Transformer模型中得到的相同输出,这样你就可以把它作为一个基本可验证的奖励(Verifiable Reward)来确保你的架构是正确的。然后,这有时候可能会花我一天的时间。比如在Llama 3上,挑战在于位置嵌入(Position Embeddings)的RoPE(旋转位置编码),他们有一个Yarn扩展,还有一些自定义的缩放,我当时没法完全匹配这些东西。正是在这种挣扎中,你会逐渐理解这些概念。但最酷的是,最终你知道你是正确的,因为你可以进行单元测试,你可以对照参考实现进行检查。
[原文] [Guest]: and I think that's maybe one of the best ways to learn really like to basically reverse engineer something yeah I think that that is something that everybody that's interested in getting to AI today should do and I think that's why I liked your book is like I came to language models from this RL and robotics field like I've never had taken the time to just like learn all the fundamentals and this transformer architecture I describe as being like so fundamental as like deep learning was a thing that I had to learn in the past and people need to do this
[译文] [Guest]: 我认为这可能是最好的学习方式之一,真的,就像是基本上对某些东西进行逆向工程(Reverse Engineer)。是的,我认为这是每个今天对进入AI领域感兴趣的人都应该做的事情。这也正是为什么我喜欢你的书。我来自强化学习(RL)和机器人领域进入语言模型领域,我从未花时间去学习所有的基础知识。而这个Transformer架构,我将其描述为如此基础,就像深度学习是我过去必须学习的东西一样,人们也需要这样做。
- 章节 2:从基础架构到垂直领域研究
- 章节 3:解构RLHF——偏好量化与社会选择理论
- 章节 4:教育的本质——拥抱“挣扎”与各种捷径
- 章节 5:低算力科研策略与职业路径抉择
- 章节 6:激进的工作文化——996、激情与倦怠
- 章节 7:硅谷的“回声室”泡沫与广阔视角
正在加载后续章节…





