在 RTX 3090 上对 Qwen 3.6 35B MoE (3B 激活) 进行基准测试
背景与摘要
本文记录了作者在拥有 24GB 显存的 NVIDIA RTX 3090 显卡上运行 Qwen 3.6 35B 混合专家 (MoE) 模型的深入测试过程。面对 22GB 的显存占用(在 4-bit 量化下),作者利用 llama.cpp 工具测试了不同的后端 (CUDA vs Vulkan) 和 CPU 卸载 (-ncmoe) 参数。测试发现,使用源码编译的 CUDA 版本性能远超 Vulkan,并且通过将 10-12 层网络卸载到 CPU,可以在保持实用推理速度(如生成速度约 140 tokens/s)的同时,利用模型高达 262k 的全量上下文窗口。
Summary
本文详细介绍了一次在 NVIDIA RTX 3090 (24GB VRAM) 上运行 Qwen 3.6 35B 混合专家模型 (MoE) 的深入探索。通过利用 llama.cpp 并实验 CPU 卸载 (-ncmoe),我探索了上下文窗口大小和推理速度之间的权衡。主要发现包括:
* CUDA 对比 Vulkan: 在支持 CUDA 的情况下编译 llama.cpp,其性能显著优于默认的 Vulkan 构建,提供了更高的吞吐量和更大的上下文窗口。
* “最佳平衡点”: 将 10–12 层卸载到 CPU 可以让模型利用其完整的 262k 上下文窗口,同时保持可用的速度。
* 性能: 在 CUDA 上,当全量由 GPU 处理时,我实现了约 140 token/秒的生成速度和约 3,300 token/秒的提示词处理速度;而当卸载层以达到完整上下文时,速度则降至约 85 token/秒。
This post details a deep dive into running the Qwen 3.6 35B Mixture-of-Experts (MoE) model on an NVIDIA RTX 3090 (24GB VRAM). By leveraging
llama.cppand experimenting with CPU offloading (-ncmoe), I explored the trade-offs between context window size and inference speed. Key findings include: * CUDA vs. Vulkan: Compilingllama.cppwith CUDA support significantly outperformed the default Vulkan build, providing higher throughput and larger context windows. * The "Sweet Spot": Offloading 10–12 layers to the CPU allows the model to utilize its full 262k context window while maintaining usable speeds. * Performance: On CUDA, I achieved ~140 tokens/s for generation and ~3,300 tokens/s for prompt processing with full GPU offload, dropping to ~85 tokens/s when offloading layers to reach full context.
The Model: Qwen 3.6 35B-A3B
Qwen 3.6 35B-A3B 是一个混合专家模型,总计拥有 350 亿个参数,但每个 token 只有 30 亿个激活参数。值得注意的是,这些激活参数中有超过 10 亿个与嵌入层和输出头绑定在一起,只留下 20 亿个用于实际推理。因为该模型要求将全套权重保留在内存中(对于 4-bit 量化而言约 22GB),这挑战了 RTX 3090 24GB 显存的极限,因此必须仔细管理上下文窗口。
The Qwen 3.6 35B-A3B is a Mixture of Experts model with 35B total parameters but only 3B active parameters per token. Notably, over 1B of those active parameters are tied up in the embedding layer and output head, leaving only 2B for actual reasoning. Because the model requires keeping the full weight set in memory (approx. 22GB for 4-bit quantization), it pushes the 24GB VRAM limit of the RTX 3090, necessitating careful management of the context window.
Getting Started: Llama.cpp
我最初在使用 Arch Linux 默认的基于 Vulkan 的 llama.cpp 包时遇到了问题,具体表现为“设备不支持分割缓冲区 (device does not support split buffers)”错误。通过调整参数——具体地说是设置 -sm none(因为我使用的是单 GPU)并使用 -ngl all——我成功地使模型稳定运行。
I initially encountered issues with the Arch Linux default Vulkan-based
llama.cpppackage, specifically "device does not support split buffers" errors. By adjusting parameters—specifically setting-sm none(since I am using a single GPU) and using-ngl all—I was able to stabilize the model.
Benchmarking Methodology
为了获取准确的数据,我使用 llama-server 自动化了基准测试过程。我测试了不同程度的 CPU 卸载 (-ncmoe),以观察在性能出现不可接受的下降之前,有多少层可以转移到系统 RAM 中。我使用了一个基于“莱姆测试 (Lem Test)”——一项极具挑战性的创意写作任务——的提示词,以确保模型必须执行大量的计算。
To get accurate data, I automated the benchmarking process using
llama-server. I tested varying levels of CPU offloading (-ncmoe) to see how many layers could be moved to system RAM before performance degraded unacceptably. I used a prompt based on the "Lem Test"—a challenging creative writing task—to ensure the model had to perform significant computation.
The Results
Context Window Scaling
将层卸载到 CPU 是为了给上下文窗口回收显存 (VRAM) 的主要机制。
Offloading layers to the CPU is the primary mechanism to reclaim VRAM for the context window. * Vulkan: 需要卸载 12 层才能达到完整的 262,144 上下文长度。 * Vulkan: Required 12 layers offloaded to reach the full 262,144 context length. * CUDA: 仅需卸载 10 层即可达到相同容量。 * CUDA: Required only 10 layers offloaded to reach the same capacity.
Throughput Comparison
在所有指标上,CUDA 始终优于 Vulkan:
CUDA consistently outperformed Vulkan across all metrics:
| Metric | Vulkan (All GPU) | CUDA (All GPU) |
|---|---|---|
| Prompt Processing | ~2,787 tok/s | ~3,360 tok/s |
| Generation Speed | ~122 tok/s | ~140 tok/s |
注:为了达到完整上下文而卸载 12 层时,CUDA 维持在约 85 tok/s,而 Vulkan 则降至约 66 tok/s。
Note: When offloading 12 layers to reach full context, CUDA maintained ~85 tok/s, while Vulkan dropped to ~66 tok/s.
Conclusion
在 24GB 显卡上运行 35B 的 MoE 模型是一种平衡的艺术。虽然 RTX 3090 受到其显存的限制,但通过 llama.cpp 将 FFN 层卸载到 CPU 的能力,使得运行具有巨大上下文窗口的高参数模型变得完全可行。对于使用 NVIDIA 硬件的用户,强烈建议使用带有 CUDA 支持的源代码编译,而不是使用通用的 Vulkan 版本,以此来最大化速度和上下文容量。
Running a 35B MoE model on a 24GB card is a balancing act. While the RTX 3090 is constrained by its VRAM, the ability to offload FFN layers to the CPU via
llama.cppmakes it entirely viable to run high-parameter models with massive context windows. For users on NVIDIA hardware, compiling from source with CUDA support is highly recommended over using generic Vulkan builds to maximize both speed and context capacity.
Appendix: The Lem Test
由 Ethan Mollick 推广的“莱姆测试”,要求 LLM 写一首关于理发的六行诗,其中每个单词都必须以字母“S”开头,同时保持悲惨、高尚的基调。
The "Lem Test," popularized by Ethan Mollick, challenges an LLM to write a six-line poem about a haircut where every word begins with the letter "S," while maintaining a tragic, lofty tone.
虽然这个 35B 的 Qwen 模型很难同时保持完美的押韵和“S”的限制,但对于一个仅有 20 亿活跃“推理”参数的模型来说,它生成的叙述却出奇地连贯。对于模型推理能力以及在高 token 计数生成期间的硬件吞吐量来说,这是一个极佳的压力测试。
While the 35B Qwen model struggled to maintain perfect rhyme and the "S" constraint simultaneously, it produced surprisingly coherent narratives for a model with only 2B active "reasoning" parameters. It serves as an excellent stress test for both the model's reasoning capabilities and the hardware's throughput during high-token-count generation.