Newshot

从零开始用100B token训练1B大模型的思考

Translation(model translation, not the source's own text)

文章标题:从头开始用100B token训练一个1B LLM的反思

正文: 是的,它并不是很好,但在某些方面是SOTA。有很多类似的东西,但这一个是我的。

我最近发现自己有一些时间和 Modal credits,所以我决定从头训练一个 LLM。虽然过去几年我有幸参与了后训练(以及一点点预训练)和模型评估,但我想看看自己能否端到端地完成这件事。成果是 Malama,以我思考其中大部分决策时所在的海滩命名。它是一个1B参数模型,使用 GLM tokenizer 和 Kimi Delta Attention 以及 full attention,并在100B token上进行了预训练,然后在编程问题上运行了 SFT 和 RL。这组选择对于商业努力来说可能并不合理,但构建一个实用模型并不是真正的目标。Malama 就其规模而言从根本上训练不足,因为我把 credits 花在了端到端流程上,而不是优化预训练。这非常有趣,尤其是探索不同的途径。

Chat benchmarks: LiveCodeBench v6, HumanEval, and MBPP
Chat benchmarks: LiveCodeBench v6, HumanEval, and MBPP

我能够让它在 HumanEval 和 MBPP 基准上(就其规模而言)具有竞争力。在编程(LiveCodeBench)上,它落后于最近的模型,即使这是它被训练所针对的细分领域。训练主要依赖现有数据集,尤其是来自 NVIDIA 的数据集。我承认,我是在通过代理蒸馏的方式,即纳入那些有前沿模型近期贡献迹象的开源仓库。特别是在 SFT 阶段,我使用更大的开源模型(Qwen3-30B-A3B、DeepSeek V4 Flash 和公开的 DeepSeek-R1 数据集)来提供推理轨迹,并使用 Qwen3-30B-A3B 为 RL 阶段筛选问题,其中奖励来自在沙盒中运行单元测试。

LiveCodeBench v6 with thinking, by model size and training stage
LiveCodeBench v6 with thinking, by model size and training stage

这次实践真正强调了高质量数据的重要性,尤其是每个 token 包含大量信息的数据。我自己尝试为公共数据集集合添砖加瓦,并拼凑了大约1B token的欧盟公开文件,但我发现它们实际上让模型变得更差而不是更好。大多数文档是半自动生成的,并且有大量低信息量的样板内容。事后看来这并不令人惊讶。它更新了我的偏见,即未来几年的关键突破不会来自新颖的架构或技术,而是来自找到信息密集的高质量数据池,或提高现有数据的样本效率。

做一些初步的规模和训练 token 估计,然后在训练运行中看到它实现,感觉训练模型更像是科学而不是艺术。

HumanEval: plain completion and chat
HumanEval: plain completion and chat

agents 能够帮助我制定实验和支线任务,并在 Modal 上快速运行它们,这令人愉快。例如,我能够尝试让早期版本成为一个 looped model——没有好处,因为目前问题仍然处于预训练阶段,而不是推理变化。给定验证函数的情况下,模型也非常擅长编写自定义 kernel,以提升整个流程各部分的速度。

除了数据、架构和训练方案的选择之外,相当一部分时间花在修复与恢复和并行化训练运行相关的各种问题上。我认为自己很幸运,一切都能装进一个 8xH100 机器,我不必担心跨多个主机训练。维护和修复训练运行感觉非常像我早期职业生涯中处理的大规模数据处理流水线。

我特意希望将训练定义为以下形式的工作流:

以便能够探索各种想法的空间,这意味着要承担一堆复杂性,才能使这项工作顺利整合起来。

Base models on arXiv abstracts of 2026-11-24 (bits per byte, lower is better)
Base models on arXiv abstracts of 2026-11-24 (bits per byte, lower is better)

看着模型随着参数和预训练 token 数量的增加,从胡言乱语慢慢变成能组成句子和更复杂的回答,感觉就像噪声凝聚成一幅美丽的图画。注意力和状态空间模型都像是推理的非常纯粹的表述。特别是状态空间模型,对我来说是记忆/状态最清晰的数学定义之一,而我很高兴发现 KDA 是 SSM 和注意力的后裔。

对我来说,训练一个 LLM 出乎意料地美丽。

感谢 Modal 提供额度,更重要的是提供了易于使用的基础设施,也感谢许多致力于开源 LLM 的人,他们为如何创建这些模型的共享理解做出了贡献,尤其是新一代开源 neo 实验室(Thinking Machines、Mirendil、Recursive、Ricursive、Flapping Airplanes 和 Open Athena / Marin)。

附录:代码生成示例

以下是 Malama v0.0.1 的两个未经编辑的通过生成(取自 jfrick/lm-exploration-results 的评估日志)。你也可以在 playground 中尝试提示 Malama v0.0.1 和更早的检查点。

LiveCodeBench v6(AtCoder abc387_b — 简单)

提示:给定一个整数 X,求 9×9 乘法表中所有不等于 X 的整数之和。


        Okay, I need to solve this problem. Let me read the question carefully.

The problem is about 9x9 multiplication table. Each cell has i*j. I need to find the sum of all numbers in the grid that are not equal to X. So, if X is present in the grid, I subtract all occurrences of X from the total sum of all numbers, then add the rest. Wait, no. Wait the problem says: "sum of those that are not X". So total_sum_total = sum of all 81 numbers in the grid. Then subtract the sum of all cells that have value X. So the answer is (total_sum_total - sum_of_X_cells) ?

Yes, that makes sense. So first, I need to calculate the total sum of all 81 numbers in the grid. Then subtract the sum of all numbers in cells where the value is X.

...

Testing sample 1: when X=1, the code loops i from 1-9, j from 1-9.

Only cell (1,1) has val=1. So sum_x += 1. All other cells are not 1. So total_sum is 81 + 7*18 = 81 + 126 = 202? Wait maybe not. Let me compute the total_sum.

Wait perhaps not. The sample 1's explanation says the answer is 2024, which suggests that the total_sum is 2024 + 1 = 2025? No. Wait sample 1's explanation says sum of all except 1 is 2024. So total_sum must be 2025 (sum of 1 is 1, so 2025-1=2024). So yes, the code's answer is correct.

Thus, the code seems to handle all samples correctly.

Edge cases: when X is not in the grid. For example, X=11. Then sum_x is 0. So answer is total_sum.

Another edge case: X=81. Then check if any cell has 81. But 9*9=81. So if X=81, then that cell (9,9) has value 81. So sum_x includes that. So answer is total_sum - 81.

Yes, the code handles that.

Thus, the Python code is as written above.
      

        X = int(input())

total_sum = 0
sum_x = 0

for i in range(1, 10):
    for j in range(1, 10):
        val = i * j
        total_sum += val
        if val == X:
            sum_x += val

answer = total_sum - sum_x
print(answer)
      

HumanEval(HumanEval/4 — mean_absolute_deviation)

提示:给定一个输入数字列表,计算该数据集围绕均值的平均绝对偏差。


        Okay, I need to write a Python function called mean_absolute_deviation that takes a list of numbers and computes the mean absolute deviation. Let me think about the steps here.

文章标题:从零开始在 100B tokens 上训练 1B LLM 的反思

所以,题目说对于列表中的每个数字,我必须计算每个数字与所有数字均值之间的绝对差。然后取这些绝对差的平均值。等等,也许不是。等等,公式大概是每个数字与均值之绝对偏差的平均值。

或者也许步骤是:

1. 计算列表中所有数字的均值。
2. 计算每个数字与均值之间绝对差的总和。
3. 将该总和除以元素个数,得到平均绝对偏差。

...

测试样例输入:[1,2,3,4]

均值是 2.5
每个数字的差值:1-2.5 是 1.5,绝对值 1.5;2-2.5 是 0.5,绝对值 0.5;3-2.5 是 0.5,绝对值 0.5;4-2.5 是 1.5。所以总和是 1.5+0.5+0.5+1.5 = 4.0?等等也许不是。等等 1.5+0.5+0.5+1.5 = 4.0。然后除以 4 得到 1.0。这与样例输出相符。所以代码对样例是有效的。

边界情况:比如所有数字都相同。比如 [5,5,5] 均值 5,差值 0。所以是 0.0。另一种情况比如 [0,0,1] 均值 0.5,差值 0.5、0.5,总和 1.0 /3= 0.333333... 也就是 0.3333333333。

是的,代码看起来是对的。
      

        def mean_absolute_deviation(numbers):
    if not numbers:
        return 0.0
    mean = sum(numbers) / len(numbers)
    total_diff = 0
    for num in numbers:
        total_diff += abs(num - mean)
    return total_diff / len(numbers)
      

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by HN AI
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗