00:00 固定分词的作用与局限
词元让模型不必逐字处理,也无需为每个罕见词单独建立表示;BPE 通过反复合并训练数据中常共同出现的字符序列构造词表。但共现不等于意义:例如 New York 可能被固定拆成两个词元,即使模型后来学到它们指同一座城市,也无法在训练后调整边界。拆分还会增加 Transformer 处理的位置和生成步骤,累积到大量文本时可能造成额外计算。
bycloud · 22:13
You might already know that LLMs don't actually process words directly, but instead on something called tokens. The amazing thing about processing tokens is that we can compress multiple characters into a single unit. This gives us a middle ground between processing every individual letter and treating every word as its own token, especially since some words can be extremely rare or long. Not only that, we can restrict the vocabulary of tokens to a fixed size, so the model doesn't need to maintain a separate representation for every possible word, as you can just combine the tokens together to create the rare words. And this is essentially why almost every modern LLM relies on tokenization, because it reduces the amount of computation needed to process text, while still allowing the model to represent words it has never seen before. However, there has always been a tiny problem with this tokenization algorithm. Most modern LLMs use something called BPE, short for byte pair encoding, which essentially builds a vocabulary by repeatedly merging sequences of characters that frequently appear together in training data, all the way up to the vocabulary limit. But the problem is that how frequently. characters appear together doesn't necessarily reflect their meaning. For example, New York refers to a single city, but a tokenizer might split it into two separate tokens, even though treating the entire phrase as one unit could be more useful in certain contexts. And what's worse is that these boundaries are fixed before training begins. So even if the model later learns how closely related the two tokens new and York are, it cannot adjust how the text is divided based on their meaning or context. So when the model processes New York, it has to process new and York as two separate positions in the transformer, even if it already knows they refer to a single city. And when generating text, it also needs a separate decoding step to produce each token, which means there could be some inefficiency when attending to two tokens at once rather than one, and you'll be wasting compute generating two tokens just for a rare word that only appears together. While one extra token might seem insignificant, imagine this happening across billions of words, especially with common terms that get split into many smaller fragments. So what if instead of relying on these fixed. boundaries, we could let the model decide how to group information based on what it has learned during training. And that's exactly what today's paper, HNet, is trying to achieve. Not only that, it has some new research updates that might blow your mind. But before I dive into it, whether models read tokens or raw bytes, one thing doesn't change. The more context they carry, the more compute it takes to serve them, and AI agents carry a lot of context, which brings us to today's sponsor, Verda, a full-stack AI cloud. With Verda Inference, you get frontier open-weight models through a single API with performance engineered for long-running agents. Verda runs everything underneath, from the GPUs to the software serving the models. Verda recently launched Verda Inference as one of Moonshot AI's launch partners, with Kimi K3.1 Pro, Moonshot's most capable open-weight model, available from day one. And when Moonshot checked every provider serving the model, Verda was the only one to match or beat Moonshot's own results on every test. And here's the part that matters for agents. So when an agent works on a task, it keeps sending its growing conversation history back to the model. and processing all that context again every time is slow and expensive. Verda Inference keeps that context in a shared cache and reuses it instead of processing it again. In Verda's testing, about 99% of the context an agent had already sent was served straight from cache with the first tokens arriving in around 150 milliseconds as the context grew past 25,000 tokens. And when long sessions of around a million tokens come back, Verda Inference got the first token up to 10 times faster than processing them from scratch. Verda Inference is also OpenAI compatible. If you're already using tools like Codex, OpenCode, or the OpenAI SDKs, you can switch by changing the base URL, the API key, and the model. To get started, enable Kimi K3.1 Pro in the Verda console, create your API key, connect your application or agent, and make your first call. So check out Verda Inference now through the link down in the description with the code BYCLOUD75 to get 75% off your first top-up. And thank you Virda for sponsoring this video.
你可能已经知道,大语言模型并不会直接处理单词,而是处理一种叫作 token(词元)的东西。 处理词元的妙处在于,我们可以把多个字符压缩成一个单元。 这让我们在逐个处理字母和把每个单词都当作一个词元之间找到了折中方案,尤其是有些词可能极其罕见或很长。 不仅如此,我们还可以把词元词汇表限制在固定大小,这样模型就不必为每个可能出现的单词都维护独立表示,因为只要把词元组合起来,就能构成罕见词。 这基本上就是几乎所有现代大语言模型都依赖分词的原因:它减少了处理文本所需的计算量,同时仍能让模型表示以前从未见过的词。 不过,这种分词算法一直有个小小的问题。 大多数现代大语言模型使用一种叫作 BPE 的方法,也就是字节对编码。它基本上通过反复合并训练数据中经常一起出现的字符序列来构建词汇表,直到达到词汇表上限。 但问题在于,字符出现的频率…… 并不一定能反映它们的含义。 例如,New York 指的是一座城市,但分词器可能会把它拆成两个独立的词元,尽管在某些语境下,把整个短语作为一个单元处理可能更有用。 更糟的是,这些边界在训练开始前就已经固定了。 因此,即使模型后来学会了词元 new 和 York 之间的密切联系,也无法根据它们的含义或语境来调整文本的切分方式。 所以,当模型处理 New York 时,即使它已经知道这两个词指的是同一座城市,也必须在 Transformer 中把 new 和 York 当作两个独立位置来处理。 生成文本时,它还需要分别对每个词元进行解码。这意味着,与其同时关注两个词元,不如关注一个词元可能更有效率;而且,生成一个只会一起出现的罕见词时,你还得耗费计算量生成两个词元。 多出一个词元看起来可能微不足道,但想想这种情况发生在数十亿个词上的情形,尤其是那些被拆成许多更小片段的常见术语。 那么,如果我们不依赖这些固定的…… 边界,而是让模型根据训练中学到的内容来决定如何分组信息,会怎么样? 这正是今天要介绍的论文 HNet 试图实现的目标。 不仅如此,它还有一些可能会让你大吃一惊的最新研究进展。 但在我深入介绍之前,无论模型读取的是词元还是原始字节,有一点始终不变。 它们携带的上下文越多,运行时所需的算力就越多,而 AI 智能体携带的上下文非常多。这就引出了今天的赞助商 Verda——一家提供全栈服务的 AI 云平台。 通过 Verda Inference,你可以通过一个 API 使用前沿的开放权重模型,其性能专为长时间运行的智能体而优化。 从 GPU 到模型服务软件,底层的一切都由 Verda 负责运行。 Verda 最近作为 Moonshot AI 的首发合作伙伴之一推出了 Verda Inference,从上线第一天起就提供 Moonshot 目前能力最强的开放权重模型 Kimi K3.1 Pro。 Moonshot 检查了所有提供该模型服务的供应商后发现,Verda 是唯一一家在每项测试中都达到或超过 Moonshot 自家结果的供应商。 而这才是对智能体至关重要的部分。 智能体执行任务时,会不断把逐渐变长的对话历史发送回模型。 每次都重新处理所有这些上下文,既慢又昂贵。 Verda Inference 会将这些上下文保存在共享缓存中,并在之后重复使用,而不是重新处理。 在 Verda 的测试中,智能体此前发送的上下文约有 99% 直接从缓存中提供;随着上下文增长到超过 25,000 个 token,首批 token 约在 150 毫秒内就能返回。 当约一百万个 token 的长会话再次被调用时,Verda Inference 返回首个 token 的速度最高可比从头处理快 10 倍。 Verda Inference 也兼容 OpenAI。 如果你已经在使用 Codex、OpenCode 或 OpenAI SDK 等工具,只需更改基础 URL、API 密钥和模型,就能切换过来。 要开始使用,请在 Verda 控制台中启用 Kimi K3.1 Pro,创建 API 密钥,连接你的应用或智能体,然后发出第一次调用。 现在就通过简介中的链接了解 Verda Inference,并使用代码 BYCLOUD75,为首次充值享受 75% 折扣。 也感谢 Virda 赞助本视频。
Anyways, HNet is not something new. The original research was published back in July 2025, but it's thanks to their latest scaling experiments that we're finally seeing just how practical this approach could be. Because this time, Cartesia, the company behind the research, managed to train a 3 billion parameter language model that reached the same average benchmark as this other model called SmallLM3, published by Hugging Face back in July 2025, but with around 10 times less training data. And the fact that it required 10 times less training data is what brought the idea of considering a new tokenization paradigm back into the picture. So, how does H-Net actually work? Well, instead of converting text into a sequence of predefined tokens, H-Net takes in the raw bytes directly. And they use a smaller network that learns how to group these bytes into larger chunks before passing them to the main transformer. But rather than grouping characters based on how frequently they appear together, the network learns where the boundaries between chunks should be based on the surrounding context. So the model could potentially learn to group the entire phrase into a single chunk when it's referring to the city New York rather than always. processing it as two separate tokens. But of course, it doesn't explicitly understand that New York is a city and therefore must become one chunk. Instead, it learns which groupings help it predict the text more accurately. And the important difference here is that this entire chunking process is trained together with the language model itself. So rather than deciding what the tokens should be before training, the model can gradually learn which characters belong together as it gets better at predicting the next byte. However, H-Net doesn't directly process every byte either.
总之,HNet 并不是什么新东西。 最初的研究早在 2025 年 7 月就已发表,但正是他们最近的扩展实验,让我们终于看到了这种方法究竟能有多实用。 这一次,开展这项研究的公司 Cartesia 成功训练了一个拥有 30 亿参数的语言模型,其平均基准测试成绩达到了另一个模型 SmallLM3 的水平。SmallLM3 由 Hugging Face 于 2025 年 7 月发布,而 Cartesia 的模型所用训练数据约少了 10 倍。 而训练数据需求少了 10 倍这一事实,让重新考虑一种新的 token 化范式再次成为可能。 那么,H-Net究竟是如何运作的? 它不会把文本转换成一串预定义的词元,而是直接接收原始字节。 它们还会使用一个较小的网络,学习如何将这些字节组合成更大的片段,再将其传递给主Transformer。 不过,这个网络并不是根据字符共同出现的频率来分组,而是根据上下文学习片段边界应当位于何处。 因此,当整个短语指的是纽约这座城市时,模型有可能学会将它组合成一个片段,而不是总是 把它作为两个独立的词元来处理。 当然,它并不会明确理解纽约是一座城市,所以必须合并成一个片段。 相反,它会学习哪些分组方式有助于更准确地预测文本。 这里重要的区别在于,整个分块过程是与语言模型本身一同训练的。 因此,模型不必在训练前就决定词元应该是什么;随着预测下一个字节的能力不断提升,它可以逐渐学会哪些字符应当归为一组。 不过,H-Net也不会直接处理每一个字节。
It learns to compress them through multiple stages. Each stage essentially groups smaller pieces of information into larger chunks. So the first stage might learn to combine bytes into character-like or word-like units, while the next stage groups them into even larger chunks. But the key idea is that these boundaries aren't fixed. The same word can actually be divided differently depending on its context, even within the same passage. For example, they tested this with a completely made-up word called Borvexilla. When EdgeNet first encounters this unfamiliar word, it splits it into several smaller chunks. But as the word repeatedly appears throughout the passage. the model gradually starts grouping it into fewer and larger chunks. And the interesting thing is that this happens during inference without updating any of the HNet's weights. Because when the word appears again, the previous occurrences are now part of the model's context, which changes how the model decides where to place its chunk boundaries. So HNet isn't learning a new chunking rule during inference, it's using what it already learned during training to dynamically adjust its chunking decisions based on the context. The same behavior also appears with repeating patterns. For example, when given a sequence of numbers containing recurring patterns, HNet can learn to group these recurring sequences together instead of processing every digit separately, which could be extremely beneficial for coding or doing math. But just because HNet can compress information more cleverly doesn't directly imply it's more efficient, because HNet still technically needs to process every individual byte through its smaller networks before passing the compressed representations into the main transformer.
它会通过多个阶段对字节进行压缩。 每个阶段本质上都会把较小的信息片段组合成更大的片段。 因此,第一阶段可能会学着把字节组合成类似字符或单词的单位,而下一阶段则会把它们组合成更大的片段。 但关键在于,这些边界并不是固定的。 同一个词实际上可以根据上下文以不同方式拆分,即使是在同一段文字中也是如此。 例如,他们用一个完全虚构的词来测试这一点,这个词叫作Borvexilla。 EdgeNet第一次遇到这个陌生词时,会把它拆成几个较小的片段。 但随着这个词在整段文字中反复出现, 模型会逐渐开始把它归为更少、更大的片段。 有趣的是,这一过程发生在推理期间,而且不会更新 HNet 的任何权重。 因为当这个词再次出现时,它之前出现的位置已经成为模型上下文的一部分,从而改变模型决定将块边界放在哪里的方式。 因此,HNet 并不是在推理期间学习新的分块规则,而是利用训练期间已经学到的内容,根据上下文动态调整分块决策。 重复模式也会呈现出同样的行为。 例如,给定一个包含重复模式的数字序列时,HNet 可以学会将这些重复序列归为一组,而不是逐个处理每个数字,这对编程或数学运算可能非常有益。 但 HNet 能更巧妙地压缩信息,并不意味着它就一定更高效,因为严格来说,HNet 仍然需要先通过较小的网络处理每个字节,然后才能将压缩后的表示传入主 Transformer。
And those smaller networks also require computation, creating additional overhead during both training and inference. So the question is what. Whether the savings from processing fewer positions in the main transformer can actually outweigh the additional computation needed to create and process these chunks. To find out, Cartesia took a standard transformer architecture and replaced its tokenization components with H-Net's learned chunking mechanism while keeping everything else the same. The only difference was whether the input was divided using predefined tokens or dynamically learned chunks. And surprisingly, H-Net consistently achieved lower validation loss across all the model sizes they tested. More specifically, they found that H-Net was 1.28 times more compute efficient than the BPE transformer, meaning that to reach the same validation loss, the conventional transformer would need 28% more training compute. And while this might not sound particularly impressive, what's interesting is that the difference becomes much larger when the models are evaluated on unfamiliar data. So after training, Cortesia evaluated both models on different datasets without updating their weights in order to see how well their learned knowledge transferred to other domains. And across these downstream evaluations, the conventional transformer. Transformer would need roughly twice as much training compute to reach the same prediction loss as HNet, and the results were even more obvious for programming languages, especially those that weren't included in the original training mixture. Across these unfamiliar programming languages, the conventional transformer would need a median of 3.1 times more training compute to match HNet's prediction loss, and for Prolog specifically, that number reached 5.37 times. So H-Net wasn't necessarily processing these unfamiliar languages faster during inference, instead it was achieving better prediction loss on them with substantially less training compute, which suggests that the way H-Net learns to group information could also help its knowledge transfer more effectively to unfamiliar data.
而这些较小的网络也需要计算,因此会在训练和推理期间带来额外开销。 所以问题是…… 在主 Transformer 中处理更少位置所节省的计算,能否抵消创建和处理这些块所需的额外计算。 为弄清楚这一点,Cartesia 采用了标准 Transformer 架构,并用 H-Net 的学习式分块机制替换了其中的分词组件,同时保持其他部分不变。 唯一的区别在于,输入是按照预定义的词元划分,还是按照动态学习出的块划分。 令人意外的是,H-Net 在他们测试的所有模型规模上,都始终取得了更低的验证损失。 更具体地说,他们发现 H-Net 的计算效率是 BPE Transformer 的 1.28 倍;也就是说,要达到相同的验证损失,传统 Transformer 需要多用 28% 的训练计算量。 这听起来或许不算特别惊人,但有趣的是,当模型在陌生数据上进行评估时,这种差距会大得多。 因此,训练结束后,Cortesia 在不同数据集上评估了两个模型,且不更新它们的权重,以了解它们学到的知识能否迁移到其他领域。 在这些下游评估中,传统 Transformer…… 要达到与 HNet 相同的预测损失,Transformer 大约需要两倍的训练计算量;而在编程语言上的结果更加明显,尤其是那些未纳入原始训练数据混合集的语言。 在这些陌生的编程语言上,传统 Transformer 要达到 HNet 的预测损失,中位数需要多用 3.1 倍的训练计算量;而对于 Prolog,这个数字更是达到了 5.37 倍。 因此,H-Net 并非一定能在推理期间更快地处理这些陌生语言;相反,它能以显著更少的训练计算量,在这些语言上取得更好的预测损失。这表明,H-Net 学习如何将信息分组的方式,也可能有助于它更有效地将知识迁移到陌生数据上。
However, this experiment so far is still quite restrictive. The HNet's compression ratio and main Transformer architecture are almost identical to the BPE baseline, so that we could tell how much of the improvement came from learned tokenization. But HNet still has a lot more potential as it can compress information across multiple stages, use different compression ratios, ratios and even optimize an LLM's architecture specifically for these learned chunks. And the reason multiple stages matter is that not all meaningful patterns exist at the same scale. For example, individual bytes might form a character, several characters might form a word, and multiple words might form an entire phrase. So instead of trying to learn all of these relationships in one compression step, HNet can gradually build larger representations from smaller ones. For instance, a compression ratio of four simply means that on average, four input positions are grouped into one. So if the first stage compresses the sequence by four times and the second stage compresses it by another two times, the main transformer now only needs to process roughly one position for every eight original bytes. But these values are actually average compression ratios. HNet doesn't always group exactly four bytes together. It can create smaller or larger chunks depending on the context. And this gives us another interesting trade-off. Compressing more aggressively means fewer positions for the main transformer to process, but it also puts more pressure on the smaller networks to preserve the useful information. So the goal isn't simply to compress everything as much as possible, but to find a balance between how much information is preserved and how much computation is saved. Which brings us to the next experiment. Since the ratio was set to match BPE earlier, what if the compression ratio was actually designed around the architecture and HNet's own compression capabilities? Well, this is where the juiciest result comes in. They trained a larger two-stage HNet with 3.67 billion parameters and compared it against Hugging Face's small LM3, a conventional transformer with around 3 billion parameters. And this time, the researchers targeted four times compression in the first stage, followed by another two times in the second stage. While they didn't clarify on how they arrived at this compression number other than suggesting it's based on prior work, which they didn't also link, the interesting part is still how HNet actually learns where to place these boundaries. So essentially, there's a small network that predicts where each chunk should end, and these decisions are trained together with the rest of the model to improve next byte prediction. There's also an additional training objective that encourages the model to. stay close to the target compression ratio without forcing every chunk to have the same length. They didn't exactly outline their latest architecture in detail either, but the trained model ended up averaging around 7.6 bytes per position processed by its main transformer, whereas small LM3's tokenizer averages around 4.5 bytes per token. So for the exact same piece of text, the HNet's main transformer now only needs to process around 40% fewer positions. Of course, this doesn't mean the entire model uses 40% less computation because HNet still has to spend compute on its smaller encoder, chunking, and decoder networks. In fact, these additional networks account for roughly 43% of HNet's total training computation compared with just 8% for the embedding and output layers of small LM3. So although the main transformer processes fewer positions, a large portion of those savings is spent on learning and reconstructing the compressed representations. And to make the comparison as fair as possible, Cartesia matched the two models to within 2% of the training flops per byte. So despite HNet processing. fewer positions in its main transformer, the additional computation from its smaller networks offset much of those savings, leaving both models with roughly the same training compute per byte.
不过,到目前为止,这项实验仍然有相当大的局限。 HNet 的压缩率和主体 Transformer 架构与 BPE 基线几乎完全相同,因此我们可以判断有多少改进来自学习式分词。 但 HNet 仍有更大的潜力,因为它可以跨多个阶段压缩信息,采用不同的压缩率,甚至专门针对这些学习得到的片段来优化 LLM 的架构。 多个阶段之所以重要,是因为并非所有有意义的模式都存在于同一个尺度上。 例如,单个字节可能组成一个字符,几个字符可能组成一个词,而多个词可能组成一个完整的短语。 因此,HNet 不必试图在一次压缩中学会所有这些关系,而是可以从较小的表示逐步构建出较大的表示。 例如,压缩率为 4,简单来说就是平均每 4 个输入位置会被合并为 1 个。 因此,如果第一阶段将序列压缩 4 倍,第二阶段再压缩 2 倍,那么主体 Transformer 现在只需处理大约每 8 个原始字节对应的 1 个位置。 不过,这些数值实际上是平均压缩率。 HNet 并不总是恰好把 4 个字节分为一组。 它可以根据上下文生成更小或更大的片段。 这也带来了另一个有意思的权衡。 压缩得越激进,主体 Transformer 需要处理的位置就越少,但这也会给较小的网络带来更大压力,要求它们保留有用信息。 所以,目标并不是尽可能压缩一切,而是在保留多少信息和节省多少计算之间找到平衡。 接下来就要说到下一个实验了。 既然之前的压缩率是为了匹配 BPE 而设定的,那么,如果压缩率是根据架构和 HNet 自身的压缩能力来设计的呢? 好,最令人振奋的结果就在这里。 他们训练了一个更大的两阶段 HNet,参数量为 3.67 billion,并将其与 Hugging Face 的小型 LM3 进行比较。后者是一个参数量约为 3 billion 的传统 Transformer。 这一次,研究人员的目标是让第一阶段压缩 4 倍,随后第二阶段再压缩 2 倍。 他们没有说明是如何得出这个压缩数值的,只是暗示它基于先前的工作,而他们也没有附上相关链接。不过,真正有意思的是 HNet 如何学会在什么位置设置这些边界。 本质上,有一个小型网络负责预测每个片段应该在哪里结束;这些决策会与模型的其余部分一同训练,以提升下一个字节的预测能力。 此外,还有一个额外的训练目标,鼓励模型…… 在不强迫每个文本块长度都相同的情况下,尽量贴近目标压缩比。 他们也没有详细说明最新架构的具体情况,但训练后的模型在其主 Transformer 处理的每个位置上,平均约对应 7.6 字节;而 SmallLM3 的分词器平均每个词元约对应 4.5 字节。 因此,对于完全相同的一段文本,HNet 的主 Transformer 现在只需处理约少 40% 的位置。 当然,这并不意味着整个模型的计算量减少了 40%,因为 HNet 仍需在较小的编码器、分块模块和解码器网络上消耗算力。 事实上,这些额外网络约占 HNet 总训练计算量的 43%;相比之下,SmallLM3 的嵌入层和输出层仅占 8%。 因此,尽管主 Transformer 处理的位置更少,但节省下来的计算量中有很大一部分又花在了学习和重建压缩后的表示上。 为了尽可能公平地进行比较,Cartesia 将两个模型每字节对应的训练浮点运算量控制在相差 2% 以内。 所以,尽管 HNet 处理的…… 主 Transformer 位置更少,但较小网络带来的额外计算抵消了大部分节省,使两个模型每字节的训练计算量大致相同。
Which raises the question, if HNet costs roughly the same to process the data, is there really a point in using it? Well, the surprising twist is HNet could actually learn more from the same amount of data. Since SmallLM3 was originally pre-trained on 11 trillion tokens, Cartesia also wanted to limit test how much training HNet would need to reach the same performance benchmark-wise as we were only matching compute previously. And to keep the comparison fair, they recreated SmallLM3's initial training data mixture, only excluding SmallLM3's later training stages. And across six selected benchmarks, HNet managed to reach SmallLM3's final average score after processing just around 1 trillion token equivalents of training data. That's pretty much 10 times less training data to reach the same average benchmark performance. So although they previously saw the models were matched to spending around the same compute per byte overall, Cartesia still found. that their compute allocation differed across the data categories. This might be thanks to how HNet compresses code more aggressively than BPE, meaning it could spend less compute on code and more on other data. So the idea of HNet consuming the same amount of computation to process the same amount of text, yet managed to reach the same average benchmark score after seeing 10 times less data, is a pretty crazy conclusion. This also implies that the improvement is more from making the computation itself more useful for learning instead of having a huge savings. But why does HNet need so much less training to reach the same benchmark performance?
这就引出了一个问题:如果 HNet 处理数据的成本大致相同,那使用它究竟有什么意义? 出人意料的是,HNet 实际上可能从相同数量的数据中学到更多。 由于 SmallLM3 最初使用了 11 万亿个词元进行预训练,Cartesia 也想测试 HNet 需要多少训练数据才能在基准测试中达到相同表现;此前他们只是在计算量上进行匹配。 为了保持比较公平,他们重现了 SmallLM3 初始训练所用的数据混合,只排除了 SmallLM3 后续的训练阶段。 在选定的六项基准测试中,HNet 仅处理了约相当于 1 万亿个词元的训练数据,就达到了 SmallLM3 的最终平均分数。 也就是说,要达到相同的基准测试平均表现,所需训练数据几乎少了 10 倍。 因此,尽管他们先前发现,整体而言两个模型每字节消耗的计算量大致相同,Cartesia 仍发现…… 它们在不同数据类别之间的计算量分配并不相同。 这或许是因为 HNet 对代码的压缩比 BPE 更激进,因此它可以减少在代码上的计算量,并将更多计算量用于其他数据。 所以,HNet 用相同的计算量处理相同数量的文本,却只看了少 10 倍的数据就达到了相同的基准测试平均分数——这个结论相当惊人。 这也意味着,提升更多来自让计算本身更有利于学习,而不是大幅节省计算量。 但为什么 HNet 只需少得多的训练,就能达到相同的基准测试表现?
How does that even make sense? Well, remember how H-Net was only 1.28 times more compute efficient on its own original validation distribution, but increased to around two times on downstream evaluations and even 3.1 times for unfamiliar programming languages. So it seems that the way HNet learns to represent information also affects how well that knowledge transfers to unfamiliar data, hence performing better on held out benchmarks. And to understand this behavior better, Cartesia wrote a second blog and. investigating why exactly this happens. Because as it turns out, two language models can achieve the exact same pre-training loss, yet perform very differently on downstream evaluation simply because of how their inputs were represented during training. But before explaining why, Cartesia separated two things that we usually think of as being closely related. The first is how efficiently a model learns to predict its original training distribution, and the second is how well that learning transfers to other distributions. When you separate these two cleanly, you can then build something called the loss-to-loss scaling law. Unlike conventional scaling laws, which measure how prediction loss improves with more training compute, loss-to-loss scaling laws measure how a model's loss on one distribution relates to its loss on another. And because pre-training loss is often used to predict how well a model will perform on downstream evaluations, if two models achieve the same validation loss, we might expect them to perform similarly on other datasets. But Cartesia found that this relationship can change depending on how the input is tokenized, which is pretty much unheard of. So they compared a. conventional BPE transformer against a pure byte-level transformer. And unlike HNet, this byte-level transformer doesn't learn to compress anything. It simply processes every individual byte through the main network. And as expected, this was much more expensive with BPE requiring around 7.2 times less training compute to reach the same validation loss. But here's the interesting part. When both models reached the exact same validation loss, the pure byte-level transformer actually performed better on downstream evaluations. In fact, the difference in their loss-to-loss scaling was equivalent to around 1.5 times more training compute for BPE. So even though BPE was much cheaper to train, its pre-training loss didn't translate into downstream performance as effectively, which suggests that the way we represent information isn't just affecting how quickly a model learns. It also affects how well that learning transfers to unfamiliar data. Not only that, Cartesia also found something even more interesting when they investigated how BPE tokenization actually works.
这怎么说得通? 还记得吗?H-Net 在它原本的验证数据分布上,计算效率只高出 1.28 倍;但在下游评估中,这一优势增至约 2 倍,在不熟悉的编程语言上甚至达到 3.1 倍。 因此,HNet 学习如何表示信息的方式,似乎也会影响这些知识迁移到陌生数据上的效果,从而让它在留出的基准测试中表现更好。 为了更深入地理解这种现象,Cartesia 又写了第二篇博客,并…… 调查这究竟为何发生。 事实证明,两个语言模型可以达到完全相同的预训练损失,却在下游评估中表现迥异,仅仅是因为它们在训练期间表示输入的方式不同。 但在解释原因之前,Cartesia 将我们通常认为密切相关的两件事区分开来。 第一,模型学习预测原始训练数据分布的效率;第二,这种学习迁移到其他数据分布的效果。 把这两者明确区分开后,就可以建立一种称为“损失到损失缩放定律”的东西。 传统缩放定律衡量的是预测损失如何随着训练计算量增加而改善;而损失到损失缩放定律衡量的是模型在一个数据分布上的损失与它在另一个数据分布上的损失有何关系。 由于预训练损失常被用来预测模型在下游评估中的表现,如果两个模型的验证损失相同,我们可能会认为它们在其他数据集上的表现也会相近。 但 Cartesia 发现,这种关系会因输入的分词方式而改变,这种情况几乎闻所未闻。 于是他们比较了一个…… 传统的 BPE Transformer 与一个纯字节级 Transformer。 与 HNet 不同,这个字节级 Transformer 不会学习压缩任何内容。 它只是通过主网络处理每一个单独的字节。 正如预期,这种做法的成本高得多:要达到相同的验证损失,BPE 所需的训练计算量约少 7.2 倍。 但有意思的地方来了。 当两个模型达到完全相同的验证损失时,纯字节级 Transformer 在下游评测中的表现其实更好。 事实上,它们损失随计算量变化的缩放差异,相当于 BPE 多用了约 1.5 倍的训练计算量。 所以,尽管 BPE 的训练成本低得多,它的预训练损失并没有同样有效地转化为下游表现,这说明信息的表示方式影响的不只是模型学习的速度。 它也会影响模型将所学迁移到陌生数据上的效果。 不仅如此,Cartesia 在研究 BPE 分词实际如何运作时,还发现了更有意思的事情。
So BPE doesn't just simply merge frequently occurring byte sequences. It also relies on something called. pre-tokenization. These are essentially manually designed rules that divide text into smaller pieces before BPE begins merging them, like preventing tokens from crossing word boundaries. So what happens if we remove these rules and let BPE learn its vocabulary directly from the raw data? Well, it actually becomes better at compression. Instead of averaging around 4.57 bytes per token, it now manages to compress 6.03 bytes into each token, which means the transformer has fewer tokens to process, so we should expect it to be more efficient, right? Well, surprisingly, no. Although the sequences became shorter, the resulting tokens weren't necessarily as useful for learning. In fact, despite processing fewer tokens, the model without pre-tokenization actually needed 1.5 times more compute to reach the same validation loss. On top of that, it also performed the worst on downstream evaluations, creating 1.3 times more compute in their loss-to-loss scaling laws. So how the information is grouped can be just as important as how much it's compressed. But there's this one tiny caveat that they had to clarify here. Some of the worst downstream results without pre-tokenization did actually come from the prompt boundary problem, which affects how tokenized models' probabilities are evaluated. But anyways, this is still why H-Net has its advantages. When Cartesia added HNet to the same loss-to-loss scaling experiments, they found HNet managed to match the downstream transfer efficiency of the pure byte-level transformer while retaining the computational savings of compressing the input. Compared with BPE, its loss-to-loss scaling was around 1.61 times more compute efficient, which means even when both models reached the same pre-training validation loss, HNet still. achieve better downstream prediction loss. So while H-Net was 1.28 times more compute efficient at reaching the same pre-training validation loss, the loss also translated into better downstream performance, compounding into roughly 2.06 times better compute efficiency in total, which is great as H-Net basically achieves both things we wanted, that is the computational savings from compressing text and the stronger downstream transfer of learning directly from bytes.
BPE 并不只是简单地合并频繁出现的字节序列。 它还依赖一种叫作……的机制。 预分词。 本质上,这些是人工设计的规则,会在 BPE 开始合并文本之前将文本划分成更小的片段,例如防止 token 跨越词语边界。 那么,如果移除这些规则,让 BPE 直接从原始数据中学习词汇表,会发生什么? 结果是,它的压缩效果确实会更好。 它不再是平均每个 token 压缩约 4.57 个字节,而是能把 6.03 个字节压缩进每个 token。这意味着 Transformer 需要处理的 token 更少,所以我们应该可以预期它会更高效,对吧? 然而,令人意外的是,并非如此。 虽然序列变短了,但生成的 token 未必同样有利于学习。 事实上,尽管处理的 token 更少,没有进行预分词的模型要达到相同的验证损失,实际需要多用 1.5 倍的计算量。 除此之外,它在下游评测中的表现也最差;按他们的损失缩放定律计算,所需计算量多了 1.3 倍。 所以,信息如何分组,可能与压缩程度同样重要。 不过,这里有一个小小的注意事项,他们需要澄清一下。 事实上,没有进行预分词时,部分最差的下游结果确实是由提示边界问题造成的;这个问题会影响对经过分词的模型的概率进行评估。 不过,无论如何,这仍然是 H-Net 具备优势的原因。 当 Cartesia 将 HNet 纳入相同的损失到损失缩放实验时,他们发现,HNet 在保留压缩输入所带来的计算节省的同时,也能达到与纯字节级 Transformer 相当的下游迁移效率。 与 BPE 相比,它在损失到损失缩放方面的计算效率约高 1.61 倍,这意味着即使两个模型达到了相同的预训练验证损失,HNet 仍然…… 取得更低的下游预测损失。 因此,虽然 H-Net 达到相同预训练验证损失所需的计算量少了 1.28 倍,但这也转化成了更好的下游表现,使总体计算效率提升约 2.06 倍。这很不错,因为 H-Net 基本实现了我们想要的两点:压缩文本带来的计算节省,以及直接从字节中学习所带来的更强下游迁移能力。
However, there's still one question left on the table, because technically we could use a separate model to determine the chunk boundaries without having to learn them alongside the language model. And if that works just as well, why bother training the entire chunking mechanism end to end in the first place? So in order to find out whether learning them end to end was actually necessary, Cartesia compared models with the same setup but only changing how their chunk boundaries were determined. And to test this, Cartesia compared H-Net against a similar architecture called BLT, short for Byte Latent Transformer, where instead of learning chunk boundaries together with the language model, this uses a separately trained byte-level model to estimate how a. uncertain the next byte is. And whenever that uncertainty crosses a certain threshold, it creates a new chunk. The idea is to have predictable sequences be grouped together while less predictable sequences might benefit from being processed in smaller pieces. So both approaches can dynamically compress raw bytes, but only H-Net learns its chunk boundaries directly from the language modeling objective. And it turns out that H-Net still performed better even when the researchers matched their architectures and compression ratios. Then they also tried a third approach where a smaller and separately pre-trained H-Net will determine the chunk boundaries. These boundaries could still adapt to the input context, but the chunking network itself was no longer updated alongside the larger model. But again, the fully end-to-end H-Net still performed the best. So the model does get benefits from learning which chunks are useful for its own predictions. And to sum up the improvements, compared to BPE, HNet requires around 1.28 times less training compute to reach the same validation loss, roughly two times less compute to reach the same downstream prediction loss, and in the larger small LM3 comparison, around 1010 times less training compute to reach the same average score across six selected benchmarks. And in the examples, they also demonstrated how much better H-Net is at dealing with text than BPE.
不过,还有一个问题悬而未决:严格来说,我们可以用一个独立模型来确定分块边界,而不必让它与语言模型一同学习。 如果这样做效果一样好,那又何必从一开始就端到端地训练整个分块机制呢? 为了弄清端到端学习分块边界是否确有必要,Cartesia 对比了设置相同的模型,只改变了确定分块边界的方式。 为此,Cartesia 将 H-Net 与一种类似的架构 BLT 进行了比较。BLT 是 Byte Latent Transformer(字节潜变量 Transformer)的简称。它不是让分块边界与语言模型一起学习,而是使用一个单独训练的字节级模型来估计下一个字节有多…… 不确定。 每当这种不确定性超过某个阈值时,模型就会创建一个新的块。 其思路是将可预测的序列归为一组,而将较难预测的序列切分成更小的片段来处理,或许会更有利。 因此,这两种方法都能动态压缩原始字节,但只有 H-Net 直接根据语言建模目标学习分块边界。 结果发现,即使研究人员使两者的架构和压缩率保持一致,H-Net 的表现仍然更好。 之后,他们还尝试了第三种方法:用一个较小、经过单独预训练的 H-Net 来确定分块边界。 这些边界仍然可以根据输入上下文进行调整,但分块网络本身不再与较大的模型一同更新。 但结果仍然是,完全端到端的 H-Net 表现最好。 因此,模型确实能从学习哪些分块有助于自身预测中获益。 总结一下这些改进:与 BPE 相比,HNet 达到相同验证损失所需的训练计算量减少了约 1.28 倍,达到相同下游预测损失所需的计算量减少了约 2 倍;在规模更大的小型 LM3 对比实验中,要达到六个选定基准测试的相同平均分数,训练计算量则减少了约 1010 倍。 在示例中,他们还展示了 H-Net 处理文本的能力比 BPE 强得多。
For instance, with DNA sequences, the model has to basically learn patterns from just four letters, A, C, G, T. And in protein coding regions, DNA is read in groups of three letters called codons. But outside this context, grouping everything into threes doesn't necessarily make sense. So H-Net learned to place its chunk boundaries along these three-letter patterns in protein coding regions while using different groupings elsewhere, all without being explicitly taught what a codon is. And in these DNA scaling experiments, H-Net achieved around six to seven times better compute efficiency than the conventional transformer baseline. They even showed some preliminary experiments applying the same idea to images, where the model could learn to group pixels into larger representations. So the bigger idea here is that H-Net isn't just another tokenizer. It's an architecture that learns how to organize raw information into useful chunks depending on the information. information that it's being presented.
例如,对于 DNA 序列,模型基本上必须仅从四个字母 A、C、G、T 中学习模式。 在蛋白质编码区域,DNA 会被分成每组三个字母来读取,这些组合称为密码子。 但在这种语境之外,把所有内容都分成三份就不一定说得通了。 因此,H-Net 学会了在蛋白质编码区域沿着这类三字母模式设置区块边界,而在其他区域采用不同的分组方式,整个过程无需明确教它什么是密码子。 在这些 DNA 扩展实验中,H-Net 的计算效率比传统的 Transformer 基线高出约六到七倍。 他们甚至展示了一些初步实验,将同样的想法应用于图像,模型能够学会把像素组合成更大的表示。 所以,这里更重要的想法是:H-Net 不只是另一种分词器。 它是一种架构,能够根据所接收的信息,学会如何将原始信息整理成有用的区块。 也就是它所接收的信息。
But of course, we're still a bit far from knowing whether this would replace tokenization in every LLM. There's also the question of inference efficiency, because reducing training compute doesn't automatically mean a model would generate text faster or be cheaper to serve. And we still don't know how these advantages will hold up after instruction tuning, reinforcement learning, or scaling to much larger models. But I am still really excited for the future of this idea as this could fundamentally change how data is represented and processed by AI models, since determining how we divide information into tokens before training even begins. Doesn't really make sense in the long run. But what do you think? Let me know down in the comments. And if you like today's topic about tokenization and want to learn more in depth about LLMs, my platform intuitiveai. academy might just be the perfect place for you to start. The platform focuses on helping you build an intuitive understanding of the key concepts behind LLMs from the fundamentals all the way to advanced topics like mixture of experts and model optimization. And rather than bombarding you with intimidating math, we want to make sure you fully understand the higher level logic first so the technical details actually make sense when you get to them. On top of that, we recently just had a content revamp where we went back and updated all the early fundamental materials to make the learning experience much better. We also recently added a new quiz system that tests your understanding after every chapter along with a weekly leaderboard to make learning a little more competitive. So if you're working with LLMs at work, transitioning into the field, or wanting to get into LLM research, check it out using the link down in the description and use our limited time code back to school for 50% off a yearly membership. And thank you guys for watching. A big shout out to Spent Mag. Chris Ledoux, Deegan, Robert Zaviasa, Puf and Inu, DX Research Group, Alex, Leo Halawani, and many others that support me through Patreon or YouTube. Follow me on Twitter if you haven't and I'll see you in the next one.
不过,我们离确定它能否取代所有大语言模型中的分词过程,显然还有一段距离。 推理效率也是一个问题,因为减少训练计算量,并不一定意味着模型生成文本会更快,或部署服务的成本会更低。 而且,我们仍不知道经过指令微调、强化学习,或扩展到规模大得多的模型后,这些优势能否保持。 不过,我仍然非常期待这个想法的未来,因为它可能从根本上改变 AI 模型表示和处理数据的方式;毕竟,在训练开始之前就决定如何把信息划分成词元,从长远来看并不太合理。 从长远来看,这样做并不太合理。 不过,你怎么看? 欢迎在评论区告诉我。 如果你喜欢今天关于分词的主题,还想更深入地了解大语言模型,那么我的平台 intuitiveai .academy 可能正是你入门的理想之选。 这个平台旨在帮助你直观地理解大语言模型背后的关键概念,从基础知识到专家混合模型、模型优化等进阶主题。 我们不会用令人望而生畏的数学内容轰炸你,而是希望先确保你充分理解更高层次的逻辑,这样等你学到技术细节时,就能真正理解它们。 此外,我们最近还全面更新了内容,重新修订了所有早期的基础材料,让学习体验变得更好。 我们最近还新增了一套测验系统,每学完一章都会测试你对内容的理解,还设有每周排行榜,让学习更有竞争性。 如果你在工作中使用 LLM、正准备转行进入这个领域,或者想从事 LLM 研究,可以点击下方简介中的链接了解详情,并使用限时优惠码 back to school,购买年会员可享受五折优惠。 感谢大家收看。 特别感谢 Spent Mag。 Chris Ledoux、Deegan、Robert Zaviasa、Puf and Inu、DX Research Group、Alex、Leo Halawani,以及其他通过 Patreon 或 YouTube 支持我的朋友们。 如果你还没关注我,欢迎到 Twitter 上关注我。我们下期再见。
现代语言模型通常用 BPE 将文本切成固定词元,既降低计算量,也能组合表示罕见词,但切分依据是字符共现而非语义,且边界在训练前已固定。H-Net 改为直接读取原始字节,并与语言模型端到端学习、按上下文动态分组。实验显示,在相近计算条件下,它在验证集和陌生领域上的预测效率更高;较大规模对比中,它以约十分之一训练数据达到相近基准平均分。其优势不只是压缩序列,也涉及知识迁移;但推理效率、指令微调和更大规模下的表现仍待验证。
词元让模型不必逐字处理,也无需为每个罕见词单独建立表示;BPE 通过反复合并训练数据中常共同出现的字符序列构造词表。但共现不等于意义:例如 New York 可能被固定拆成两个词元,即使模型后来学到它们指同一座城市,也无法在训练后调整边界。拆分还会增加 Transformer 处理的位置和生成步骤,累积到大量文本时可能造成额外计算。
H-Net 以原始字节作为输入,由较小网络学习将字节组合成较大的块,再交给主 Transformer;边界依据上下文学习,而不是预先固定。它不会预先理解 New York 是城市,而是通过共同训练,学习哪些分组有助于预测下一个字节。研究团队曾报告,一个 30 亿参数 H-Net 模型在平均基准上达到与 SmallLM3 相同的成绩,所用训练数据约少十倍,这使动态分块重新受到关注。
H-Net 通过多个阶段逐步把小片段压缩成更大的块,边界并非固定,同一个词也可随上下文改变切分方式。文稿举例称,虚构词 Borvexilla 初次出现时被分成多个小块,反复出现在上下文后则逐渐合并成更大的块;这一变化发生在推理阶段,不需要更新权重,因为先前出现的内容会影响后续分块。数字序列中的重复模式也可能被合并,有助于处理代码或数学内容。
在替换分词机制、保持其他架构相同的对照实验中,H-Net 在各个测试模型规模上均取得更低验证损失;达到同一验证损失时,传统 BPE Transformer 需要多约 28% 的训练计算量。差异在陌生数据上更明显:下游评估中传统模型约需两倍计算量,在训练混合中未出现过的编程语言上,中位数约为 3.1 倍,Prolog 达 5.37 倍。这体现的是较低训练计算下获得更好的预测损失,并不意味着 H-Net 推理必然更快。
初步对照实验的压缩率和主 Transformer 架构接近 BPE,后续方案则利用多阶段压缩和不同压缩率:平均每四个位置压成一个,再压缩两倍时,主 Transformer 约每八个原始字节处理一个位置。较大的两阶段 H-Net 模型平均每个主干位置对应约 7.6 字节,SmallLM3 的词元平均约 4.5 字节,因此主 Transformer 处理的位置少约 40%。但 H-Net 的编码、分块与解码网络约占训练计算的 43%,而 SmallLM3 的嵌入和输出层约占 8%;研究者把每字节训练 FLOPs 控制在相差 2% 以内后,两者总体训练计算仍大致相当。
在重建 SmallLM3 初始训练数据混合、排除其后续训练阶段的比较中,H-Net 在六个选定基准上的平均分,约用 1 万亿 token 等价训练数据就达到 SmallLM3 的最终平均成绩;文稿将其概括为约少用十倍训练数据。虽然每字节总体计算量大致匹配,计算在数据类别间的分配可能不同;一种解释是 H-Net 对代码压缩更激进,从而能把较少计算用于代码、更多用于其他数据。结果提示,优势可能更多来自让计算更有效地学习,而非单纯减少处理成本。
Cartesia 用 loss-to-loss scaling 描述模型在一种分布上的损失与另一种分布上的损失之间的关系,并发现输入表示方式会改变这种关系。纯字节模型逐字节处理,达到相同验证损失时约需比 BPE 多得多的计算;但在两者验证损失相同时,纯字节模型的下游表现更好,其损失迁移关系相当于 BPE 需要约 1.5 倍训练计算。换言之,预训练损失相同并不保证跨领域表现相同,输入如何表示也会影响知识迁移。
BPE 使用预切分规则将文本划成小片段,例如阻止词元跨越词边界。去掉这些规则后,平均压缩率从每词元约 4.57 字节提高到 6.03 字节,但模型达到相同验证损失反而需要多约 1.5 倍计算,下游表现也更差;这说明分组是否利于学习,不能只看压缩多少。加入 loss-to-loss 实验后,H-Net 相对 BPE 的迁移效率约高 1.61 倍;结合其达到相同预训练损失时约 1.28 倍的计算效率,综合效率约为 2.06 倍。
研究者比较了端到端训练的 H-Net 与 BLT:BLT 使用另一个字节级模型估计下一个字节的不确定性,超过阈值时便开始新块;还比较了由单独预训练的 H-Net 决定边界的方案。匹配架构和压缩率后,端到端 H-Net 表现仍更好,表明让分块机制直接服务于语言模型自身的预测目标有价值。文稿总结称,相比 BPE,H-Net 达到相同验证损失约需 1.28 倍更少计算,达到相同下游预测损失约需两倍更少计算;在较大模型的六项基准比较中,约用十分之一数据达到相近平均分。
在 DNA 例子中,编码区按三个字母组成的密码子读取,但其他区域未必适合一律按三字母分组。H-Net 能在编码区沿三字母模式设置边界、在其他位置采用不同分组,而无需明确获知密码子的概念;DNA 实验中相对传统 Transformer 的计算效率约高六至七倍。研究者还展示了初步图像实验,模型可学习把像素组织成更大的表示,说明这种架构尝试按信息内容组织原始数据,而不只是替换文本词元表。
H-Net 是否会取代所有 LLM 的传统分词仍未确定。减少训练计算不自动代表生成更快或服务更便宜;指令微调、强化学习以及扩展到更大模型后能否保持优势,也仍是开放问题。其长期意义在于让模型在训练中学习如何划分和组织信息,但现有结果尚不足以证明它适用于所有模型和场景。
04:26 H-Net 通过与语言模型共同训练、依据上下文动态组织原始字节,避免了分词边界必须在训练前固定的限制。
15:48 H-Net 的优势不只是减少主 Transformer 处理的位置,分组方式本身也可能提升模型在陌生数据上的知识迁移。
12:33 在文稿所述的六项基准比较中,H-Net 约用十分之一的训练数据达到 SmallLM3 相近的平均成绩。
18:04 端到端学习分块边界的 H-Net,在所述匹配对照中优于由其他模型单独估计边界的方案。
20:27 H-Net 的推理效率、服务成本以及在指令微调、强化学习和更大模型上的表现仍需进一步验证。