Expert Transplant: I Replaced Gemma 3 1B’s FFNs With Another Model’s MoE Experts on a MacBook Air
From the publisher’s feed, collected in the ZeroLabs newsroom.
From the dense feed-forward layer, to a frozen Mixture of Experts taken from another model, to the two projection matrices that map hidden states between them, across four training stagesFigure 1: Hybrid architecture. Gemma 3 1B keeps its embeddings, attention layers and norms. Each FFN slot runs either a frozen MobileMoE MoE block (orange) between two trained projections (green) or, in Stage 4, Gemma’s own FFN.The layers of a pretrained transformer are trained jointly. Each layer receives hidden states produced by the layers before it, in one basis and one width, and its weights are fitted to that input distribution. A sub-layer taken from a different model receives hidden states of a different width, in a different basis, from layers it was never trained with.Project J’AI tests one question: Can the Mixture-of-Experts (MoE) layers of one pretrained model replace the feed-forward networks (FFNs) of another, independently trained model, if the only trained parameters are two linear projections per layer? Both models stay frozen. W_in maps the host’s hidden state into the donor’s input space, and W_out maps the donor’s MoE output back into the host’s hidden-state space.Objective-> Remove the FFNs of one model, insert the MoE layers of a different model in their place, and measure whether the result still functions as a language model. The results indicate that it does: in each slot, the trained projections map the host’s hidden states into valid inputs for the donor’s router and experts, and map the expert outputs back into valid inputs for the host’s residual stream.This article covers four training stages on a 16 GB MacBook Air: Stages 1 and 2 in summary, the architecture and its equations with Stage 3, and a partial transplant with a smaller donor in Stage 4.Final numbers for Stage 4, the best run:20 of 26 of Gemma’s FFNs replaced by MobileMoE-S MoE blocks35.4M trained parameters, with both models frozen0.82 nats CE gap to Gemma, down from 13.09 with the FFNs deleted10 of 30 basic questions answered correctly (Gemma: 28)Every result here comes from the project’s run files. Model specifications and benchmark scores come from the model cards and papers in the references. Where the hybrid fails, the tables say so.The ExperimentA transformer layer has two sub-layers. Attention combines information across sequence positions: each position’s output is a softmax-weighted sum of value vectors from the current and preceding positions. The feed-forward network applies the same two-layer MLP to each position’s hidden state independently. FFN layers learn key-value associations: the first weight matrix computes key activations from patterns in the input hidden state, and the second weight matrix maps those activations to value vectors that are added to the residual stream. In dense models, much of the factual subject-to-attribute prediction is computed in these layers.A Mixture of Experts layer replaces the FFN with N smaller FFNs (experts) and a router. For each token, the router computes one score per expert from the hidden state, selects the top-k experts, and returns the score-weighted sum of their outputs. The router and the experts are trained jointly with the language-modeling loss, usually with a load-balancing term or bias. In MobileMoE, N = 60 and k = 4.Project J’AI follows from this. If a dense model’s FFN outputs can be replaced by the outputs of a stronger MoE model’s frozen expert layers, the host might gain some of the donor’s benchmark advantage without updating either model’s weights. This requires a map between the two models’ hidden-state spaces, and prior work indicates that such maps can be linear. A single trained linear layer can join two networks at a cut point. A trained linear projector maps a frozen vision encoder’s outputs into a frozen LLM’s input embedding space. And independently trained models seem to converge on similar representation geometry.What I hadn’t seen is the same construction at the sub-layer level, between two language models, with the donor’s experts frozen. Model stitching joins two networks at one point. Sparse upcycling initialises an MoE from a model’s own FFN weights. Here, the experts come from a different model and run inside the host, and the host’s residual stream passes through a transplanted block in every one of the 26 layers.I set out to test two hypotheses:H1, stitchability. With the host’s FFNs replaced by the donor’s MoE blocks, the hybrid recovers most of the cross-entropy the host loses when its FFNs are deleted.H2, healthy routing. Inside the hybrid, the donor’s frozen routers distribute tokens over many experts instead of concentrating them on a few, and, at positions where the two tokenizers align, select the same experts as the donor’s own routing more often than chance.The Host and the DonorI needed a pair that matched in depth (so layer i can borrow layer i), had a large knowledge gap in the donor’s favour, and could train on one laptop.Table 1: The host and the first donor. Both have 26 layers, but their widths, tokenizers and FFN designs all differ.The host is Gemma 3 1B (google/gemma-3-1b-pt) , a dense model trained on 2T tokens, with a GeGLU FFN (1,152 → 6,912 → 1,152) in each of its 26 layers. The donor for Stages 1 to 3 is MobileMoE-M-Base, a MoE from Meta: 2.8B parameters in total, 528M active per token, and 26 layers of width 1,024, each with 60 routed experts and one always-active shared expert. MobileMoE-M scores 54.7 on 5-shot MMLU by its model card, and the MobileMoE team's benchmark table puts Gemma 3 1B at 26.2. The experiment tests whether part of that difference transfers through the transplanted MoE blocks. Stage 4 uses a smaller model from the same family, MobileMoE-S-Base.Three differences between the models determine the design:Widths: Gemma’s hidden state is 1152 and MobileMoE-M’s is 1024, so each projection changes both the basis and the dimension.Tokenizers: Gemma uses a 262,144-token vocabulary and MobileMoE the 128,256-token Llama 3 vocabulary. The same text produces different token sequences, so any position-by-position comparison requires an alignment step.Data: Gemma’s training set was never released, so the training data is MobileMoE’s open pre-training mix (62% web, 11.6% math, 10% code, 10% knowledge, 6.4% science), streamed so that every token is read once.All runs use one machine: a MacBook Air M5 with 16 GB of unified memory, PyTorch on the Apple GPU (MPS), both models in bf16 and the projections in fp32. No cloud, no CUDA. GPU memory use per component: Gemma’s weights 2.0 GB, MobileMoE-M’s 26 MoE blocks 5.2 GB, the projections with their AdamW state 1.0 GB, and one end-to-end micro-step about 0.9 GB. Only MobileMoE’s pre-MoE norms, routers and experts are loaded onto the GPU.Before any long run, seven gating tests had to pass on the real models. With Gemma’s own FFN in the slot, the hybrid must reproduce Gemma’s outputs exactly. The extracted MoE block must reproduce MobileMoE’s own block output, only the projections may receive gradients, the chunked loss must match plain autograd, and aligned positions must cover the same characters in both tokenizers. A full training step with all 26 layers must also fit in GPU memory: it peaked at 10.9 GB, under the 11.84 GB that macOS allows the GPU. The tokenizers align on 90.2% of Gemma’s tokens.Measuring the HybridDeleting all 26 FFNs sends Gemma’s perplexity to about 5 million. Gap recovery places the hybrid between that floor (0) and the intact Gemma (1):Equation 1: Gap recovery. With the floor at about 5 million perplexity, the perplexity version saturates, so I report the loss-space version, GR_CE.GR_CE also saturates for weak hybrids, as the Stage 1 results show. The primary metrics are therefore the CE gap (the hybrid’s cross-entropy minus Gemma’s, in nats per token), the perplexity ratio and next-token accuracy. The CE gap and the perplexity ratio are the same quantity on two scales: ratio = e^gap, so a gap of ln 2 ≈ 0.69 nats is twice Gemma’s perplexity. All three are measured on three held-out sets: the validation mix (MobileMoE’s data, never trained on), WikiText-103 and C4, with 250k tokens per set in every final evaluation.For factual recall, a 30-question test computes the fact log-probability: the mean log-probability per token of the reference answer (“Paris”) after the reference sentence prefix (“The capital of France is”). Fact recovery places that value between “all FFNs deleted” (0%) and Gemma (100%). It changes before the greedy answers become correct.Routing has its own metric. For each layer, f_e is expert e’s share of the top-4 assignments, and the normalised entropy of that distribution measures how evenly the 60 experts are used:Equation 2: Routing health and agreement. A normalised entropy of 1 means all 60 experts receive equal load, and the 0.7 alarm corresponds to about 18 experts in effective use. Agreement J_t is the Jaccard overlap between the hybrid’s top-4 set and MobileMoE’s own at aligned positions, 0.039 by chance.Two further routing statistics are reported: dead experts, which receive under 0.1% of the routing slots, and the busiest expert’s share, which is 1/60 ~1.7% under uniform load.Table 2 lists the final evaluation of all four runs. The sections below describe each run.Table 2: All four runs at a glance. Stages 1 to 3 are one architecture trained for longer, and Stage 4 is a different one.Stages 1 and 2 in ShortStages 1 to 3 replace all 26 of Gemma’s FFNs, with Gemma layer i using MobileMoE-M layer i. Both models have 26 layers, so the layer map is the identity. Training has three steps, with equations in the Stage 3 section. The first is a ridge-regression initialisation of both projections. The second is local matching, which trains each layer to reproduce the output of the FFN it replaced. The third is end-to-end training on next-token cross-entropy, with a KL term toward the original Gemma’s output distribution.Stage 1: One Million TokensStage 1 was a pipeline test: 983,040 tokens, about three hours in total, with a peak of 10.8 GB of GPU memory. Its purpose was to verify that the pipeline runs on the laptop, that the losses decrease, and that no NaN values appear.Ridge initialisation, before any gradient step, already reproduced most of the FFN output. The full chain W_in → MoE block → W_out reproduced Gemma’s FFN output with a mean validation NMSE of 0.30, so the average layer recovered about 70% of its FFN’s output energy.Local matching then ran for 30 steps and did not reduce the loss (0.313 → 0.316). Each layer was fitted independently, so the per-layer errors compound over 26 layers in sequence: after local matching, the hybrid’s perplexity was 1,562, 154 times Gemma’s, with 8% next-token accuracy.End-to-end training produced the first working hybrid. In 45 steps (0.74M tokens, 119 tokens per second), the training cross-entropy fell from 6.85 to 3.93 and the KL to Gemma from 4.50 to 1.94. In the final evaluation, perplexity was 71.3 on the validation mix (6.95 × Gemma’s), 144.6 on WikiText-103 (12.2 ×) and 129.1 on C4 (8.0 ×), with next-token accuracy at 31.0% against Gemma’s 52.6% on the mix. GR_CE on the mix was 0.852.That GR_CE already exceeded the 0.5 threshold I had set for H1. This is the first finding of the experiment: with the deleted-FFN floor 13.09 nats above Gemma (about 5 million perplexity), almost any functioning language model scores high on GR_CE. The Stage 1 hybrid generated grammatical English that degenerated into repeated sequences: “The capital of France is the first to the world. The world is the first to the world.” On the question test, 11 of 30 replies copied a few-shot example or the question. The model reproduced the answer template and copied tokens from its context, and produced no correct facts.Stage 2: Five Million TokensSince local matching hadn’t helped, I dropped it. The ridge initialisation depends only on the layers and the calibration text, so Stage 2 reused Stage 1’s and trained end to end only. It ran 305 steps of 16,384 tokens (4,997,120 in total) at 131 tokens per second, with a peak memory of 9.8 GB, in about 5 hours.Table 3: Stage 2’s final evaluation, with Stage 1 → Stage 2 for every hybrid number. 250k held-out tokens per set.Every 50 steps, the run measured perplexity and accuracy on 100k held-out tokens. Each check was lower than the previous one, by a decreasing amount: 64.4, 50.3, 42.4, 38.1, 36.1, 34.7, then 34.0 in the final evaluation, 3.31 × Gemma’s. The CE gap decreased by 38% on the validation mix (1.94 → 1.20 nats) and by 28% on WikiText-103 (2.50 → 1.79) and C4 (2.08 → 1.49). The gap is largest on WikiText-103, consistent with distribution shift: the projections were trained on MobileMoE’s mix, and WikiText-103 differs from it.Routing entropy stayed above the alarm. Dead experts halved (91 → 45 of 1,560, with 30 of the remaining 45 in layers 0 to 4), and the mean normalised entropy over the 26 layers rose from 0.940 to 0.959. The lowest-entropy layer was layer 1, at 0.829, where the busiest expert received 14% of the routing slots against a uniform 1.7%.On the 30 questions, the reference answer’s log-probability increased for 29 of them. The mean fact log-probability rose from −5.33 to −3.18 per token (Gemma: −0.23, all FFNs deleted: −14.81), so fact recovery went from 65% to 80%, and no reply copied an example or the question in full. One reply was correct. The incorrect replies show the failure mode: “The capital of France is France.” “Water freezes at 100 degrees Celsius.” “A triangle has two sides.” Each reply follows the answer template and has the correct answer type (location, temperature, count), with an incorrect value that is often a token copied from the question.Two findings follow from Stages 1 and 2. First, next-token prediction on running text recovers faster than factual recall: at 3.31 × Gemma’s perplexity, the hybrid answers 1 of 30 questions. Gemma’s attention layers are unchanged, so in-context operations still work: copying tokens from the prompt, following the few-shot template and predicting the answer type. The subject-to-attribute mapping, which dense models compute mainly in FFN layers, is not recovered. Second, the CE gap decreases slowly with tokens, roughly as tokens^−0.23, which predicts a perplexity near 24 at 20M tokens. Stage 3 tests that prediction.Stage 3: Architecture, Math and Twenty Million TokensStages 1 to 3 share one architecture. This section derives it from the forward pass to a single expert, then the training objective and the Stage 3 run.Figure 2: The hybrid of Stages 1 to 3, end to end. Gemma 3 1B keeps its embeddings, attention, norms and output head. In all 26 layers, its FFN is replaced by MobileMoE-M’s MoE block between two trainable projections (green).The forward pass is Gemma’s: token embeddings scaled by √1,152, 26 hybrid layers, then Gemma’s final RMSNorm and tied output head (the transposed embedding matrix), which produces logits over 262,144 tokens. Only the FFN slot inside each layer changes.One Transplanted LayerIn Gemma 3, each sub-layer is preceded and followed by an RMSNorm, with a residual connection around both. Before surgery, one decoder layer computes:Equation 3: Gemma’s decoder layer. Attention updates the residual stream X to h, and the FFN slot, between the pre-FFN norm N_A and the post-FFN norm P_A, adds its output on top.N_in and P_att are the norms around attention, and N_A and P_A the norms around the FFN. The FFN is a GeGLU, 1,152 → 6,912 → 1,152, with 3 × 1,152 × 6,912 = 23.9M parameters per layer. The transplant keeps N_A, P_A and the residual connection, and replaces only FFN_A.Figure 3: One transplanted layer. Gemma’s FFN (grey, dashed) leaves the forward pass. Its slot now holds W_in, MobileMoE’s norm and MoE block (orange, frozen) and W_out (green, trainable).Equation 4: The transplanted layer. h_t is Gemma’s residual stream after attention, and x_t = N_A(h_t) is what enters the FFN slot.We can read Equation 4 from the inside out. W_in (1,024 × 1,152) translates Gemma’s normalised state into MobileMoE’s coordinates. N_B is MobileMoE’s own pre-MoE RMSNorm. MoE_B is MobileMoE’s router, its 60 routed experts and its shared expert, all frozen. W_out (1,152 × 1,024) translates the result back, and Gemma’s post-FFN norm P_A and residual connection take it from there.Everything outside the slot carries a Gemma-shaped tensor, so Gemma’s attention and output head never notice the change, except through the values they receive. W_in and W_out are two independent matrices. W_out isn’t the transpose of W_in, because the way into the donor’s space and the way back out are different problems.One detail shapes everything after it. Each projection is followed by an RMSNorm (N_B after W_in, P_A after W_out), and an RMSNorm throws away the length of its input:Equation 5: Scaling the input of an RMSNorm by α changes nothing, so only the direction of each projection’s output reaches the next stage.So each projection only has to get the direction right, which is one reason I expected a straight line to be enough.In code, the surgery is one module and one loop, shortened here from the repo’s ReplaceFFN. The wrapper keeps Gemma's original FFN next to the frozen MoE block and the two trainable projections, and a single mode switch decides what the slot computes:class ReplaceFFN(nn.Module): """The FFN slot of one Gemma layer after surgery: W_out · MoE_B(N_B(W_in · x))."""def __init__(self, ffn_a, moe_block, d_a=1152, d_b=1024): super().__init__() self.ffn_a = ffn_a # Gemma's own FFN, frozen: the teacher self.inner = moe_block # MobileMoE's N_B + router + experts, frozen self.w_in = nn.Linear(d_a, d_b, bias=False) # trainable, 1152 -> 1024 self.w_out = nn.Linear(d_b, d_a, bias=False) # trainable, 1024 -> 1152 self.mode = "transplant" # or "original" (Gemma) or "zero" (FFN deleted) def forward(self, x): # x = N_A(h) if self.mode == "original": return self.ffn_a(x) if self.mode == "zero": return torch.zeros_like(x) m = self.inner(self.w_in(x.float()).to(torch.bfloat16)) # projections in fp32, MoE in bf16 return self.w_out(m.float()).to(x.dtype) # P_A and the residual stay Gemma'sfor i, layer in enumerate(gemma.model.layers): # all 26 layers layer.mlp = ReplaceFFN(layer.mlp, moe_blocks[i]) # Gemma layer i borrows MobileMoE layer iThe three modes share one set of weights. "original" is the intact Gemma (the teacher during training), "zero" is Gemma with its FFNs deleted (the floor), and "transplant" is the hybrid, so every evaluation compares them on exactly the same text.Inside the Borrowed MoE BlockFigure 4: Routing one token inside the transplanted block. Scores and expert indices are illustrative.Equation 6: MobileMoE’s router. Each expert gets an independent sigmoid score. A fixed per-expert bias b decides which four are selected, but not their weights. The chosen four are normalised and scaled to sum to 2.5.Equation 7: The block’s output: the always-on shared expert plus the weighted outputs of the four selected experts.Two properties of this block determine how the transplant behaves. First, the router weights W_r are frozen, so W_in alone determines the router input and therefore the top-4 selection. If W_in maps Gemma’s hidden states into a small region of MobileMoE’s input space, the top-4 sets concentrate on a few experts and the rest receive no tokens, which is why every evaluation measures the load over the 60 experts. Second, routing is dropless: each expert processes every token routed to it, with no capacity limit.Each routed expert is a gated FFN, 1,024 → 512 → 1,024, and the shared expert is a gated FFN, 1,024 → 2,048 → 1,024. One block has 60 · 3 · 1,024 · 512 + 3 · 1,024 · 2,048 + 60 · 1,024 ~100.7M parameters, where the last term is the router, and 12.6M of them are active per token.Extracting the block required two implementation changes. MobileMoE computes its router logits with F.linear on the router's weight tensor, so a forward hook on the router module never fires, and the block returns its output flattened to (tokens, 1,024). The wrapper reads the router logits from the block's second return value and reshapes the output to (batch, sequence, 1,024).The parameter count:Equation 8: 61.3M trainable parameters over 26 layers. Each transplanted layer activates 8.9M fewer parameters per token than the FFN it replaces, so the hybrid runs about 0.77B active parameters per token against Gemma’s 1.00B.Four 512-wide experts plus a shared expert are smaller than one 6,912-wide GeGLU, which is why the hybrid is cheaper per token than Gemma. About 3.6B parameters sit frozen in memory, Gemma’s 1.0B and the 2.6B of MobileMoE-M’s 26 MoE blocks. Less than 2% of what’s loaded ever receives a gradient.Teaching Two Strangers to TalkW_in and W_out start as random matrices, and a random W_in sends Gemma’s tokens to random experts. So training runs in three steps, each one closer to the real objective than the last.Figure 5: The training pipeline. Ridge regression gives every layer a sensible start, local matching fits each layer to Gemma’s own FFN (Stage 1 only), and end-to-end training fits the whole hybrid to Gemma’s next-token predictions.Ridge initialisation: Gemma and MobileMoE read the same calibration text, each with its own tokenizer. At every position where both tokenizers end a token at the same character (90.2% of Gemma’s tokens), we pair Gemma’s normalised state x with MobileMoE’s own MoE input at the same layer. W_in is the ridge-regression solution that maps one to the other. We then fit W_out the same way, from the MoE block’s output to Gemma’s own FFN output.Equation 9: Ridge initialisation. XᵀX and XᵀY are accumulated batch by batch in fp64, so 9 GB of activations never have to be stored. Targets are RMS-normalised per token, because N_B discards their length anyway.The regulariser λ is selected per layer on a held-out tenth of the calibration batches, and W_out is fitted second, with W_in fixed. This fit, computed once in Stage 1 on 211,601 aligned positions and reused through Stage 3, is the initialisation for every all-26 run. W_in alone reached a mean validation NMSE of 0.36, and the full chain recovered from 56% (layer 11) to 84% (layer 24) of each FFN’s output energy.Figure 6: Ridge initialisation, layer by layer, on MobileMoE-M. W_in fits worse in deeper layers, while the full chain fits best in the last ones. Local matching (dotted) did not move the per-layer loss away from where ridge put it.Local matching trains each layer independently to reproduce the output of the FFN it replaced, with a normalised MSE for which the zero prediction (a deleted FFN) scores exactly 1. One forward pass of the original Gemma provides inputs and targets for all 26 layers, at a learning rate of 1e-3 and 8,192 tokens per step. I ran it only on the first 25% of Stage 1’s tokens, where it did not improve on ridge.End to end. The full hybrid predicts the next token through Gemma’s output head, and a KL term penalises divergence from the original Gemma’s output distribution:Equation 10: End-to-end loss: cross-entropy on the next token plus β times the KL divergence from the original Gemma (the same weights, transplants off). β = 1: the goal is to recover Gemma, so drifting away from it counts as error.Why the loss needed its own backward pass. With Gemma’s 262,144-token vocabulary, the logits of one 1,024-token sequence take 1.07 GB in fp32, and autograd keeps several copies. The repo computes CE and KL over 256 positions at a time and implements the backward pass by hand: it recomputes each chunk’s logits z and forms dL/dz = (g_CE + g_KL)·softmax(z) − g_CE·onehot(y) − g_KL·p_A in place. Each chunk’s logits take 256 × 262,144 × 4 bytes = 0.27 GB, and at most two logit buffers are allocated at once.The teacher is the same set of weights in "original" mode, so p_A costs one extra forward pass without gradients and no second model in GPU memory.For end-to-end training, I used AdamW [9] with betas (0.9, 0.95) and eps 1e-8, a peak learning rate of 3e-4 with a 2% warm-up and a cosine decay to 10% of the peak, weight decay 0.01, and global gradient-norm clipping at 1.0. Every optimizer step averages 16 sequences of 1,024 tokens, 16,384 tokens in all.Two further implementation changes were required on MPS. The first is a bucketed MoE forward. MobileMoE’s reference loop gathers the tokens routed to each expert, a count that changes on every call. MPS compiles and caches a kernel for every new tensor shape, so GPU memory use grew without bound. The bucketed forward pads each expert’s token group to one of a few fixed sizes, with one GPU synchronisation per layer instead of one per expert:def _bucket(n: int) -> int: """Smallest size >= n in {16, 24, 32, 48, 64, 96, 128, ...}: two sizes per octave, so a group is padded by about a fifth on average and only about 2·log2(n) shapes ever occur.""" if n return 16 p = 1 q = (p >> 1) + (p >> 2) return q if n The second change runs right-padded batches without an attention mask. For padding positions beyond Gemma’s 512-token sliding window, every key is masked, the softmax over an all-masked row returns NaN on MPS, and the next layer propagates the NaN to every position. Both models are causal, so right padding cannot affect the logits of earlier positions, and the mask is removed.The Stage 3 RunStage 3 doesn’t start over. It picks up Stage 2’s projections and data stream and trains for 15M more tokens (915 steps), so no token is read twice and the total reaches 19,988,480. The objective, the data mix and the evaluation stay the same. Only two things are new: a fresh AdamW state, and a new cosine schedule from the same peak, a warm restart in the sense of:Equation 11: The extension starts from Stage 2’s final projections and runs its own warm-up and cosine schedule over 915 steps.With S = 915 steps, the warm-up lasts 2% of the run, about 18 steps, before the cosine decays from 3e-4 to 10% of that peak.Before the run, I measured throughput for micro-batches of 1, 2 and 4 sequences in fresh processes. Gradient accumulation keeps every optimizer step at 16 sequences, so only throughput and GPU memory change.Table 4: The speed check before each run picks the micro-batch. Every optimizer step still averages 16 sequences of 1,024 tokens. Stage 4’s column comes up in its own section.For Stage 3, 4 × 4 already exceeded the 11.84 GB limit (12.02 GB), so 8 × 2 was not tested. Stage 3 trained at 2 × 8, at 165 to 175 tokens per second (Stage 2: 131) with a peak of 10.97 GB, and took about ~12–14 hours for its 15M tokens.Stage 3 ResultsThe learning-rate restart increased the loss at first. The training cross-entropy rose from 3.29 at step 0 to 4.12 at step 10, and the first held-out check (perplexity 35.8) was higher than Stage 2’s last one (34.7). By step 200 it was below that value, and every later check was lower than the previous one. The gradient norm decreased from about 2.5 to 1.4 over the run, with no NaN or inf values.Figure 7: All four runs on one axis. Stage 3 (dark orange) starts where Stage 2 ends, loses a little to the warm-up, then follows the curve down. Stage 4 (violet) comes in its own section.The last check, at 19.7M tokens, read 24.0, close to the 24 that Stage 2’s fit had predicted. The curve was flattening: the last 200 steps, with the learning rate below 7e-5, reduced perplexity by only 0.7.Table 5: Stage 3’s final evaluation, against Stages 1 and 2.On the validation mix, Stage 3 reaches a perplexity of 23.5, 2.29 × Gemma’s 10.25, with 42.5% next-token accuracy (Gemma: 52.6%) and a CE gap of 0.83 nats. Four times the tokens did not reduce the gap uniformly: it decreased by 31% on the validation mix and by 22% on WikiText-103 and C4. A power law through Stages 2 and 3, the functional form scaling-law studies use for loss against data [11], quantifies the difference:Equation 12: The CE gap as a power law in tokens. Each doubling of tokens removes 1 − 2^−α of the remaining gap.Figure 8: The gap to Gemma against tokens, on log-log axes. Dotted: the power law through Stages 2 and 3. The violet diamond is Stage 4, against that line. The fourth panel is the question test’s fact log-probability gap.Stage 3 read exactly four times the tokens of Stage 2, so T₃/T₂ = 4 and each exponent follows from two values. On the validation mix, α = ln(1.20/0.83)/ln 4 ~0.27. The three exponents:α = 0.27 on the training mix. Each doubling of tokens removes about 17% of the gap.α = 0.18 on held-out text from other distributions (WikiText-103 and C4). Each doubling removes about 12%, so the projections generalise beyond the training distribution, at a lower rate.α = 0.41 for the fact log-probability. Its gap decreased fastest, 5.11 → 2.95 → 1.67 nats from Stage 1 to Stage 3, about 25% per doubling.Extrapolating with the same exponents: twice Gemma’s perplexity is a gap of ln 2 ≈ 0.69 nats, and 1.5 × is ln 1.5 ≈ 0.41. Solving the power law on the mix gives T ≈ 20M · (0.83/0.69)^(1/0.27) ≈ 40M tokens for 2 ×, and about 300M for 1.5 ×. C4, with its smaller exponent, needs about 300M tokens for 2 ×. At 175 tokens per second, 300M tokens is about three weeks of continuous training on a fanless laptop.Routing entropy increased overall: the mean rose to 0.961, and dead experts fell to 31 of 1,560, 21 of them in layers 0 to 3. Layer 1’s entropy kept decreasing, to 0.806, with its busiest expert receiving 15.6% of the routing slots, more than nine times the uniform share. Stage 4 shows the same trend at a faster rate.On the questions, Stage 3 answered 6 of 30 correctly (Paris, Tokyo, Portuguese, Jupiter, gravity, blue). The mean fact log-probability rose to −1.90 per token (e^−1.90 ≈ 0.15 probability per answer token), a fact recovery of 89%. The reference answer’s log-probability increased over Stage 2 for 29 of 30 questions, the exception being 2 + 2. About 8 of the 30 replies repeat the question: “The opposite of hot is the opposite of hot.”Stage 4: A Partial Transplant With a Smaller DonorStage 3’s power law puts 1.5 × Gemma’s perplexity at about 300M tokens, too many for this hardware. Stage 4 tests whether a different layer layout lowers the CE gap per training token, and how much of the recovery depends on the donor’s experts. It changes three things at once.Stage 4 ArchitectureA smaller donor. MobileMoE-S-Base has the same block design as MobileMoE-M (sigmoid top-4 routing over 60 experts, a shared expert, the Llama 3 tokenizer) at roughly half the parameter count. It has 20 layers of width 768, routed experts of 768 → 384 → 768, and 1.3B parameters in total with 272M active per token. It scores lower on knowledge benchmarks: 43.7 on 5-shot MMLU against MobileMoE-M’s 54.7, 33.2 against 49.0 on TriviaQA and 12.6 against 20.9 on Natural Questions, by the model cards.Table 6: The two donors. MobileMoE-S has the same design as MobileMoE-M at roughly half the size.A partial transplant. With 20 donor layers and 26 host layers, every MobileMoE-S layer can be used exactly once, at the same relative depth. Layer j goes to Gemma layer l(j) = round(j · (26 − 1)/(20 − 1)) = round(25j/19). For example, j = 2 lands on round(2.63) = 3, so Gemma layer 2 gets no donor layer. The right panel of Figure 9 shows the full map.The six Gemma layers that no donor layer reaches keep their own FFN, frozen and untouched, with no projections around it. Those are layers 2, 6, 10, 15, 19 and 23, about every fourth layer over the depth. I call this layout spread.Figure 9: Stage 4. Gemma 3 1B keeps the FFNs of 6 layers (blue), and the other 20 hold MobileMoE-S’s MoE blocks at the same relative depth, each between two trainable projections (green).Equation 13: Stage 4. Each layer either keeps Gemma’s own FFN or runs MobileMoE-S’s MoE block of layer j between W_in and W_out. The training objective is unchanged.Each transplanted layer computes the Stage 3 equation with W_in (768×1152) and W_out (1152×768), and MobileMoE-S’s own frozen router, selection bias, shared expert and routed scaling factor. In code, the layout is one function, shortened here from the repo’s layer map. It returns a map from Gemma layer indices to MobileMoE-S layer indices, and layers absent from the map are not modified.def spread_layers(n_a: int, n_b: int) -> dict[int, int]: """Every B layer once, at its relative depth in A. Returns {A layer: B layer}. Gemma 3 1B (26) with MobileMoE-S (20): the FFNs of layers 2, 6, 10, 15, 19, 23 stay.""" out = {relative_depth(j, n_b, n_a): j for j in range(n_b)} # j -> round(j * 25 / 19) if len(out) != n_b: raise ValueError("two B layers fall on the same A layer") return dict(sorted(out.items()))42% fewer trained parameters. The projections are now 1,152 → 768 and back, in 20 layers instead of 26:Equation 14: What the partial transplant costs: 35.4M trained parameters instead of 61.3M, and about 0.70B active parameters per token instead of 0.77B (Gemma 3 1B: 1.00B).The active count, step by step: Gemma’s 26 FFNs account for 621.1M of its 999.9M parameters, leaving 378.8M for embeddings, attention and norms. Adding 6 kept FFNs (6 × 23.9M) and 20 transplanted slots at 7.12M active MoE parameters plus 1.77M projection parameters each gives about 0.70B. The weights on the GPU decrease from 6.97 GB to 4.11 GB.All other settings are unchanged so that Stage 4 compares with the all-26 runs token for token. It uses the same data in the same order as Stages 2 and 3, the same objective (the KL teacher is still Gemma with all 26 FFNs), the same optimizer, and 15M tokens in 915 steps. Ridge initialisation is recomputed for MobileMoE-S, and local matching is not used.Confound. Compared with Stages 1 to 3, Stage 4 keeps 6 FFNs, uses a lower-scoring donor and trains fewer parameters. A difference in results cannot be attributed to any one of the three. No control that separates them (random-weight experts, or MobileMoE-M in the same 20 slots) was run.Stage 4 also has a different floor. Deleting only the 20 transplanted FFNs and keeping the other 6 gives the layout floor, and its CE is higher than deleting all 26:Table 7: The two floors. Deleting 20 FFNs and keeping 6 is worse than deleting all 26, on every set.On the validation mix, the layout floor’s CE gap is 18.31 nats against 13.09 for deleting all 26, and on the question test its fact recovery is −37% on the all-26 scale.The 6 kept FFNs were trained on residual-stream inputs produced with the other 20 FFNs present. With those 20 removed, the kept FFNs receive inputs outside their training distribution, and their outputs increase the CE more than removing them would. Against the layout floor, GR_CE would be 0.955, an overstatement, so every Stage 4 number uses the all-26 floor of Stages 1 to 3 (GR_CE 0.938).Training Stage 4In the throughput check (Table 4), micro-batch 1 already exceeds every Stage 3 setting at 284 tokens per second, and I selected 8 × 2 at 391 tokens per second and 10.23 GB. Ridge initialisation on the 20 mapped layers takes about eight minutes, against 22 for MobileMoE-M. End-to-end training runs at about 50 seconds per step, 326 tokens per second on average, 1.8 × Stage 3’s throughput: about 13.3 hours for 15M tokens against Stage 3’s 23.5. Peak GPU memory reached 11.6 GB, close to the 11.84 GB limit, and 4 × 4 would have used about 2 GB less at 5% lower throughput.The ridge fits show a layer-specific pattern:Figure 10: Ridge initialisation with the two donors, per Gemma layer. Through the block and W_out, layers 5, 11 and 12 are the hardest with both donors.W_in reproduces MobileMoE-S’s MoE inputs with a validation NMSE of 0.22 in Gemma layer 0, rising to about 0.38 in layers 20 to 25, slightly lower than MobileMoE-M’s 0.24 to 0.44. Through the block and W_out, the Gemma layers with the highest NMSE are 5, 11 and 12 (0.42, 0.43 and 0.40), the same layers as with MobileMoE-M. This indicates that the difficulty lies in Gemma’s FFN outputs at those layers rather than in the experts, though not conclusively, since both donors share a model family and training data.Results: Fewer Tokens, Fewer Parameters, Same QualityStage 4 reads exactly the tokens that Stages 2 and 3 read, in the same order, so its held-out checks can be compared with the all-26 runs at matched token counts (Stage 2’s checks up to 4.92M, then Stage 3’s, interpolated):Figure 11: CE gap to Gemma at matched tokens. Stage 4 (violet) sits below all 26 layers at every check, by 0.07 to 0.27 nats, and the advantage shrinks late.Stage 4’s CE gap was 0.22 nats lower at 1.64M tokens. At 4.92M it was 0.17 nats lower than Stage 2’s, although Stage 2’s learning rate had fully annealed by then and Stage 4’s had not. The difference was largest, 0.27 nats, at 6.55M and 8.19M tokens, partly because of Stage 3’s warm-up, then decreased to 0.10 at 13.11M and 0.07 at 14.75M. That last difference is below the 0.1-nat threshold I had set in advance for counting a difference.Table 8: Stage 4 (15M tokens, 20 of 26 layers, MobileMoE-S) against Stage 3 (20M tokens, all 26, MobileMoE-M), and against the all-26 power law read off at 15M tokens.Stage 4’s perplexity is equal to or lower than Stage 3’s on every set: 23.2 against 23.5 on the mix, 45.1 against 48.3 on WikiText-103 and 48.8 against 51.3 on C4. Next-token accuracy matches within a few tenths of a percentage point on every set. Stage 4 uses 25% fewer tokens, 42% fewer trained parameters and a donor 11 MMLU points lower.The power law estimates the all-26 hybrid’s CE gap at 15M tokens, a more controlled comparison: 0.90 on the mix, 1.48 on WikiText-103 and 1.22 on C4. Against those values, Stage 4’s gap is 0.08 nats lower on the mix, 0.11 on C4 and 0.14 on WikiText-103. The difference is largest on the sets outside the training distribution, where the all-26 hybrid had its smallest exponent. One hypothesis is that the 6 kept FFNs, trained on Gemma’s own 2T tokens, contribute Gemma’s original FFN outputs at those layers, which improves prediction on text outside the training mix. I haven’t tested that.Fact RecallTable 9: The 30-question test across every run. Fact recovery uses the scale of Stages 1 to 3 (all 26 FFNs deleted = 0%).Stage 4 answered 10 of 30: Paris, Portuguese, the Nile, the Sun, the heart, gravity, 12 months, blue, Shakespeare and 1945. It did not answer Tokyo and Jupiter, which Stage 3 had. Its mean fact log-probability is −1.82 against Stage 3’s −1.90, a fact recovery of 89%, the same as Stage 3’s. Per question, the reference answer’s log-probability is higher than in Stage 3 for 16 questions, lower for 12, and within 0.05 for 2.Figure 12: The right fact’s log-probability per question for Stages 2, 3 and 4, with Gemma in blue. Stage 2 → 3 is a clear step to the right, while Stage 3 → 4 moves both ways.The difference between 10 and 6 correct answers is within sampling noise for n = 30. The fact log-probability, the lower-variance measure, is nearly the same for Stages 3 and 4: Stage 4 reaches about the same fact log-probability with a donor that scores 11 MMLU points lower.Table 10: Ten questions, three models. The replies have the right shape, and the facts are often near misses.The incorrect answers are mostly entities of the correct type that are related to the reference answer: the Congo for the Nile and 1939 for the end of World War II in Stage 3, “John” for the first person on the Moon in Stage 4, George W. Bush for the first president in both. “The United States” is a high-frequency default output in both runs, generated for the capital of Germany and the location of the pyramids. Numeric answers are mostly incorrect in both: 2 + 2 = 2, a triangle with 12 sides (Stage 3) or four (Stage 4), and a 12-day week in Stage 4.Greedy 40-token continuation has the lowest quality in both hybrids. For the prefix “The capital of France is”, Stage 3 repeats “the capital of the United States” and Stage 4 generates a sequence of zeros, although both answer “The capital of France is Paris.” in the question template.Routing: The Early Layers NarrowFigure 13: Left, routing entropy per Gemma layer at the end of Stages 3 and 4. Right, the weakest layer at every check. Stage 4’s weakest layer heads toward the 0.7 alarm.From Gemma layer 4 upward, Stage 4’s MoE layers have entropy equal to or higher than Stage 3’s (0.97 to 0.99), with a mean of 0.954 over the 20 layers. The low-entropy layers are the first MoE layers. Gemma layer 0 ends at 0.724, with its busiest expert receiving 18.3% of the routing slots, about eleven times the uniform share. Layer 1 is at 0.788, and 26 of the 29 dead experts (of 1,200) are in Gemma layers 0, 1 and 3. The lowest entropy decreased at every check, from 0.846 to 0.714, close to the 0.7 alarm from Equation 2. Stage 3’s layer 1 showed the same trend at a slower rate.The same early layers show this with both donors. One hypothesis, which I haven’t tested: early MoE routers select experts mainly from token identity, learned on the Llama 3 tokenizer. Gemma’s tokenizer segments text differently, and a linear W_in cannot reproduce a router input that depends on which Llama 3 token occupies the position. Deeper routers depend more on contextual features, which a linear W_in reproduces more accurately.What the Four Stages Say TogetherThe transplant functions as a language model. A frozen Gemma 3 1B runs with the frozen MoE blocks of a model with a different training set, tokenizer and width. With at most 61M trained parameters, it improved on every held-out metric with more training tokens. H1 is supported for language modeling: the CE gap is under 1 nat on the training mix. The routing-health part of H2 is supported too, except in the first MoE layers. I did not measure agreement with the donor’s own routing.Some failure points are in Gemma, some in the routing. Gemma’s layers 5, 11 and 12 have the highest linear-fit error with either donor, and both donors’ first MoE layers have decreasing routing entropy inside Gemma.Next-token prediction recovers faster than factual recall, and the CE gap decreases slowly with tokens. At 17% of the gap per doubling on the training mix and 12% on other distributions, approaching Gemma’s CE requires hundreds of millions of tokens. The partial transplant matched the full one with fewer tokens and fewer trained parameters.The donor’s benchmark score may matter less than I assumed. A donor 11 MMLU points lower gave the same perplexity, the same accuracy and the same fact recovery. If the transplanted experts provided the donor’s factual predictions to Gemma, in the way a dense model’s FFNs compute its factual predictions [1], a lower-scoring donor should have produced lower fact recovery. Either Gemma’s attention, its kept FFNs and the trained projections account for most of the recovered CE, or the 6 kept FFNs compensated for the lower-scoring donor. Stage 4 cannot separate these, and whether the pretrained expert weights matter requires a random-expert control.ConclusionCan one model’s MoE layers replace another model’s FFNs with only a trained linear map on each side? For language modeling, yes, after four stages on a MacBook Air. Whether the donor’s factual predictions transfer through its experts is less clear, and the Stage 4 result indicates the donor’s experts contribute less than I expected.If you try a transplant of your own, write the gating tests first. Every blocking issue here was an implementation issue (autograd memory for 262,144-way logits, per-shape kernel compilation on MPS, NaN rows from fully masked padding), and each was detected before the long runs. Report the CE gap rather than gap recovery, because a floor at 5 million perplexity assigns a high GR_CE to almost any functioning model. Before attributing recovery to the donor’s pretrained experts, run the control I didn’t: random-weight experts in the same slots. And test keeping some of the host’s own FFNs early, since here the partial transplant matched the full one with fewer tokens and trained parameters, although that run also changed the donor.Reproduce it. The training and evaluation code, configs, figures and run scripts are on GitHub: expert-transplant. Each stage has its own script, for example bash scripts/stage3_run.sh for Stage 3 and bash scripts/stage4_run.sh 15m for Stage 4, and bash scripts/m0_checks.sh runs the seven gating tests before any of them. Gemma 3 is under the Gemma Terms of Use, and MobileMoE-M-Base and MobileMoE-S-Base are under the FAIR Noncommercial Research License, so anything derived from them, trained projections included, is for non-commercial research only.Note. Due to hardware constraints (one MacBook Air with 16 GB of unified memory), I have stopped this experiment after Stage 4 for now. If you try it, with this pair of models or another, let me know your results.Want to learn more? Check out my other article: LatentMoE: NVIDIA’s Latent Mixture of Experts Explained Through Equations, Architecture, Code and Visual WorkflowReferencesMor Geva, Roei Schuster, Jonathan Berant, Omer Levy, Transformer Feed-Forward Layers Are Key-Value Memories (2021), Research paper (arXiv:2012.14913)Karel Lenc, Andrea Vedaldi, Understanding Image Representations by Measuring Their Equivariance and Equivalence (2015), Research paper (arXiv:1411.5908)Yamini Bansal, Preetum Nakkiran, Boaz Barak, Revisiting Model Stitching to Compare Neural Representations (2021), Research paper (arXiv:2106.07682)Haotian Liu, Chunyuan Li, Qingyang Wu, Yong Jae Lee, Visual Instruction Tuning (2023), Research paper (arXiv:2304.08485)Minyoung Huh, Brian Cheung, Tongzhou Wang, Phillip Isola, The Platonic Representation Hypothesis (2024), Research paper (arXiv:2405.07987)Aran Komatsuzaki et al., Sparse Upcycling: Training Mixture-of-Experts from Dense Checkpoints (2022), Research paper (arXiv:2212.05055)Gemma Team, Google DeepMind, Gemma 3 Technical Report (2025), Research paper (arXiv:2503.19786)Yanbei Chen, Hanxian Huang, Ernie Chang, Jacob Szwejbka, Digant Desai, Zechun Liu, Vikas Chandra, Raghuraman Krishnamoorthi, MobileMoE: Scaling On-Device Mixture of Experts (2026), Research paper (arXiv:2605.27358)Ilya Loshchilov, Frank Hutter, Decoupled Weight Decay Regularization (2019), Research paper (arXiv:1711.05101)Ilya Loshchilov, Frank Hutter, SGDR: Stochastic Gradient Descent with Warm Restarts (2017), Research paper (arXiv:1608.03983)Jared Kaplan, Sam McCandlish, Tom Henighan, Tom B. Brown, Benjamin Chess, Rewon Child, Scott Gray, Alec Radford, Jeffrey Wu, Dario Amodei, Scaling Laws for Neural Language Models (2020), Research paper (arXiv:2001.08361)Expert Transplant: I Replaced Gemma 3 1B’s FFNs With Another Model’s MoE Experts on a MacBook Air was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.