Increasing num_experts_per_tok at inference time, is this supported?

#51
by Schestex - opened

Hi,

I'm interested in experimenting with the MoE routing configuration of Inkling 2 Mini.

The current configuration uses:

n_routed_experts = 128
num_experts_per_tok = 8
route_scale = 8.0

I'd like to investigate whether increasing the number of routed experts per token from 8 to 9 or even 10 could improve coding, reasoning and agentic task performance without modifying the original expert weights or performing additional training.

A few questions:

Is num_experts_per_tok intended to be configurable at inference time, or is the value of 8 fundamentally tied to the training process?

Would changing it to 9 or 10 in the model configuration be sufficient, or would modifications to the router or expert dispatch implementation be required?

How should route_scale and expert weight normalization be adjusted when increasing top-k?

Does the routing mechanism support this change across all three loop passes?

Have you experimented with higher top-k values internally? Are there any known quality or performance results?

My goal is to explore whether additional expert computation can improve model quality while keeping the original checkpoint weights unchanged.

Thanks for any technical insights!

Schestex changed discussion title from Increasing *num_experts_per_tok* at inference time, is this supported? to Increasing `num_experts_per_tok` at inference time, is this supported?
Schestex changed discussion title from Increasing `num_experts_per_tok` at inference time, is this supported? to Increasing num_experts_per_tok at inference time, is this supported?

Yes — in the transformers implementation this is a config change, not a code change, and the normalization takes care of itself.

The router (Inkling2LoopTopKRouter in modeling_inkling2_loop.py) reads the value once when the model is built: self.top_k = config.num_experts_per_tok, then selects with torch.topk over the router scores plus the correction bias. The same router class serves every layer, so setting num_experts_per_tok to 9 or 10 in the text_config of config.json before loading changes all of them together, loop passes included. One catch from the same code: since the value is read in the router's init, editing the config after the model has loaded won't take effect — it has to be set before construction.

On route_scale and normalization, nothing needs adjusting by hand. The selected experts' scores are renormalized over just the selected set (divided by their sum), then multiplied by route_scale (8.0 here). So at k=9 or 10 the mixture's total scale stays exactly where it was at k=8; each expert's individual share simply gets smaller. Raising route_scale to compensate would change the output magnitude instead — the shipped normalization is already the conservative choice.

What the code can't tell you is whether it helps. The router and its correction bias were trained at k=8, so the 9th- and 10th-ranked experts get admitted in combinations training never used, and expert compute per token rises by roughly a ninth per added expert. A clean first check: fix a small prompt set, run k=8, 9, and 10 with identical seeds and sampling settings, and compare the outputs side by side before trusting any benchmark delta.

The config values above are from this repo's config.json as served today (128 routed experts, k=8, route_scale 8.0). Hope it saves you some spelunking — curious what you find at 9 and 10.

Sign up or log in to comment