The Head Dimension That Changed Everything: Architectural Alignment in EAGLE-3 Training

In the intricate dance of training a speculative decoding draft model for a 1-trillion-parameter language model, few moments are as consequential as the one captured in message 2781 of this opencode session. It is a brief message — barely a paragraph of analysis followed by a single file edit — yet it represents a critical juncture where the assistant recognized a silent architectural mismatch that could have rendered the entire training pipeline useless. This article examines that message in depth: the reasoning that motivated it, the assumptions it challenged, and the architectural knowledge it required.

The Moment of Discovery

The message opens with a direct comparison between two configurations:

AQ-MedAI uses num_attention_heads=64, num_key_value_heads=64, head_dim=128. With hidden_size=7168, normally head_dim = 7168/64 = 112. But they set head_dim=128 explicitly. This makes the attention dimension 64 * 128 = 8192 > 7168, meaning the Q/K/V projections project up from 7168 to 8192.

This observation is the culmination of a chain of reasoning that began in the preceding message ([msg 2780]). There, the assistant had just completed a successful end-to-end training run on 10 samples — the first time the EAGLE-3 training pipeline had executed without errors. But rather than celebrating, the assistant immediately pivoted to verification: "Now I need to verify the checkpoint format is compatible with what vLLM expects for EAGLE-3 spec decode." This forward-looking instinct is characteristic of the assistant's methodology throughout this session — each milestone is immediately followed by a check for downstream compatibility.

The assistant had noticed a discrepancy: the saved config's head_dim was 112, but the AQ-MedAI reference model (the canonical EAGLE-3 implementation for Kimi-K2.5) used head_dim=128. To confirm this, the assistant queried the HuggingFace model hub in [msg 2780], fetching the configuration of AQ-MedAI/Kimi-K2-Instruct-eagle3. The result confirmed the suspicion: head_dim: 128.

Why Head Dimension Matters

The head dimension in a transformer attention mechanism determines the size of each attention head's query, key, and value vectors. In standard Llama-style architectures, head_dim is computed as hidden_size / num_attention_heads. For Kimi-K2.5, hidden_size=7168 and num_attention_heads=64, yielding the default head_dim=112. But the AQ-MedAI reference model overrides this to 128.

The consequence is mathematically significant. With head_dim=128 and 64 heads, the total attention dimension becomes 64 × 128 = 8192, which is larger than the hidden size of 7168. This means the Q, K, and V projection matrices in the EAGLE-3 draft model's single transformer layer must project upward — from 7168 dimensions to 8192 dimensions — rather than the more typical downward or identity projection. This is an intentional architectural choice in the reference implementation, likely designed to give the draft model more representational capacity in its attention mechanism despite having only a single transformer layer.

If the assistant had not caught this discrepancy, the trained draft model would have had attention projections of shape [7168, 112] per head instead of [7168, 128], producing weight tensors with incompatible shapes. When vLLM attempted to load the checkpoint for speculative decoding, it would have failed with a shape mismatch error — or worse, silently loaded incorrect weights, producing garbage predictions during draft generation.

The Edit and Its Implications

The assistant's response is decisive and minimal:

This is an important difference. I should match it. Let me fix the config: [edit] /home/theuser/glm-kimi-sm120-rtx6000bw/eagle3-train/04_train.py

The edit itself (visible in the file modification) sets head_dim=128 on the LlamaConfig used to construct the EAGLE-3 draft model. This single parameter change propagates through the entire model construction: the LlamaAttention module reads head_dim from the config to determine the output dimension of its Q/K/V projections, the weight initialization routines allocate tensors of the correct shape, and ultimately the saved checkpoint contains weights that match what vLLM expects.

The LSP diagnostics shown after the edit — "Import 'torch' could not be resolved" and similar — are false positives from the local development environment's type checker, which lacks access to the remote server's Python environment. The assistant correctly ignores these, as they do not affect runtime behavior.

Input Knowledge Required

To understand and act on this discrepancy, the assistant needed several layers of knowledge:

  1. Transformer architecture fundamentals: The relationship between hidden_size, num_attention_heads, and head_dim, and how they determine projection matrix shapes.
  2. The HuggingFace Transformers config system: Knowledge that LlamaConfig computes head_dim automatically from hidden_size / num_attention_heads unless explicitly overridden, and that head_dim is a stored attribute that controls attention layer construction.
  3. The AQ-MedAI reference model: Awareness that a reference EAGLE-3 implementation exists on the HuggingFace hub, and that its configuration represents the canonical architecture that vLLM's speculative decoding engine expects.
  4. vLLM's checkpoint loading requirements: Understanding that vLLM performs strict shape checking when loading speculator weights, and that any mismatch between the saved checkpoint's weight shapes and the expected architecture will cause loading failures.
  5. The speculators library's model construction: Knowledge that Eagle3DraftModel builds its attention layers from a LlamaConfig, and that modifying this config before model creation changes the resulting weight shapes.

Output Knowledge Created

This message produced a corrected training script that now generates checkpoints with the correct head dimension. The downstream consequence is visible in [msg 2782], where the assistant inspects the saved checkpoint and finds weight tensors with the expected shapes — including k_proj.weight: [8192, 7168], q_proj.weight: [8192, 7168], and v_proj.weight: [8192, 7168] — confirming that the 8192-dimensional attention space (64 heads × 128 head_dim) is now correctly reflected in the model weights.

The Broader Context

This message sits within a larger narrative arc in segment 22 of the session. The assistant had spent the preceding hours building an EAGLE-3 training pipeline from scratch, wrestling with API incompatibilities between the speculators library and vLLM 0.16, patching custom worker code for Kimi-K2.5's architecture, and finally getting the training loop to execute. The successful 10-sample run in [msg 2775] was a major milestone — but the assistant knew that "successful" meant nothing if the output format was wrong.

The head dimension fix in [msg 2781] is a textbook example of the "verify early, verify often" philosophy that characterizes robust ML engineering. Rather than assuming that a training run that completes without errors has produced a usable checkpoint, the assistant immediately cross-referenced the output against the reference implementation. This caught the mismatch before scaling up to the full training dataset, saving what could have been hours or days of wasted computation.

Assumptions and Potential Pitfalls

The assistant's reasoning makes one implicit assumption: that the AQ-MedAI reference model's architecture is the correct one for vLLM compatibility. This is a reasonable assumption — the AQ-MedAI model is the only publicly available EAGLE-3 implementation for Kimi-K2.5, and the assistant had previously verified that vLLM's speculative decoding code references this architecture. However, it is worth noting that the assistant did not independently verify why the reference model uses head_dim=128. The up-projection from 7168 to 8192 is unusual and could reflect a specific design choice by the AQ-MedAI team that may not be strictly necessary for all EAGLE-3 training scenarios. The assistant's decision to match it faithfully is conservative and correct for the immediate goal of vLLM compatibility, but it does close off the possibility of experimenting with alternative head dimensions.

Conclusion

Message 2781 is a quiet but pivotal moment in this coding session. In a few lines of analysis and a single config parameter change, the assistant averted an architectural mismatch that would have silently invalidated the entire training pipeline. It demonstrates that in large-model engineering, the most important decisions are often not about algorithms or hyperparameters, but about ensuring that the tensors coming out of one system have exactly the shapes that the next system expects. The head dimension — a single integer buried in a configuration file — becomes the linchpin connecting training to inference, and getting it right makes all the difference.