Optimality and NP-Hardness of Transformers in Learning Markovian Dynamical Functions
Yanna Ding, Songtao Lu, Yingdong Lu, Tomasz Nowicki, Jianxi Gao
TL;DR
This work tackles the problem of in-context learning for dynamics-driven, Markovian functions using transformer models. By reformulating the 1-layer linear self-attention loss into a strictly convex, reparameterized objective, the authors derive a closed-form global minimizer $X^* = H^{-1} b$ and show that recovering the corresponding transformer parameters is NP-hard, highlighting a fundamental expressivity gap. They then reinterpret multilayer linear self-attention as preconditioned gradient descent solving a multi-objective problem, and provide empirical validation on simplified transformers and GPT-2-like models. The results illuminate why deeper architectures can better capture structured Markovian dynamics and why shallow, single-layer LSAs may fail to realize the reparameterized optimum. Overall, the paper clarifies optimization landscapes, computational limits, and depth-driven improvements for ICL with dynamics-based inputs, offering a principled lens on transformer expressivity in structured settings.
Abstract
Transformer architectures can solve unseen tasks based on input-output pairs in a given prompt due to in-context learning (ICL). Existing theoretical studies on ICL have mainly focused on linear regression tasks, often with i.i.d. inputs. To understand how transformers express ICL when modeling dynamics-driven functions, we investigate Markovian function learning through a structured ICL setup, where we characterize the loss landscape to reveal underlying optimization behaviors. Specifically, we (1) provide the closed-form expression of the global minimizer (in an enlarged parameter space) for a single-layer linear self-attention (LSA) model; (2) prove that recovering transformer parameters that realize the optimal solution is NP-hard in general, revealing a fundamental limitation of one-layer LSA in representing structured dynamical functions; and (3) supply a novel interpretation of a multilayer LSA as performing preconditioned gradient descent to optimize multiple objectives beyond the square loss. These theoretical results are numerically validated using simplified transformers.
