Transformers As Generalizable Optimal Controllers

Turki Bin Mohaya, Maitham AL-Sunni, John M. Dolan, Peter Seiler · DOI

Abstract

We study whether optimal state-feedback laws for a family of heterogeneous Multiple-Input, Multiple-Output (MIMO) Linear Time-Invariant (LTI) systems can be captured by a single learned controller. We train one transformer policy on LQR-generated trajectories from systems with different state and input dimensions, using a shared representation with standardization, padding, dimension encoding, and masked loss. The policy maps recent state history to control actions without requiring plant matrices at inference time. Across a broad set of systems, it achieves empirically small sub-optimality relative to Linear Quadratic Regulator (LQR), remains stabilizing under moderate parameter perturbations, and benefits from lightweight fine-tuning on unseen systems. These results support transformer policies as practical approximators of near-optimal feedback laws over structured linear-system families.

Introduction

In classical control theory, designing an optimal controller—such as the Linear Quadratic Regulator (LQR)—traditionally requires a precise mathematical model of the system, represented by plant matrices. This dependence makes controllers rigid; if a system's physical parameters change (e.g., due to wear or payload shifts), the controller must often be recalculated from scratch. While "foundation models" have transformed fields like natural language processing, control has remained largely system-specific. This research investigates whether a single Transformer-based neural network can serve as a generalist, near-optimal controller for a diverse family of heterogeneous systems.

Methodology: Control as Sequence Modeling

The core innovation lies in casting LQR imitation as a sequence-to-action learning problem. To handle systems with varying numbers of inputs and outputs, the authors employ several key techniques:

  • Standardization and Padding: Systems of different sizes (from simple motors to 6-DOF manipulators) are mapped to a shared representation space using zero-padding and system-wise standardization.
  • Dimension Encoding: A binary identifier is appended to input vectors to inform the model of the active state and input dimensions.
  • Implicit System Identification: The architecture utilizes a multi-block Transformer to process a sliding window of recent states. This history allows the model to implicitly identify the underlying dynamics of the plant without explicit plant matrices.
Ablation of window length and data scale.

As shown in the ablation studies, the choice of window length is critical. A window of approximately 12 steps provides enough historical context for the model to "figure out" which system it is controlling, while longer windows offer diminishing returns. Training on larger datasets also consistently improves the validation loss, suggesting strong scaling properties.

Experimental Results and Generalization

The model was trained on a library of 17 "seen" systems, including inverted pendulums and robotic arms, and tested on 11 "unseen" systems such as thermal systems and vibrating beams. To ensure robustness, each system was subjected to random parameter perturbations of up to $\pm 30\%$.

Sub-optimality across seen and unseen systems.

The results demonstrate that the Transformer achieves remarkably low sub-optimality compared to the true LQR solution across both seen and unseen categories. Notably, the model remains stabilizing even under significant parameter shifts, exhibiting a level of flexibility that traditional non-adaptive controllers lack. While zero-shot performance on unseen systems is strong, a single epoch of fine-tuning (few-shot learning) further bridges the gap to optimal performance.

Conclusion

This work demonstrates that Transformers can effectively approximate optimal feedback laws across a wide range of linear systems. By learning the underlying structure of control rather than memorizing specific instances, these models offer a path toward more generalizable and robust robotic controllers. Future research will focus on providing formal stability guarantees—a standard requirement in classical control that remains an empirical observation here—and extending the framework to handle the complexities of nonlinear dynamics.

Summary updated

Abstract

We study whether optimal state-feedback laws for a family of heterogeneous Multiple-Input, Multiple-Output (MIMO) Linear Time-Invariant (LTI) systems can be captured by a single learned controller. We train one transformer policy on LQR-generated trajectories from systems with different state and input dimensions, using a shared representation with standardization, padding, dimension encoding, and masked loss. The policy maps recent state history to control actions without requiring plant matrices at inference time. Across a broad set of systems, it achieves empirically small sub-optimality relative to Linear Quadratic Regulator (LQR), remains stabilizing under moderate parameter perturbations, and benefits from lightweight fine-tuning on unseen systems. These results support transformer policies as practical approximators of near-optimal feedback laws over structured linear-system families.
BibTeX
@misc{mohaya2026transformers,
  author = {Turki Bin Mohaya and Maitham AL-Sunni and John M. Dolan and Peter Seiler},
  title = {{Transformers As Generalizable Optimal Controllers}},
  year = {2026},
  eprint = {2603.14910},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.14910},
}
Figure