STEM: Decoupling Transformer Memory from Computation with Static Lookup Tables in FFN Layers

    This article introduces STEM, a feed-forward network (FFN) design that replaces the up-projection in gated FFNs with a per-layer embedding table indexed by token ID. It explains how the FFN's memory access works, how this design separates memory capacity from per-token matrix multiplication cost, and how it differs from Mixture-of-Experts routing. It also covers engineering challenges in sharding, sparse training, memory bandwidth, and the limits of static memory, along with suggested evaluation metrics.

    1. Background: Must the FFN Compute Its Addresses Every Time?

    In standard Transformers, the feed-forward network (FFN) is generally considered one of the main carriers of model parameters and computation. Take the gated FFN as an example. Its typical forward pass can be abstracted as:

    1. a = act(W_gate · x)
    2. u = W_up · x
    3. h = W_down · (a ⊙ u)

    Here, x is the hidden state of the current token after the attention layer. W_up maps the input to a higher-dimensional space, W_gate produces the gating signal, and W_down compresses the high-dimensional result back to the model dimension. From the perspective of key-value memory, the vector produced by W_up · x can be understood as an input-dependent “address vector.” The gate modulates the content associated with that address, and the down projection compresses and fuses the result.

    This path is expensive. Every token at every layer must run dense matrix multiplications to compute its address vector dynamically. The computation grows with the hidden dimension and the FFN intermediate dimension, and the parameters in W_up are tightly coupled to the input representation. If the model wants more memory capacity, it usually has to increase the intermediate dimension or add experts. Both options raise the computation cost per token or the routing complexity.

    This raises a question: if one of the core roles of the FFN is to access memory token by token, must the address vectors be computed dynamically every time? Could the model look up addresses instead of computing them?

    2. Core Change: Replacing the Up-Projection with a Static Hierarchical Embedding Table

    The approach, referred to as STEM below, modifies the FFN structure directly. It removes the up-projection and no longer computes the address vector dynamically. Instead, each layer keeps its own embedding table indexed by token ID. During the forward pass, the model uses the token ID to look up a static vector and uses it as the output that W_up · x would have produced. The gate and down projection stay in place to compress the representation and modulate it with context.

    It can be abstracted as:

    1. e = E_layer[token_id] # Per-layer embedding table, looked up by token ID
    2. a = act(W_gate · x) # The gate still depends on the contextual hidden state
    3. h = W_down · (a ⊙ e) # The down projection performs compression and fusion

    Illustrative pseudocode:

    1. def standard_gated_ffn(x, W_gate, W_up, W_down):
    2. a = act(W_gate @ x)
    3. u = W_up @ x
    4. return W_down @ (a * u)
    5. def stem_ffn(x, token_id, layer, W_gate, W_down):
    6. a = act(W_gate @ x)
    7. e = layer.embedding_table[token_id] # Static lookup, independent of the current context
    8. return W_down @ (a * e)

    The static vector e contains no information about the current context. However, the gating signal a is still generated from x, so the model keeps some ability to select and modulate based on context. The down projection compresses the high-dimensional memory vector back to the model dimension and fuses it with other representations. STEM does not turn the whole FFN into a fully static module. It makes the generation of memory addresses static and keeps the context-dependent modulation of memory content in the gate and the down projection.

    Compare the memory access paths. A traditional FFN follows this sequence: dynamically compute the address, read implicit memory, apply gated modulation, and produce a compressed output. STEM follows this one: index statically by token ID, read memory from the table, apply gated modulation, and produce a compressed output. The change looks like a simple module replacement, but it separates memory capacity from the matrix multiplication cost per token.

    3. Why Capacity and Per-Token Computation Are Decoupled

    In a standard FFN, increasing the intermediate dimension to add memory capacity also increases the cost of the W_up, W_gate, and W_down matrix multiplications. STEM works differently. Its memory capacity depends mainly on the number of rows V in each layer’s embedding table and on the dimension d_ff. The per-token matrix multiplication stays in the gate and the down projection. Expanding the vocabulary or the table capacity does not directly add dense W_up · x multiplications, because the table lookup replaces that path.

    To be precise, this decoupling holds for matrix multiplication FLOPs, not for all costs. Lookups still require memory access. Larger tables increase storage, memory gather operations, cache misses, and communication pressure in distributed settings. A more accurate statement is this: STEM moves the main cost of expanding memory capacity from per-token matrix multiplication to storage and memory access. Expanding capacity no longer necessarily increases per-token computation linearly.

    This property is useful in practice. When a model needs a large memory but its per-token computation budget is limited, static lookup offers a different path from widening the FFN or adding dynamic routing.

    4. Differences from Dynamic Routing

    Mixture-of-Experts (MoE) models also try to increase capacity without activating all parameters. Their core mechanism is dynamic routing at runtime: a routing network selects a few experts for each token, and the selected experts process it. STEM has no dynamic routing. It indexes the per-layer embedding table directly by token ID, so a static index replaces the routing step.

    The differences can be summarized as follows:

    • Selection basis: MoE scores experts dynamically based on the current hidden state. STEM looks up the table directly by token ID.
    • Execution path: MoE requires routing computation, expert dispatch, and load balancing. The STEM path is highly deterministic and consists mainly of lookups and aggregation.
    • Capacity organization: MoE expands capacity through combinations of experts. STEM expands capacity through token-level embedding rows in each layer.
    • Cost structure: MoE costs include routing and expert computation. STEM costs lean toward storage, memory access, and sparse updates.

    STEM is therefore not a simple replacement for MoE. It separates memory access from dynamic computation and routing and uses a purely static indexing approach. It suits scenarios that prioritize determinism, easy parallelization, and decoupled capacity. It also faces the expressiveness limits of static memory.

    5. Key Engineering Challenges

    1. Distributed Sharding and Lookup Aggregation

    A large table in every layer creates significant storage pressure. In practice, embedding tables are often sharded by layer, by vocabulary range, or by dimension. In a batch, many token IDs may repeat. The system can aggregate duplicate IDs first and then merge the lookup results, which reduces repeated memory access. Frequent tokens can use a hot cache, and infrequent tokens can use tiered storage or on-demand loading.

    2. Sparse Training and Optimizer State

    Gradients for a lookup embedding are sparse, since a batch typically updates only some of the rows. Maintaining full optimizer state for the entire table can consume a large amount of GPU memory and host memory. Sparse optimizers, sharded optimizer states, and frequency-based reweighting can help. Attention is also needed for long-tail tokens, which may receive too few updates. The initialization and learning rate schedule for new or rare tokens also affect training stability.

    3. Memory Bandwidth and Inference Caching

    Removing the up-projection reduces matrix multiplication, but table lookups can become a memory bandwidth bottleneck. At inference time, teams need to consider the quantization precision of the table, paged loading, prefetching, and cache hit rates. For batched requests, the cache can be organized by token frequency. For multilingual or domain expansion, table capacity and cold-start strategy should be planned in advance.

    4. Limits of Static Memory

    A static vector does not depend on context, so the same token retrieves the same memory in every context. The gate and down projection can modulate that memory based on context, but they cannot fully replace the input-dependent address generation of a dynamic FFN. This approach therefore fits best when memory access accounts for a large share of the work and token-level patterns are strong. For tasks that depend heavily on context disambiguation or compositional generalization, STEM may need to be combined with attention, a dynamic FFN, or a hybrid architecture.

    6. Evaluation Suggestions and Practical Observations

    When evaluating this kind of architecture, do not look only at training loss. Also track:

    • Per-token matrix multiplication FLOPs and end-to-end throughput;
    • Table storage footprint, memory bandwidth, and cache hit rate;
    • Performance on long-tail tokens, multilingual content, and new domain terms;
    • The effect of ablating the gate and the down projection;
    • The benefit curve and saturation point as table capacity scales;
    • Training stability under distributed sharding and sparse updates.

    Overall, the value of STEM does not lie in claiming that this structure is always better. It offers a clear design perspective. It makes the generation of memory addresses in the FFN static, replaces the up-projection with a lookup, and moves the main cost of expanding capacity from per-token matrix multiplication to storage and memory access. It also shows that Transformers do not have to compute memory addresses dynamically. With careful capacity planning and engineering optimization, static indexing can be a practical way to restructure the FFN’s memory mechanism.