# Fewer active experts in Qwen3.6-35B-A3B (MLX, M3 Max): speed vs accuracy A common r/LocalLLaMA tip says that lowering `num_experts_per_tok` on a MoE gives a nearly free speedup. This experiment tests that claim on `mlx-community/Qwen3.6-35B-A3B-4bit` (commit `38740b847e4cb78f352aba30aa41c76e08e6eb46`) at top-k = 8 (the default), 6, 4 and 2. ## What it measures (per k) - Decode tok/s (median, min–max of 5) and prefill tok/s (median of 5). Setup: a 512-token wikitext prompt, 256 greedy tokens, 1 warm-up, configs interleaved in rotating order. - Speedup vs k=8, and peak unified memory (`mx.get_peak_memory`, reset before each run). - wikitext-2-raw test perplexity: first 32,768 tokens, 16 non-overlapping 2048-token windows, the same windows for every k. - GSM8K exact match on 150 test questions (fixed sample, `random.Random(0)`). Setup: 0-shot, chat template with `enable_thinking=False`, greedy, max 384 new tokens. Also a paired bootstrap 95% CI of the difference vs k=8, plus counts of truncated and unparseable answers. - Wall-clock per config and `pmset -g therm` before, during and after. ## How the change is made mlx_lm 0.31.3 routes through `Qwen3NextSparseMoeBlock`, which reads `self.top_k` on every forward pass. The steps are: a softmax over all 256 router logits, then top-k via `argpartition`, then the k probabilities are divided by their sum (`norm_topk_prob=True`, the default; the config does not override it). The shared expert stays on (sigmoid-gated). `bench.py` sets `layer.mlp.top_k` on all 40 layers at runtime, so the model loads only once. The verify phase checks two things: 1. It wraps `SwitchGLU.__call__` and asserts that the expert-index tensor has width k and k distinct experts per token in every layer. 2. It asserts that k=8, after toggling, reproduces the unmodified model's first 48 greedy tokens exactly. Results go to `out/verify.json`. ## Reproduce ```zsh ./run.sh # full run, offline, roughly 15–30 min on M3 Max (model already in the HF cache) ./run.sh --quick # plumbing check: 1 rep, 2 PPL windows, 8 GSM8K questions; results.json is marked QUICK ``` Uses `/opt/homebrew/Caskroom/miniconda/base/bin/python` (mlx 0.31.2, mlx-lm 0.31.3, numpy 2.4.2, pyarrow 24.0.0, transformers 5.12.1, Python 3.13.5). The datasets are vendored in `data/` as the original HF parquet files: `Salesforce/wikitext` wikitext-2-raw-v1 test and `openai/gsm8k` main test. The model must already be in `~/.cache/huggingface`. Outputs: - `results.json`: every number the post cites. - `results_table.md` - `speedup_vs_accuracy.svg` - `out/speed.jsonl`, `out/ppl.jsonl`, `out/gsm8k_k{8,6,4,2}.jsonl` (raw model outputs) - `out/verify.json`, `out/meta.json` (versions, thermal logs), `out/bench.log` Run on mains power with other apps closed. `out/power.txt` records the power source. ## Hardware Apple M3 Max (the exact chip and RAM are recorded in `results.json` → `environment`), macOS 27 / Darwin 27. ## Caveats - One model, one 4-bit quantization, one runtime (MLX), one machine. - Only the model's own renormalization was tested (top-k probabilities rescaled to sum to 1). - 150 GSM8K questions is a small sample. Read the CIs: if a CI includes 0, the difference is noise. - Accuracy runs use thinking off, greedy decoding and max 384 tokens. Absolute GSM8K numbers are therefore not comparable to the model card; only the differences between k values are meaningful. - GSM8K generation is batched (BatchGenerator, batch 32) to fit the time budget. All speed numbers come from the separate single-stream phase. - Answer extraction uses one rule for every k: the last number inside `\boxed{}` if there is one, otherwise the last number in the output. - The speed prompt is raw wikitext text with no chat template. Decode speed doesn't depend on the prompt content.