cs.LGOct 12, 2026

Masked Attention Pooling Is Invariant to Padding and Permutation: A Formal Proof in Lean

Authors: Yusuf Khaled Sadek, Enes Yilmaz

Organizations: The Ohio State University, Columbus, OH, USA

Abstract

Attention-based multiple instance learning (MIL) pools a variable-size bag of instance embeddings into one vector. In batched training, bags are padded to a common length, and the pooled output is expected not to depend on how much padding was added or on the order in which instances are stored. This expectation holds only if padded rows are removed from both the numerator and the softmax normalizer. Common implementation idioms meet it only under side conditions. Zeroing padded features alone does not work. Masking logits with −∞-\infty fails on empty bags and on nonfinite padding. Masking with a large negative constant is exact only after floating-point underflow. We define masked attention pooling with a guarded normalizer and prove in Lean 4 with mathlib that it is invariant under any bijective reindexing of rows and under appending any finite number of masked rows with arbitrary real features and logits. We also prove that values at masked positions are irrelevant and that an all-masked bag maps to zero. The theorems hold for arbitrary finite index types and feature dimensions. Using the jax-lean certificate pipeline, we connect these theorems to the Jaxpr traced from the JAX kernel itself. Lean checks translation certificates for two concrete shapes, identifies the generated functions with the generic specification, and transfers both invariances to the imported Jaxpr's real-arithmetic semantics. All audited theorems depend only on Lean's three standard axioms. The results concern ideal real arithmetic. Floating-point execution, XLA, and the JAX tracer and importer remain outside the proof.

Figures & tables

Explore similar work

CardsList
  1. The Mask Is Not the Model: Auditing Prefix Invariance in Attention, State-Space, and Hybrid Sequence Models

    Aug 24, 2026Taebong Kim, Youngsik Hong, Minsik Kim +3LLM AuditingSequence Modeling

  2. MLIPS: Multi-Layer Indexer Pool Sharing

    Oct 20, 2026Samkit Jain, Sai Kishan Pampana, Shlok Agarwal +4LLM Inference AccelerationSparse Attention