Views
No views yet
| Method | Description | Result |
|---|---|---|
| Expert-only repeat | Repeat only the MoE block (Router + Experts) | No effect or degradation |
| Full-block repeat | Repeat both Attention and MoE | Severe degradation (-20pp) |
| Attention-only repeat | Repeat only the Attention (dense) component | +13.3pp improvement |
Normal: x -> [Attention] -> [MoE: Router -> Top-4/32 Experts] -> out
Modified: x -> [Attention] -> [Attention (2nd pass)] -> [MoE: Router -> Top-4/32 Experts] -> outConfiguration Score Delta vs baseline
--------------------------------------------------
attn-L19-20 12/15 +13.3pp *** BEST
attn-L18-20 11/15 +6.7pp
baseline 10/15 0.0pp
attn-L18-19 10/15 0.0pp
attn-L17 9/15 -6.7pp
attn-L19-21 9/15 -6.7pp
attn-L16-20 8/15 -13.3pp
expert-repeat-L10-12 9/15 -6.7pp
full-block-L10-12 7/15 -20.0pp1from load_model import load_attn_repeat_model
2from mlx_lm import generate
3from mlx_lm.sample_utils import make_sampler
4
5model, tokenizer = load_attn_repeat_model()
6sampler = make_sampler(temp=0.0)
7response = generate(model, tokenizer, prompt="Your question here", max_tokens=512, sampler=sampler)
8print(response)1import mlx.nn as nn
2from mlx_lm import load, generate
3
4class AttentionRepeatWrapper(nn.Module):
5 def __init__(self, block):
6 super().__init__()
7 self.block = block
8
9 def __call__(self, x, mask, cache=None):
10 # First attention pass
11 residual = x
12 h = self.block.input_layernorm(x)
13 h = self.block.self_attn(h, mask, cache)
14 x = residual + h
15 # Second attention pass
16 residual = x
17 h = self.block.input_layernorm(x)
18 h = self.block.self_attn(h, mask, cache)
19 x = residual + h
20 # Single MoE pass
21 residual = x
22 h = self.block.post_attention_layernorm(x)
23 h = self.block.mlp(h)
24 x = residual + h
25 return x
26
27model, tokenizer = load("mlx-community/gpt-oss-20b-MXFP4-Q4")
28for idx in [19, 20]:
29 model.model.layers[idx] = AttentionRepeatWrapper(model.model.layers[idx])@misc{gpt-oss-20b-attn-repeat,
title={Attention Repeat for MoE Models: Applying RYS Method to GPT-OSS-20B},
author={shi3z},
year={2026},
note={Based on RYS method by David Ng and llm-circuit-finder by alainnothere}
}