跳到主内容
@wquguru
精选88GitHub 新爆发仓库(GitHub)技巧与观点

14岁少年用RTX 3060 Ti从零训练3.26亿参数模型Lyra

luka0x12/Lyra: A 326M-parameter decoder-only Transformer trained from scratch on 6.4B tokens using a single RTX 3060 Ti. Includes the full…

原文
发到 X
推荐理由

极低算力下的完整训练复盘极具参考价值,特别是失败记录部分,建议低资源研究者收藏参考。

A 326M-parameter decoder-only Transformer trained from scratch on 6.4B tokens using a single RTX 3060 Ti. Includes the full pretraining, SFT, and inference pipeline.

一个拥有 3.26 亿参数的仅解码器 Transformer,使用单张 RTX 3060 Ti 在 64 亿 token 上从头训练。包含完整的预训练、SFT(监督微调)和推理流程。

GitHub repository created 2026-12-02 · 1089 stars in 1.6 days (about 660 a day) · Python

GitHub 仓库创建于 2026-12-02 · 1.6 天内获得 1089 颗星(约每天 660 颗)· Python

Lyra-326M

A 326M-parameter decoder-only Transformer trained from scratch on 6.4B tokens, on a single NVIDIA RTX 3060 Ti (8 GB VRAM), by a 14-year-old in Serbia.

一个拥有 3.26 亿参数的仅解码器 Transformer,由一名塞尔维亚 14 岁少年在单张 NVIDIA RTX 3060 Ti(8 GB 显存)上,使用 64 亿 token 从头训练。

This repository contains the complete pipeline: data streaming, pretraining, supervised fine-tuning (SFT), and the custom terminal chat interface.

该仓库包含完整的流程:数据流式传输、预训练、监督微调(SFT)以及自定义的终端聊天界面。

Model Weights: - Base Model: luka0x12/Lyra-326M-base - Instruct Model: luka0x12/Lyra-326M-Instruct

模型权重: - 基础模型:luka0x12/Lyra-326M-base - 指令模型:luka0x12/Lyra-326M-Instruct

The Build

构建过程

  • Pretraining (PTL-1): 195,312 steps on a mixture of FineWeb-Edu (70%), Cosmopedia v2 (20%), and Python-Edu (10%). Reached a validation loss of 2.32 nats (perplexity 10.19). - SFT (Second Voice): ~78k examples using length-bucketed batches and assistant-only loss masking. Taught the base model to answer questions, refuse gracefully, and stop rambling. - Hardware: One RTX 3060 Ti, 32 GB system RAM. Sustained ~10,000 tok/s during pretraining. Total wall-clock time: ~180 hours. Total energy: ~57 kWh.
  • 预训练 (PTL-1):在 FineWeb-Edu (70%)、Cosmopedia v2 (20%) 和 Python-Edu (10%) 的混合数据集上进行 195,312 步训练。验证损失达到 2.32 nats(困惑度 10.19)。 - SFT(第二声音):使用约 7.8 万个示例,采用长度分桶批次和仅助手端的损失掩码。教导基础模型回答问题、优雅地拒绝以及停止胡言乱语。 - 硬件:一张 RTX 3060 Ti,32 GB 系统内存。预训练期间持续吞吐量约为每秒 10,000 个 token。总耗时:约 180 小时。总能耗:约 57 kWh。

Repository Structure

仓库结构

Running Locally

本地运行

You do not need to train this from scratch to use it. Download the instruct weights from Hugging Face and run the chat interface.

你不需要从头训练即可使用它。从 Hugging Face 下载指令权重并运行聊天界面。

The Failure Ledger

失败记录

Building a training pipeline from scratch on constrained hardware means hitting every edge case in PyTorch. The `docs/architecture.md` file contains a detailed ledger of the 9 major bugs encountered during this project, including:

在受限硬件上从头构建训练流程意味着会遇到 PyTorch 中的各种边缘情况。`docs/architecture.md` 文件详细记录了本项目中遇到的 9 个主要错误,包括:

1. The 8x Loss Illusion: The dashboard displayed a loss of 35.2 because the GPU accumulator summed micro-steps but the readout only divided by optimizer steps. The model was fine; the math in the UI was wrong. 2. The Resume Rewind: `best.pt` only saved when validation improved. Restarting with `--resume` loaded a checkpoint from 20,000 steps ago, silently throwing away 10 hours of compute. Fixed by introducing a separate `last.pt` progress tracker. 3. CUDAGraph Collisions: `torch.compile(mode="max-autotune")` enables CUDA graphs, which require static memory addresses. Combined with gradient accumulation and `set_to_none=True`, the backward pass allocated new gradient tensors inside the captured graph, causing instant OOM crashes. 4. The "Drunk" Base Model: At 1.5B tokens, the base model output pure semantic drift (e.g., claiming the capital of France was Luxembourg). This wasn't a bug; it was the expected intermediate state of a model that had learned syntax but not yet bound sparse factual entities.

1. 8倍损失幻觉:仪表盘显示损失为35.2,因为GPU累加器对微步进行了求和,但读数仅除以优化器步数。模型本身没问题;UI中的数学计算有误。 2. 恢复回退:`best.pt`仅在验证集指标提升时保存。使用`--resume`重启时加载了2万步之前的检查点,无声无息地丢弃了10小时的计算量。通过引入独立的`last.pt`进度跟踪器解决了此问题。 3. CUDAGraph冲突:`torch.compile(mode="max-autotune")`启用了CUDA图,这需要静态内存地址。结合梯度累积和`set_to_none=True`,反向传播在被捕获的图中分配了新的梯度张量,导致瞬间OOM(内存溢出)崩溃。 4. “醉酒”的基础模型:在1.5B tokens时,基础模型的输出出现纯粹的语义漂移(例如声称法国首都是卢森堡)。这不是bug;这是模型学习语法但尚未绑定稀疏事实实体时的预期中间状态。

License

许可证

  • Code: Apache-2.0. Use it, fork it, build your own. - Weights: CC-BY-NC-4.0. The SFT mixture includes DailyDialog (CC BY-NC-SA 4.0) and non-commercial subsets of Tulu-3, so the final weights cannot be used for commercial products. - Custom SFT Data (`lyra_sft.jsonl`): CC0 (Public Domain). Do whatever you want with the identity dataset.
  • 代码:Apache-2.0。随意使用、分叉、构建你自己的版本。 - 权重:CC-BY-NC-4.0。SFT混合数据包含DailyDialog(CC BY-NC-SA 4.0)以及Tulu-3的非商业子集,因此最终权重不能用于商业产品。 - 自定义SFT数据(`lyra_sft.jsonl`):CC0(公共领域)。你可以对身份数据集做任何你想做的事。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件