神级项目训练GPT-2仅需5分钟,Andrej Karpathy都点赞
发布时间:2024-11-21 17:32
发布者:网络
浏览次数:租用 H100 的钱只需 233 美元。
2 训练的项目「llm.c」曾经引发机器学习社区的热烈讨论。☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 免费无限量使用 DeepSeek R1 模型☜☜☜



10B tokens-->1B tokens 8xH100 上花 45 分钟训练 -->8xH100 上花 5 分钟训练
先进的架构:旋转嵌入、QK-Norm 和 ReLU^2; 新优化器:Muon; 嵌入中的 Untied Head; 投影和分类层初始化为零(muP-like); 架构 shortcut:值残差和嵌入 shortcut(部分遵循论文《Value Residual Learning For Alleviating Attention Concentration In Transformers》); 动量(Momentum)warmup; Tanh soft logit capping(遵循 Gemma 2); FlexAttention。
<section><code>pip install -r requirements.txt</code></section><section><code>pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu124 —upgrade # install torch 2.6.0</code></section><section><code>python data/cached_fineweb10B.py 10 # downloads only the first 1.0B training tokens to s*e time</code></section><section><code>./run.sh</code></section>
<section><code>sudo apt-get update</code></section><section><code>sudo apt-get install vim tmux python3-pip python-is-python3 -y</code></section><section><code>git clone <a href="https://www.php.cn/link/e8cb5f581442030021d62fd780fa674d" rel="nofollow" target="_blank" >https://www.php.cn/link/e8cb5f581442030021d62fd780fa674d</a></code></section><section><code>cd modded-nanogpt</code></section><section><code>tmux</code><code></code><code></code><code>pip install numpy==1.23.5 huggingface-hub tqdm</code></section><section><code>pip install --upgrade torch &</code></section><section><code>python data/cached_fineweb10B.py 18</code></section>
<section><code>sudo docker build -t modded-nanogpt .</code></section><section><code>sudo docker run -it --rm --gpus all -v $(pwd):/modded-nanogpt modded-nanogpt python data/cached_fineweb10B.py 18</code></section><section><code>sudo docker run -it --rm --gpus all -v $(pwd):/modded-nanogpt modded-nanogpt sh run.sh</code></section>



<section><code>@torch.compile</code></section><section><code>def zeroth_power_via_newtonschulz5 (G, steps=5, eps=1e-7):</code></section><section><code>assert len (G.shape) == 2</code></section><section><code>a, b, c = (3.4445, -4.7750,2.0315)</code></section><section><code>X = G.bfloat16 () / (G.norm () + eps)</code></section><section><code>if G.size (0) > G.size (1):</code></section><section><code>X = X.T</code></section><section><code> </code><code>for _ in range (steps):</code></section><section><code>A = X @ X.T</code></section><section><code>B = b * A + c * A @ A</code></section><section><code>X = a * X + B @ X</code></section><section><code>if G.size (0) > G.size (1):</code></section><section><code>X = X.T</code></section><section><code> </code><code> return X.to (G.dtype)</code></section>
内存使用量比 Adam 低 采样效率提高约 1.5 倍 挂钟开销小于 2%
在更新中使用 Nesterov 动量,在动量之后应用正交化。 使用特定的五次 Newton-Schulz 迭代作为正交化方法。 使用五次多项式的非收敛系数以最大化零处的斜率,从而最小化必要的 Newton-Schulz 迭代次数。事实证明,方差实际上并不那么重要,因此我们最终得到一个五次多项式,它在重复应用后(快速)收敛到 0.68、1.13 的范围,而不是到 1。 在 bfloat16 中运行 Newton-Schulz 迭代(而 Shampoo 实现通常依赖于在 fp32 或 fp64 中运行的逆 pth 根)。
以上就是神级项目训练GPT-2仅需5分钟,Andrej Karpathy都点赞的详细内容,更多请关注其它相关文章!
# 产业
# python
# git
# docker
# 处理器
# ai
# follow
# type
# 仅需
# 迭代
# 训练器
# 神技
# 只需
# 南极
# 华纳
# 要在
# 五大
# 句话
# 黄冈免费网站推广app
# 运城seo优化作用
# 如何优化网站应承易速达
# 什么推广网站好点呢
# 南宁seo前景如何
# 京东商城营销推广力度
# 内江seo
# 高邮英文网站推广
# 网站优化友好链接优化
# 福州搜索优化讯息网站




