Papers · 2025 · Reading: 23 min, plus 1 in closed details.
Paper · arXiv preprint (cs.CL), not peer reviewed · arXiv 2502.08213

LLM Modules: Knowledge Transfer from a Large to a Small Model using Enhanced Cross-Attention (LLM Modules)

Konstantin Kolomeitsev
Independent researcher, Almaty, Kazakhstan · arXiv v1 12 February 2025 (the only version); code and weights released 11 to 13 February 2025

In one line: Freeze Qwen2-1.5B and pass its last hidden states through two trainable cross-attention layers with an adapter and a gate into a GPT-Neo-sized decoder (randomly initialised in the released code, not the pretrained GPT-Neo-125M), trained on Bespoke-Stratos-17k reasoning traces. The evidence is qualitative: on the one prompt every model was given (5 plus 5, one sample each, graded by the author) the pair writes R1-style reasoning where GPT-Neo trained alone writes incoherent text; the second prompt went to the pair only, and the reported loss curve cannot show learning because the released cross-attention lets each position see later tokens.

2 prompts
the whole evaluation: "sum of 5 and 5" and "remainder of 7 by 4", one sample each
no benchmark, no accuracy, no repeated runs · §5.2
1.1 loss
the final training and validation loss after 15 epochs, from 13.8 at the start
the code's cross-attention can see later tokens, so the loss cannot show learning · §5.3
1.76B parameters
what the combined model runs at inference (recounted from the code and configs)
1.14 times the frozen Qwen2-1.5B it was meant to replace · §4.1

How far to trust it: Read it as an idea, not a result. The evidence is two hand-picked prompts, one sample each, graded by the author. The released code adds problems the paper does not mention: its cross-attention lets every position see later tokens during training, so the loss curves cannot show learning; once the training subset starts being redrawn, the validation set is mostly reused training data; the "small" model is initialised at random rather than from GPT-Neo-125M, and running the pair takes 1.14 times the parameters of the frozen model alone. The idea of a frozen model read by a trained adapter is sound; Flamingo and CALM show it working with real evaluations. The evidence, judged.

The idea in one sentence: instead of distilling a large model into a small one, keep the large model frozen and train a small decoder that reads its last hidden states through cross-attention; a toy rebuild of the released code learns the task only once a causal mask is added, and as released the training loss is measured with the next token visible, so the paper's evidence (two prompts and a loss curve) cannot show that it works.

You need: distillation, the alternative the paper argues against (Distillation and small language models), and the causal mask in teacher-forced training (The transformer from zero); this page is the paper. New terms: knowledge source (the frozen Qwen2-1.5B); generation module (the trainable GPT-Neo-sized decoder); Enhanced Cross-Attention (cross-attention plus an adapter and a gate, the bridge between them); CombinedModel (the pair); the leak (the bridge lets each position read later tokens during training).

The "small model" runs the whole frozen large model on every token
Notice the dashed box: Qwen2-1.5B never trains, so training is cheap, but it runs for every generated token, so deployment is not. And the bridge sits in front of the decoder, not inside it, which is not what the paper's prose says. Drawn from the released model.py (the paper has no figure); counts from the Hugging Face configs, by recompute.py. On this page's toy, the bridge as released answers 2% of unseen problems when generating; with a causal mask, 69%; the small model alone, 11% (the leak, the toy).

Konstantin Kolomeitsev (independent, Almaty, Kazakhstan). arXiv 2502.08213, 12 February 2025, one version. Code and weights (Hugging Face, access on request); the same code openly on GitHub; the author's blog post. Added to this knowledge base on 2026-09-01 from a blog entry. Topics: llm-training-and-post-training, llms.

Read this as a small proof of concept, not as a result.
Single author, tiny models, one dataset, no baseline sweep, and an evaluation of two prompts. It is filed here because the architectural idea, a frozen large model read by a small trainable one, is worth knowing, not because the evidence is strong. Reading the released code (below) makes the evidence weaker still, and this page's toy shows why.

Problem: getting a large model's capability into a small one

§1, §2

The paper's foil is distillation (Hinton et al., 2015; the methods compared on Distillation and small language models), as in DistilBERT and TinyBERT, which it cites (§2): it needs a large training run, and the student ends up as one fused artifact with the teacher's knowledge baked in irreversibly; to change the knowledge you distill again.

The paper's alternative: leave the large model frozen and let a small trainable model read its internal representations directly, so the pair works as two composable modules rather than one distilled model (§1). It promises that training "significantly reduces training costs while remaining effective for solving specific business tasks", and (§2) that, unlike classic distillation, it preserves "a larger portion of the original model's information" and handles "longer input sequences (e.g., 128K tokens in Qwen2 versus 2K tokens in GPT-Neo)". That last claim does not survive the code: see the context claim.

Idea: a knowledge source and a generation module

§3.1
  • Knowledge source: Qwen2-1.5B, frozen. It reads the query and its hidden representations are passed on, not its output text (§3.1). It never receives gradients, so training fits on modest hardware.
  • Generation module: GPT-Neo-125M, trainable. It receives those representations "via Enhanced Cross-Attention layers and, combining them with its own computations, generates a coherent response".
  • Only the small side trains: the connecting layers and the small model. The framing is modular: the frozen model is a reusable knowledge source, and different small heads could in principle attach to it for different tasks. That composability is the structural difference from distillation.
The point was a small deployable model. To answer one question, how many parameters does the trained CombinedModel run?

Where the layers sit is the part the prose gets wrong. The paper (§4.1) and the old version of this page say the cross-attention is inserted into GPT-Neo's stack. In the code it sits in front of it, inside the module called ModifiedQwenWithCrossAttention. Fig. 1 builds the pair as the released model.py does, in the order a token passes the parts, with each part's code lines and parameter count (recounted in The evidence, rebuilt):

  1. Qwen2-1.5B reads the query, frozen. The query, in Qwen2's tokenizer (151,646 tokens), runs through all 28 blocks of width 1536: 1,543.7M parameters, every one with requires_grad = False, run under torch.no_grad() (lines 140 to 148, 182). It never trains.
  2. Its last hidden state goes through pre_proj. Qwen2 runs on the query; its last hidden state (hidden_states[-1], one 1536-wide vector per position) goes through a trainable 1536 × 1536 projection, pre_proj (2.4M; lines 190 to 193). Qwen2's own output layer is never used.
  3. The stream g is made from the same state. The stream g starts as an MLP of that same state (1536 → 1152 → 768, 2.7M; lines 171 to 178), and a separate linear projection, proj (1536 → 768, 1.2M; line 196), is kept for later. So the queries are not GPT-Neo's own states: both sides of the "cross"-attention are views of Qwen2's last layer, computed before GPT-Neo runs.
  4. Two Enhanced Cross-Attention layers update g. Queries from g, keys and values from the pre_proj states (Wq, Wk, Wv), then the adapter and the gate (lines 19 to 130, 204 to 207): 5.1M per layer, of which cross-attention 3.5M, adapter 0.4M and gate 1.2M. The mask covers padding only, which is the leak below.
  5. g + proj enters GPT-Neo as its input embeddings. final_states = gptneo_states + projected_states (line 210) is all GPT-Neo ever sees. GPT-Neo's own token embeddings are never used, and its positional embeddings are zeroed at the start (they still train); sequences are cut to 2,048 positions (lines 246 to 250). Its 12 blocks of width 768 (85.0M) start from random weights (green in Fig. 1; see Method).
  6. A new output layer reads out Qwen2's vocabulary. It maps 768 to Qwen2's 151,646 tokens (116.5M, line 232), because the pair uses Qwen2's tokenizer (§4.1): 53% of all trained parameters. Labels are the input tokens (line 435), so it is trained on every token, the system prompt included. The plate is not to scale: it would be 197 times longer than wide.
  7. Every token runs all of it. 1.76B parameters per generated token, 1.14 times Qwen2-1.5B alone; 219.5M of them train (the bridge's 16.4M, the decoder and the new output layer).

Method: Enhanced Cross-Attention

§3.2, §4.1

The paper describes its connecting layer in three parts (§3.2): linear projections that convert the large model's width (1536) to the small model's (768); an adapter block, an extra non-linear transformation; and a gating mechanism that "dynamically blends the original representations with the external knowledge". Read from the code, one layer is (step 4 of Fig. 1):

a = Adapter( CrossAttn( Q = g Wq, K = h Wk, V = h Wv ) ),   z = σ( [g, a] Wz ),   g ← g + ( z ⊙ a + (1 − z) ⊙ g )
h
Qwen2's last hidden state at every position, after a trainable 1536 × 1536 projection (pre_proj), LayerNormed
g
the stream that becomes GPT-Neo's input, 768 wide, LayerNormed before the query projection
Adapter
768 → 256 → GELU → 768, LayerNorm, plus a residual (the bottleneck adapter of Houlsby et al., 2019; adapters among the PEFT methods: PEFT)
z
a sigmoid gate per position and per channel, computed from the stream and the adapter's output
8 heads of 96 dimensions, scores scaled by 1/√96, dropout 0.1 on the attention weights (model.py lines 19 to 130).

Two more things the paper does not say. GPT-Neo is built with GPTNeoForCausalLM(gptneo_config) (line 220): from its configuration, with random weights, never loaded from the pretrained GPT-Neo-125M. So "the small model" brings an architecture, not knowledge; the paper's "GPT-Neo-125M-clean" control (trained from scratch) is the honest comparison for it.

A freezing line that freezes nothing (harmless)

The line meant to freeze the embedding layers sets an attribute on the module, not on its parameters, so it freezes nothing; it does not matter, because those embeddings are never used.

Fig. 1: widths and block counts from the Hugging Face configs of Qwen2-1.5B and GPT-Neo-125M (a slab's side is proportional to the model's width), code lines from model.py, parameter counts by recompute.py. Grey is frozen; the decoder's green marks its random start.

Training: what the code actually trained on

§4.2

The paper's description (§4.2): Bespoke-Stratos-17k, examples longer than 4,096 tokens filtered out "to avoid memory overflow errors", dynamic padding, a random train and validation split, AdamW and early stopping. Bespoke-Stratos-17k is 16,710 questions (math, code, science and puzzles) with DeepSeek-R1's reasoning traces and answers. So the CombinedModel is itself trained on a teacher's outputs: what the paper offers instead of distillation is a different student architecture, not a different source of knowledge.

The code adds the rest (model.py, main and train_model): 15 epochs, batch size 1, learning rate 1e-4 for the bridge and 5e-5 for GPT-Neo, gradient clipping at 1.0, mixed precision, patience 5. Each epoch uses a 30% subset, redrawn with a new seed whenever the last validation loss was below 1.8. The author's blog adds one NVIDIA L4 GPU (4 vCPUs, 32 GB), about 5 hours and under 10 dollars (blog). Running the code's data pipeline on the dataset with Qwen2's tokenizer (stratos_stats.py; details):

  • Most long traces never reach their end. GPT-Neo has 2,048 positions, so the code cuts every sequence there; 58% of the examples that pass the 4,096 filter are longer, so 22% of all kept tokens (the end of the reasoning and the final solution) are never trained on.
  • The loss includes the system prompt. Labels are the input tokens, so the same 246-token instruction counts in every example: 13% of all loss tokens are a fixed text the model can learn by heart.
  • The validation set is mostly old training data once the reshuffle starts, because each epoch redraws train and validation from the whole dataset. If it starts after epoch 1, 99.6% of the last epoch's validation examples were trained on earlier.

The leak: the cross-attention can see the answer

model.py lines 64 to 73

Teacher-forced training feeds the whole text at once and is only honest if no position can see the tokens after it, which a causal mask guarantees (The transformer from zero). Qwen2 and GPT-Neo are both causal. The cross-attention between them is not: it masks padding only (mask = attention_mask.unsqueeze(1).unsqueeze(2), shape [batch, 1, 1, length]). So during training, position t can attend to Qwen2's state at position t + 1, which encodes token t + 1, the very token it must predict. At generation time the future does not exist yet, and that shortcut is gone.

Trained on reasoning traces with this mask, the toy below reaches a training loss of almost zero and a validation loss far below the honest model's. How often does it get the answer right when it actually generates?

Fig. 2 runs this page's trained toy (built in The toy) on one held-out problem, teacher-forced as in training. Rows are query positions (the stream g that becomes the decoder's input), columns the frozen model's states (keys and values); a bar's height is the weight, first cross-attention layer, mean of 4 heads, computed in your browser from the shipped seed-0 weights. Orange bars read positions that come later.

  1. The whole matrix, as released. Every row may read every column, and most of the weight sits right of the diagonal, on states that come later. It piles up on two columns of the check line, its second "=" and the number after it, which even the first rows read.
  2. Position "sum" predicts the first operand. Nothing before it says which number comes next: an honest model can only guess (1 in 20). The released mask lets this query read every state, later ones included.
  3. Position "a" predicts the second operand. Again unknowable from the past, and again every state is readable, the operand being predicted included.
  4. "T" predicts the copy of a. The trace starts by restating the problem: the answer is 3 positions back, readable without any shortcut. Here the answer is in the past, so no shortcut is needed.
  5. "b" predicts "=". Pure format, learned from the traces.
  6. "=" predicts the answer. The one step that needs knowledge. The frozen model's own state at "=" already holds the answer; the shortcut is to read the next state instead, which IS the answer token. An orange stream into the next column is the shortcut.
  7. "c" predicts "-". Format again: the check line.
  8. "A" predicts the final answer. A copy of the answer written earlier.
  9. Now generate: the future does not exist yet. At generation time the model has only the tokens it has written, so the cross-attention can only read the past and the weights renormalise over it. On this problem the released model first goes wrong at "T": in training it read a from later states (the check line ends with it); now those states do not exist, and it writes "16" instead of "2". Its whole trace reads T 16 % 6 = 6 ; 6 < 6 ok A 6. This problem was picked as the first held-out sum the fixed model gets right and the released one does not; over all 364 held-out problems the released model generates the right answer 2% of the time (3 seeds).

Two cautions. The toy may make the shortcut easier than it is in Qwen2. There, the last hidden state at t + 1 is tuned to predict token t + 2, though it is computed from token t + 1 and probably still carries much of it (unconfirmed: not measured here); how much the real run used the shortcut cannot be measured without running the 7.2 GB checkpoint. And the real CombinedModel does produce coherent text, so it also learned the honest path; the toy's released variant mostly did not. What the leak does settle: the paper's evidence of learning, a loss falling "from 13.8 to 2.3 in the first epoch and to 1.1" (§5.3), is measured with the shortcut open on both training and validation data, so it cannot show how well the model predicts text it has not seen.

Results: two prompts

§5, Table 1

Seven models are compared (§5.1): DeepSeek-R1 671B; DeepSeek-R1-Distill-Qwen-1.5B (GGUF, 32-bit) as "a distilled model"; Qwen2-1.5B-Instruct (GGUF, 16-bit) as "the knowledge source model"; GPT-Neo-125M; GPT-Neo-125M-fine-tuned (with a 2,048-token limit); GPT-Neo-125M-clean, trained from scratch; and the CombinedModel. The evaluation is two prompts (§5.2):

  1. "sum of 5 and 5": "All small models produced a set of incoherent text. Large pre-trained models generated the correct answer; however, the Qwen2 model did not provide any 'reasoning' even when instructed. The CombinedModel demonstrated detailed reasoning comparable to large 'reasoning' models."
  2. "find the remainder by dividing 7 by 4": "The CombinedModel generated a response with a step-by-step explanation of the calculation, indicating the presence of a 'reasoning' component."

Table 1 summarises the responses in words: DeepSeek R1 671B, the distilled 1.5B and the CombinedModel get "[Detailed reasoning] [Brief structured answer]"; Qwen2 1.5B "[Brief structured answer, without reasoning]"; both GPT-Neo controls "[Lack of reasoning and coherent answer]". The other observations (§5.3): the loss fell from 13.8 to 2.3 in the first epoch and to 1.1 later, "confirming the successful convergence of the model"; the CombinedModel improved significantly on the original small models; transferring knowledge via Enhanced Cross-Attention "enables the combined model to produce more structured and logically coherent outputs". Code and pretrained weights are released.

The released transcripts (compare-responses-from-models.md, all eleven graded in The evidence, rebuilt) add what the table hides:

  • One sample per model and prompt, drawn with temperature 0.9 and no seed, so the same prompt could give a different answer on the next run.
  • The second prompt was given to the CombinedModel only. Its answer, 3, is right, but its working includes false steps ("7 - 4*3 = 7 -12 = -5, but since the remainder has to be positive, it's 3").
  • The prompts differ between models: DeepSeek-R1 got the bare question, the GPT-Neo models a different template, and the GPT-Neo-clean run and one GPT-Neo-fine-tuned run were primed with the opening reasoning marker.
  • The "knowledge source" in the table is Qwen2-1.5B-Instruct, a chat-tuned model, while the CombinedModel reads the base Qwen2-1.5B. And the comparison is against DeepSeek's released distilled model (trained on 800,000 R1 samples from Qwen2.5-Math-1.5B, per the DeepSeek-R1 paper), not against a distillation run of the author's under the same budget.
The paper's discussion and future work (§6), and the blog's framing

The paper's discussion (§6) lists the advantages (lower cost than full fine-tuning of large models, adapting to a task by training on only the needed data, "the potential for exponential improvement in generation quality through the combination of representations from various architectures") and future work: combining other model types (a CNN with an LLM), studying different cross-attention configurations, and applying the method to business tasks. The blog frames the frozen model as a "database" whose "tables" the small model learns to use.

The toy: what reproduces

this page, not the paper

Nobody outside can rerun the paper's comparison cheaply, so this page rebuilds the architecture exactly, at toy scale, and runs the comparisons the paper did not. A frozen "large" model (2 blocks, width 48, 60,432 parameters) is pretrained on 560 arithmetic facts (sums of numbers up to 19, remainders by 2 to 9) in a brief format, 7 + 5 = 12, so it plays Qwen2's role: it knows the answer, and never reasons. The finetuning data play Bespoke-Stratos's role: reasoning traces such as Q sum 7 5 T 7 + 5 = 12 ; 12 - 5 = 7 ok A 12, for only 25% of the facts. Every variant then sees the same 140 traces; 364 problems that appear in no trace are the test (training details in Run the modules).

Mean of 3 seeds (range in brackets); each variant at its own best learning rate from {1e-4, 3e-4, 1e-3, 3e-3}, picked on 56 validation problems. "Generates right" is free-running greedy decoding from the prompt; "teacher-forced" reads the true trace; "future scrambled" replaces every token after the first "=" with a random number.

  • The architecture works once the mask is fixed. The causal CombinedModel answers 69% of problems it never saw a trace for: it learned the trace format from the 140 examples and reads each answer from the frozen model. The small model alone, trained on the same traces, gets 11%: it has the format but not the knowledge. That is the paper's qualitative claim, and at toy scale it holds.
  • As released, it does not. 2% right when generating, while its teacher-forced loss is the lowest of all. Scrambling the future drops its teacher-forced accuracy at the answer from 87% to 52%; the causal model does not move (77% and 77%), as it cannot.
  • The like-for-like control does worse here, for a reason worth knowing. Fine-tuning the frozen model itself on the same 140 traces (what DeepSeek did to make its distilled model) gets 45%: after 2,500 steps on so few traces it forgets facts it was not shown (its brief-format answers on the test facts fall from 100% to 17%), while the frozen model inside the pair cannot forget. That is a point in the paper's favour that the paper never measured; a gentler fine-tune (fewer steps, or LoRA) was not tried here and might close the gap.
  • "Enhanced" is not shown to matter. Plain cross-attention, without the adapter and gate, gets 65% against 69%; a single trained linear layer on the frozen states gets 1%, so the trained decoder is needed to produce the trace format.

What the toy cannot test: scale, real language, and whether the real run's coherent outputs came despite the leak. It tests the mechanism and the comparisons, nothing more.

How much of this to believe

judged by this page

What holds up. The architecture is reasonable and fully released: code, weights and outputs, under the MIT licence, enough to check every claim, which is how the problems below were found. The one comparison that carries information is the CombinedModel against GPT-Neo trained alone on the same data: the alone versions produce mostly incoherent text (one sample states 5 plus 5 is 10 inside an invented riddle, then answers 25/8), the pair produces coherent traces with right answers on two prompts. Since the pair's small part also starts from random weights, the coherence must come from Qwen2's states, which supports the core idea that a frozen model's last layer can be read by a trained module. The author states the limits plainly in the blog ("I had no illusions of obtaining a fully reasoning model"), which counts in his favour.

What does not:

  • No measurement. Two prompts, one sample each, graded by the author (§5.2); no benchmark, no accuracy, no error bars. "Comparable in quality to models obtained by distillation" (abstract) rests on one arithmetic prompt both models get right.
  • The loss curve cannot show learning. The cross-attention sees later tokens during training and validation (above), 13% of the loss is a fixed system prompt, and, once the reshuffle starts, the validation examples are mostly earlier training examples. "Confirming the successful convergence" (§5.3) is not supported by these numbers.
  • Not like for like (the transcript caveats above): DeepSeek's distilled model as the baseline, the Instruct model as the "knowledge source", different prompts, a second prompt for one model. The obvious control, fine-tuning Qwen2-1.5B (or a LoRA on it) on the same 17k traces, is missing. On the toy, a full fine-tune run as long as the pair's training does worse (45% against 69%) because it forgets, so the answer is not a foregone conclusion either way; it has to be measured.
  • The method is not what the text says. The small model is not pretrained GPT-Neo; the cross-attention is not inside its stack; the context is 2,048 tokens, not 128K.
  • The cost claim is half the story. Training is cheap (about 5 hours on one L4), but inference runs 1.14 times Qwen2-1.5B's parameters; the paper's "small model" framing does not apply to deployment.

Verdict. An idea worth knowing, with no evidence that it beats the simple alternative. Believe that a trainable module can read a frozen model's last hidden states and learn a new output format from few examples (the toy confirms it, once the mask is fixed). Do not believe the paper's comparison with distillation, its loss curve, or its context and size claims.

What it takes to use this

  • Code: one file, model.py, MIT licence, Hugging Face Transformers and PyTorch; the 7.2 GB checkpoint (every weight in 32-bit, frozen Qwen2 included) behind an access request on Hugging Face.
  • Fix before using: add a causal mask to CrossAttentionLayer (line 70: combine the padding mask with a lower-triangular one); load the pretrained GPT-Neo if that is what you want; mask the system prompt out of the labels; keep a fixed validation set; mind the 2,048-token cut.
  • Budget: one NVIDIA L4 for training; inference runs the whole frozen model every token, plus the head (the hero figure).
    Memory, in more detail

    Training needs the frozen model in memory plus about 220 million trainable parameters and their optimizer state; the author used one NVIDIA L4. Inference needs the whole frozen model every token, plus the head.

  • When it might pay off: when you cannot change the large model (shared, certified or served elsewhere) but can read its hidden states, and need a new output behaviour; when several heads should share one frozen backbone. When it buys little: when you could fine-tune the large model, a LoRA or QLoRA on a 1.5B model fits easily on one GPU (QLoRA fine-tunes a 65B model on one 48 GB GPU, QLoRA abstract; memory per method on PEFT) and keeps inference at 1.0 times the model; and when you need a genuinely small model at inference, which only distillation gives.
Since the paper (sources read 3 October 2026)
  • The GitHub repository has no commits after 13 February 2025 (checked 3 October 2026), and the paper has one arXiv version.

Why it matters

beyond the paper

The idea belongs to a real family: freeze the big model, train a small module that reads its internals. It is attractive whenever you want capability without owning or retraining the large model. The family's serious members differ from this paper in instructive ways:

What this paper does not establish is whether its version works at any useful scale. A 1.5B teacher and a 125M-sized student on 17k examples cannot tell you whether the approach survives at 70B, whether it beats a well-tuned distillation run under equal compute, or how it behaves when the frozen model's representations are out of distribution. Treat the architecture as a pointer to the literature above and the results as anecdotal.

Connections

  • The serious versions of this idea: Flamingo's gated cross-attention into a frozen language model (Flamingo §2.2), CALM's composition of an anchor with an augmenting model (CALM §3.1), and the adapter and parameter-efficient fine-tuning literature: adapters, LoRA, QLoRA.
  • Contrast with actual distillation, under llm-training-and-post-training: DeepSeek-R1 distilled its reasoning into Qwen and Llama models by fine-tuning on 800,000 samples, the same kind of traces this paper trains on.
  • Adjacent in this batch: Bitune and Trained Persistent Memory, also frozen-backbone-plus-adapter designs.
  • The pieces: cross-attention and the causal mask come from Attention Is All You Need; the paper also cites T5 for transfer learning.