arXiv:2611.00585cs.LGOct 2026

Manuscript Offprint

arXiv:2611.00585

Conic Certification of Transformer Attention

Masoud Ataei

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Attention is the computational core of large language models, yet the verifiers that bound how far an attention head's output can move under input perturbations give no guarantee on how loose their bounds are. A weak certificate therefore cannot be told apart from a fragile model. We develop a conic programming theory of attention certification that supplies this guarantee. We prove that the difficulty lies not in the softmax but in the bilinear interaction of a varying query with the keys. This interaction makes certification NP-hard over boxes and inapproximable once the attention logits can move by a constant amount. A fixed query or listed token substitutions, by contrast, make the exact worst case efficiently computable. An exponential cone moment relaxation then certifies a head with an error bounded quadratically in the perturbation radius by computable quantities, an order that cannot be improved. We also show that relaxations that treat a network one operation at a time, linear bound propagation among them, pay on second-order terms a sum of per-operation maxima instead of one coupled maximum. Computational results on GPT-2 indicate that the theory carries over to a trained model. Against exact worst cases with the query fixed, the certificate attains the predicted second-order accuracy. It is tighter than linear bound propagation on every head, and the looseness of bound propagation tracks the predicted per-operation excess.

Keywords: certified robustness, transformers, self-attention, conic programming, exponential cone, semidefinite relaxation, linear bound propagation, neural network verification, computational complexity, trustworthy artificial intelligence

1 Introduction

Transformers [1] have become the computational substrate of modern artificial intelligence, and how their behaviour can change under a change of their inputs has become a central question of trustworthy artificial intelligence. Adversarial examples [2, 3], and their counterparts for language models [4], show that small and deliberately chosen changes can redirect what a model computes. A certificate answers the question for all inputs at once. Given a set of admissible inputs and a quantity read linearly from the model, such as a logit margin, it returns a number that the quantity provably cannot exceed anywhere in the set. A certificate is sound when it never underestimates the worst case, and it is useful only to the extent that it does not overestimate it by much.

For networks of piecewise-linear units, certification is mature. Complete methods solve the problem exactly by satisfiability modulo theories, mixed-integer programming or branch-and-bound [5–7]. Incomplete methods relax it by linear programming, bound propagation, abstract interpretation or semidefinite programming [8–13], and the limits of relaxing one neuron at a time are relatively well understood [14]. Attention is different. It couples a bilinear interaction between tokens with the softmax normalization. The verifiers built for it propagate linear bounds or zonotopes through the two operations separately [15–17], with convex bounds on the softmax itself [18], or work at the level of the text [19, 20], and randomized smoothing [21] offers probabilistic guarantees of another kind. For sparsemax attention, mixed-integer programming finds the exact worst case [22], and Rezazadeh and Gholami Davoodi [23] compute the tightest bound on the softmax that score intervals alone allow. These verifiers are sound and can be fast. None of them, however, comes with a guarantee on how far its bound lies from the true worst case or on how that distance scales with the perturbation, and the complexity of the underlying problem has not been mapped. A loose certificate therefore cannot be attributed either to the method or to the model.

This paper develops a theory of attention certification based on conic programming. Its object is the central primitive of a transformer, namely one attention head with fixed weights, input tokens varying in convex sets, and a linear functional of the head's output. The construction rests on one observation. The softmax, usually regarded as the obstacle, has a rigid structure. The exponential cone represents the exponential in it exactly from below, and a secant bounds it from above with a slack known in closed form. The difficulty lies instead in the bilinear score between a query and a key. Lifting the problem into a moment matrix meets this difficulty by coupling where a head attends with what it reads.

The ingredients are classical, and the novelty lies in what is proved about them. They are moment relaxations of nonconvex quadratic problems [24–26], the exponential cone of relative entropy programming [27], the hardness of the cut norm [28] and Dinkelbach's method of fractional programming [29]. Semidefinite certificates for ReLU networks [12], curvature-based certificates for smooth networks [30] and Lipschitz analyses of attention [31] neither relax the softmax nor establish an order of accuracy in the perturbation radius. What this paper contributes is an accuracy theory for the coupled problem. It proves that the moment relaxation is accurate to second order in the perturbation radius, with constants that do not depend explicitly on the sequence length or the dimension, and that this order is attained, so it cannot be improved. It also identifies the computable quantity at the core of the error. Semidefinite relaxations of quadratic problems that are exact at a nominal instance can remain exact under small changes of the data [32]. Here, the admissible set grows from a point, and the gap of the relaxation is of exact second order. The paper also maps the complexity of the problem, with exact algorithms against which certificates are measured. Moreover, in the spirit of the convex barrier of Salman et al. [14] but at second order, it identifies the loss that relaxations treating one operation at a time cannot avoid.

The results form three strata. The first locates the difficulty. The softmax does not make certification hard. Its Lipschitz and interval bounds do not grow with the context or the dimension, and relaxed attention patterns obey an exact identity that weights their slack by the values the head reads. Hardness comes from the bilinear score alone. With a varying query and tokens in boxes, certification is NP-hard already for two tokens, and inapproximable once the attention logits can move by a constant amount. With a fixed query, the exact worst case is the root of a separable scalar equation, computed in polynomial time for boxes and ellipsoids, and listed token substitutions are solved exactly for any query.

The second stratum constructs the certificates. A linear program over the admissible attention patterns is solved greedily, with a first-order gap that does not depend explicitly on the dimension. Its solution exhibits a worst admissible attention pattern, and its sensitivities show how the bound responds to the values of the keys and to the attention bounds. A level-one exponential cone moment relaxation has a gap bounded by a value-weighted secant slack. This slack vanishes quadratically in the score width and hence in the perturbation radius. The gap of the relaxation is of exact second order already for a head with two keys and a fixed query, in which one key varies in a disc. The radius certified to a given accuracy therefore grows like the square root of the tolerance. Safe dual bounds with an explicit rounding allowance, and an exact reduction to each head's subspace, make the certificate robust to solver inaccuracy and affordable on a trained model.

The third stratum explains the looseness of bound propagation. Relaxations that bound one operation at a time include linear bound propagation with any choice of slopes. On second-order parts and remainders, they pay a sum of per-operation second-order maxima, whereas the exact term is one coupled maximum. The excess grows with the effective rank of the coupled term.

The theory is tested on synthetic heads and on all heads of GPT-2 small [33], with perturbations of the normalized tokens that each head reads. Against exact worst cases with the query fixed, the gap of the second-order certificate grows quadratically in the perturbation radius, as predicted. The certificate is tighter than the linear bound propagation methods CROWN [9] and α\alpha-CROWN [34] on every head, typically by a factor of four to twenty. On the remainders of GPT-2 blocks, the looseness of CROWN tracks the predicted per-operation excess and exceeds it only by a small factor. The code and the exact worst cases are publicly available. 1^{1}

1^{1}https://github.com/chimera1001/conic-attention-cert

The paper is organized as follows. Section 2 sets up the problem, the quantities that control it and the structure of the softmax, and Section 3 maps the complexity of certification. Section 4 constructs the two certificates and Section 5 describes how they are computed. Section 6 analyses per-operation relaxations, Section 7 reports the computational results and Section 8 concludes. Proofs are collected in Appendix A, and the relaxation is written out in Appendix B.

References (56)