Can Custom Models Learn In-Context? An Exploration of Hybrid Architecture Performance on In-Context Learning Tasks

Ryan Campbell, Nelson Lojo, Kesava Viswanadha, Christoffer Grøndal Tryggestad, Derrick Sun, Sriteja Vijapurapu, August Rolfsen, Anant Sahai · Submission to NeurIPS 2024 · Rejected

TL;DR

By systematically disassembling and hybridizing GPT-2, LLaMA, and Mamba into 12 distinct model variants, this paper reveals how fine-grained architectural choices—like normalization layers, position embeddings, and state-space mixers—dictate in-context learning (ICL) behavior. The authors discover that certain architectural pairings induce strong, undesirable inductive biases (such as learning ordinary least squares instead of sparse regression) or completely stall training convergence on synthetic benchmarks.

What Problem Does This Paper Address?

While Large Language Models demonstrate an impressive ability to learn algorithms purely in-context from prompt demonstrations, most research treats architectures as monolithic blocks. Studies examining ICL on synthetic function classes typically analyze standard GPT-2 (multi-head attention, absolute positional embeddings, LayerNorm) or compare pure Transformers against pure State Space Models (SSMs like Mamba).

Consequently, researchers lack a clear understanding of how granular, modern design choices—such as Rotary Position Embeddings (RoPE), SwiGLU activations, RMSNorm, or hybrid Attention-Mamba layers—individually and jointly shape a model’s ICL capabilities and learning dynamics.

Methods

The authors build a modular, typed experimental framework and evaluate 12 architectures (~10M parameters each, 12 layers, 256 embedding dimension):

  • Base baselines: Unmodified GPT-2, LLaMA, and Mamba.
  • GPT-2/LLaMA hybrids (6 variants): GPT-2 modified with various combinations of RoPE, SwiGLU feed-forward networks, and RMSNorm.
  • LLaMA/Mamba hybrids (3 variants): LLaMA modified by substituting the SwiGLU FFN with a Mamba Mixer block, removing RoPE and prepending a Mamba Mixer as a positional embedder, or doing both.

All models are trained for 500k steps using Adam ($lr = 10^{-4}$) to minimize the mean squared error over sampled prompt completions.

To aggregate performance across varying sequence lengths into a single interpretable number, the authors introduce the ICL Regression Score ($S_{\text{model}}$): $$S_{\text{model}} = \frac{\sum_i (\xi_{\text{model}}^{(i)} - \xi_0^{(i)})}{\sum_i (\xi_{\text{base}}^{(i)} - \xi_0^{(i)})}$$ where $\xi^{(i)}$ is the squared error at context length $i$, $\xi_0^{(i)}$ is a zero-estimator baseline, and $\xi_{\text{base}}^{(i)}$ is a task-specific standard algorithm baseline. A score of 1 matches the baseline; values above 1 outperform it.

Datasets

The study trains and evaluates models purely on six synthetic in-context learning benchmarks adapted from prior literature:

  1. Linear Regression: $y = w^T x$, $d=20, N=41$ (Baseline: Least Squares).
  2. Sparse Linear Regression: $w$ has $k=3$ active features, $d=20, N=41$ (Baseline: LASSO).
  3. 2-Layer MLP Regression: Target generated by a random 2-layer MLP with width 100, $d=20, N=101$ (Baseline: 2-layer NN).
  4. Decision Tree Regression: Depth-4 random decision trees, $d=20, N=101$ (Baseline: Pretrained GPT-2).
  5. Sparse Parity: Parity over $k=2$ coordinates from 10 inputs, $N=140$ (Baseline: Trained Mamba).
  6. Vector MQAR: Multi-Query Associative Recall on the unit sphere, $d=20, N=128$.

Key Insights and Ideas

  • Architectural Local Minima & Suboptimal Convergence: On Sparse Linear Regression, where LASSO is optimal, GPT-2 with RMSNorm and SwiGLU converged to the Ordinary Least Squares (OLS) solution (ICL score $0.754$) rather than learning sparsity. When tested out-of-distribution on standard linear regression, it outperformed siblings trained on sparse data, proving it learned a valid—but task-suboptimal—least squares algorithm.
  • Escaping Regression Baselines: Some architectures dynamically transition through algorithms during training. GPT-2 SwiGLU quickly converged to OLS by 100k steps, but with continued training "unlearned" it to adopt the optimal LASSO-like predictor by 500k steps.
  • Destructive Combinations: Simply replacing LayerNorm with RMSNorm in standard GPT-2 (without RoPE) caused catastrophic failures: its score collapsed on Decision Trees ($0.114$ vs. $1.000$ for baseline GPT-2) and stalled on Sparse Linear ($0.535$).
  • Parity vs. Associative Recall Trade-offs: Pure Transformers (GPT-2 and LLaMA) completely failed Sparse Parity (score $\approx 0.023$). However, injecting Mamba blocks into LLaMA enabled all LLaMA-Mamba hybrids to master Sparse Parity (score $1.000$) while maintaining Transformer-level retrieval capability on Vector MQAR.

Key Results

  • Linear & MLP Regression: All 12 variants converged to near-optimal predictors ($S_{\text{model}} \approx 0.996$ for Linear, $\approx 1.130$ for 2-layer MLP).
  • Sparse Linear: Most models attained $S_{\text{model}} \approx 0.93$, led by LLaMA RoPE,SwiGLU-less ($0.938$). GPT-2 RMS ($0.535$) and GPT-2 RMS SwiGLU ($0.754$) severely underperformed.
  • Decision Trees: LLaMA RoPE-less achieved the top score ($1.018$). Mamba converged slowly ($0.832$), while GPT-2 RMS failed entirely ($0.114$).
  • Sparse Parity: Clean dichotomy: pure attention models scored $0.023$, while Mamba and all LLaMA-Mamba hybrids achieved perfect $1.000$ scores.

Limitations and Future Work

  • Single Seeds: Due to compute constraints (~1200 GPU hours total), each architecture–task pair was run only once, preventing measurement of seed-to-seed variance.
  • Training Horizon: Training capped at 500k steps; some architectures (e.g., Mamba on Decision Trees) were still steadily improving and might have converged with additional compute.
  • Synthetic Scope: Experiments were restricted to low-dimensional synthetic regression problems. Future work must validate whether these architectural inductive biases translate to natural language modeling, token retrieval, or vision tasks.

Summary updated

BibTeX
@misc{campbell2024can,
  author = {Ryan Campbell and Nelson Lojo and Kesava Viswanadha and Christoffer Grøndal Tryggestad and Derrick Sun and Sriteja Vijapurapu and August Rolfsen and Anant Sahai},
  title = {{Can Custom Models Learn In-Context? An Exploration of Hybrid Architecture Performance on In-Context Learning Tasks}},
  year = {2024},
  eprint = {2411.03945},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.03945},
}
Figure