移除85%权重后Gemma MoE仍可用,仅3.8B参数实现高效本地推理
I removed 85% of gemma's weights (and it is mostly fine)
针对端侧部署痛点,提供了一套完整的MoE转稠密模型剪枝与训练方案,包含具体的专家选择策略、训练目标设定及资源消耗数据,对做本地化优化的开发者极具参考价值。
I pruned Gemma 4 26B-A4B, an MoE model, down to 15% of its original size, and the model still does great on one narrow task. It gets 92% agreement with the original on a classification task. That’s close to how often the 12B agrees with the 26B on the same ticks, which is 90%. This isn’t a model for general tasks, and tasks that require knowledge suffer because the knowledge is just gone.
我将 Gemma 4 26B-A4B(一种 MoE 模型)剪枝至原始大小的 15%,该模型在单一狭窄任务上仍表现优异。在分类任务中,它与原始模型的 agreement(一致性)达到 92%。这与 12B 模型与 26B 模型在同一组样本上的一致性(90%)相近。这不是一个适用于通用任务的模型,需要知识支撑的任务表现会受损,因为相关知识已丢失。
It was made for my app that runs an on-device LLM 24/7, so that makes memory footprint and energy consumption extremely important. On my Mac it hits 79 tokens/s, which is roughly double the speed of the 12B, using 3.8 GB of memory (roughly half).
它是为我的一款应用设计的,该应用在设备端全天候运行 LLM,因此内存占用和能耗至关重要。在我的 Mac 上,它达到了 79 tokens/s 的速度,大约是 12B 模型速度的两倍,同时仅使用 3.8 GB 内存(约为后者的一半)。
I selected a set of 8 experts per layer and used them for everything. Since the model selects 8 experts per token by default and there are only 8, the router no longer chooses which experts to use, and the model becomes dense: 3.81B parameters, 2.75 GB at Q4_K_M.
我为每层选择了一组 8 个专家,并将它们用于所有计算。由于模型默认每个 token 选择 8 个专家,而总共只有 8 个专家,路由器不再决定使用哪些专家,模型变得稠密:参数量为 3.81B,在 Q4_K_M 量化下占用 2.75 GB。
What I want is for each block to do the same computation and produce the same result, given the same input. With block-local training, I’m not training on the answer. I’m training on the thought process. I’m saying, do the same thinking, not get the same answer.
我希望每个 block 在给定相同输入时执行相同的计算并产生相同的结果。通过 block-local training(块内局部训练),我并非针对答案进行训练,而是针对思维过程进行训练。我的意思是让模型进行相同的思考,而非仅仅得到相同的答案。
This is all trained off my own data. The method is efficient enough that it could be trained on a user’s own device, on their own data, in about 5 GB of memory, to mitigate issues stemming from deployment having different data than was in the training dataset. I haven’t tested that on a real user’s device yet. If you are curious about why I decided that fine tuning was a bad idea or how I designed this, take a look at the post I wrote going into the details of how I made this and why I felt this route was right for my application.
这一切均基于我自己的数据进行训练。该方法效率足够高,可以在用户自己的设备上、使用其自身数据、仅需约 5 GB 内存进行训练,从而缓解因部署环境与训练数据集数据不同所引发的问题。我尚未在实际用户设备上测试过这一点。如果你好奇我为何认为微调是个坏主意,或者我是如何设计这一方案的,可以查看我撰写的详细博文,其中介绍了我是如何制作此模型以及为何认为这条路径适合我的应用场景。
This is the first time posting publicly like this. I would love feedback or thoughts, and to anyone who knows of better methods for choosing which experts to keep, please lmk.
这是我首次以这种方式公开发布内容。我非常希望获得反馈或意见,任何知道如何选择保留专家更优方法的人,请告诉我。
Post: https://tolby.app/blog/frankensteining-gemmas-experts
原文链接:https://tolby.app/blog/frankensteining-gemmas-experts
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力