Papers
Topics
Authors
Recent
Search
2000 character limit reached

FlexFormer: Adaptive Compression, Flexure & Transformers

Updated 4 July 2026
  • FlexFormer is a multifaceted research concept spanning adaptive compression in long video generation, strain-energy-based flexure synthesis, and learnable-kernel Transformer attention.
  • It implements domain-specific methodologies, including a context-compression autoencoder in LoViC, a self-adjoint formulation for topology optimization, and trainable Fourier features in Transformers.
  • Its versatile applications address computational challenges across multimodal video processing, mechanical flexure design, and efficient sequence modeling.

FlexFormer is a polysemous research label rather than a single canonical method. In recent arXiv literature, it denotes at least three distinct technical constructs: a context-compression autoencoder inside the long-video generation framework LoViC; a strain-energy-based topology optimization formulation for short-stroke flexure synthesis; and a linear-time Transformer with learnable attention kernels based on random Fourier features. The shared name reflects different notions of flexibility—variable-length multimodal compression, versatile flexure design, and data-adaptive kernelized attention—rather than a unified research lineage (Jiang et al., 17 Jul 2025).

1. Terminological scope and disambiguation

The term has appeared in substantially different domains, with different mathematical objects, objectives, and implementation stacks. Treating these as a single method is a common source of confusion.

Usage Domain Defining role
FlexFormer Long video generation Flexible autoencoder that jointly compresses video and text into unified latent representations (Jiang et al., 17 Jul 2025)
FlexFormer Topology optimization Self-adjoint strain-energy-based formulation for short-stroke flexure synthesis (Koppen et al., 2021)
Flexformer Efficient Transformers Flexible linear Transformer with learnable attention kernel (Zhang et al., 26 Jun 2026)

A further source of ambiguity is neighboring work on flexible structures. The paper "Shear-flexible geometrically exact beam element based on finite differences" studies a flexibility-based beam formulation and is explicitly framed as relevant to a “FlexFormer”-style query, but it does not introduce a method named FlexFormer (Jirasek et al., 2024). This suggests that, in mechanical-design contexts, lexical overlap with “flexure,” “flexibility-based,” or “flexible” formulations can obscure whether the reference is to a specific named framework or to a broader design philosophy.

2. FlexFormer in LoViC: context compression for long video generation

Within LoViC, FlexFormer is the key compression module that makes long-video generation practical by compressing arbitrary-length video-text history into a much shorter latent context before decoding with a diffusion transformer (Jiang et al., 17 Jul 2025). LoViC addresses the quadratic cost of vanilla self-attention in long spatiotemporal token sequences by decomposing generation into a segment-wise process: previous video segments and their prompts are compressed by FlexFormer, concatenated, and injected into the DiT to generate the next segment.

The architecture has two parts: a FlexFormer encoder, which compresses input video and text tokens into compact context tokens, and a FlexFormer decoder, which reconstructs video and text features from those compressed tokens. A central design decision is that the latent is unified across modalities: each context pair (Videoi,Texti)(\text{Video}_i,\text{Text}_i) is encoded into Contexti\text{Context}_i, and the resulting latents are concatenated for conditioning. The latent therefore functions as a joint video-text context representation rather than as visual memory alone.

The paper identifies two specific limitations of a standard Q-Former-style design. First, cross-attention prevents RoPE usage, so spatial structure across context tokens cannot be naturally encoded. Second, a fixed number of learnable queries can lose too much information when the context grows long. FlexFormer addresses both by replacing a fixed query bank with a single learnable query token that is replicated as needed, and by introducing Interpolated-RoPE (I-RoPE) for spatiotemporal position assignment to query tokens.

This design supports arbitrary-length inputs and linearly adjustable compression rates. Instead of hard-coding a fixed latent capacity, the number of replicated query tokens is determined by the total number of input tokens and the target compression ratio. For decoding, two learnable query tokens—one for video and one for text—are replicated to match the original modality lengths.

3. Positional mechanisms, temporal tasks, and empirical behavior in LoViC

FlexFormer departs from vanilla Q-Former cross-attention by adopting a self-attention-based encoding scheme inspired by MMDiT: query tokens and input tokens are concatenated and processed jointly (Jiang et al., 17 Jul 2025). This permits RoPE-style positional encoding over the whole sequence and is presented as crucial for preserving spatial awareness among video tokens.

The positional construction builds from RoPE and M-RoPE. For 3D video tokens with position p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w) and embedding split as x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}, M-RoPE applies RoPE independently along temporal, height, and width axes:

M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).

FlexFormer then introduces I-RoPE by assigning each replicated query token an interpolated spatiotemporal coordinate:

I-RoPE(qi)=M-RoPE(qi,(pt(i),ph(i),pw(i))),\text{I-RoPE}(q_i)=\text{M-RoPE}(q_i,(p_t^{(i)},p_h^{(i)},p_w^{(i)})),

with

(pt(i),ph(i),pw(i))=Interpolate(i;T,H,W,N).(p_t^{(i)},p_h^{(i)},p_w^{(i)})=\text{Interpolate}(i;T,H,W,N).

According to the paper, this explicit spatial prior significantly improves reconstructions and downstream video continuity; without it, outputs often become blurrier.

Compression is not fixed. Query copies can be distributed according to uniform, linear, or logarithmic strategies. The paper particularly emphasizes linear compression, in which query-token density is linearly scaled with respect to time, preserving more detail near frames adjacent to the current segment and allowing stronger compression farther away. An empirical conclusion is that downstream DiT performance depends more on how context is compressed than on raw autoencoder reconstruction quality in isolation. The reported best balance of efficiency and generation quality comes from linear compression.

Because LoViC represents generation tasks through temporal arrangement and positional indexing rather than through task-specific decoders, the same FlexFormer-plus-DiT stack supports prediction, retrodiction, interpolation, and multi-shot generation (Jiang et al., 17 Jul 2025). For multi-shot generation, the model introduces a temporal gap between shots in positional space so that scene transitions are interpreted as shot boundaries rather than accidental discontinuities. Ablations compare variants including M-RoPE plus multiple query tokens, M-RoPE plus a single query token, I-RoPE plus a single query token, and I-RoPE plus an MLP query. The best reconstruction is reported for I-RoPE plus a single query token, and adding an extra MLP before the query tokens slightly hurts performance.

4. FlexFormer as a topology optimization formulation for flexure synthesis

In the topology optimization literature, FlexFormer denotes a strain-energy-based formulation for the synthesis of short-stroke flexures, not a neural architecture (Koppen et al., 2021). The formulation is built around prescribed rigid-link relative motions, called mechanism degrees, and uses strain energy under prescribed displacements to evaluate whether those motions should be compliant or stiff.

The design domain is discretized into finite elements with design variables xjX:={xR0<x1}x_j\in\mathcal{X}:=\{x\in\mathbb{R}\mid 0<x\leq1\}, and the mechanism is described by a set of prescribed relative motions D\mathbb{D}. This set is partitioned into degrees of constraint C\mathbb{C}, which should be stiff, and degrees of freedom Contexti\text{Context}_i0, which should remain compliant. The optimization problem is

Contexti\text{Context}_i1

Here Contexti\text{Context}_i2 is the mechanism-degree strain energy,

Contexti\text{Context}_i3

with displacement fields obtained from

Contexti\text{Context}_i4

The central modeling choice is that each mechanism degree is posed as a prescribed displacement scenario at the rigid-link interfaces. In 2D, the paper uses Contexti\text{Context}_i5, Contexti\text{Context}_i6, and Contexti\text{Context}_i7 as common relative motions. Under this interpretation, higher strain energy under prescribed displacement means higher stiffness in that mechanism degree. The objective therefore maximizes stiffness in the DOCs while inequality constraints keep DOF stiffness below allowable limits.

To combine multiple DOCs, the paper normalizes strain energies relative to their initial values,

Contexti\text{Context}_i8

and uses a sum objective

Contexti\text{Context}_i9

This removes dependence on the absolute magnitudes of the prescribed displacement cases across different DOCs.

5. Self-adjoint structure, implementation, and demonstrated scope in flexure synthesis

A major claim of the flexure-synthesis FlexFormer is that the problem is self-adjoint, because the structural responses are strain energies under prescribed displacements in a linear elastic setting (Koppen et al., 2021). The paper states that, for specific optimization responses such as strain energy, no separate adjoint problem is required. Sensitivities therefore retain the favorable structure of classic compliance minimization:

p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)0

where p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)1 is elemental strain energy and p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)2 is a multiplicative factor.

The implementation uses SIMP interpolation,

p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)3

with Young’s modulus interpolation

p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)4

The optimization is solved in a sequential approximate optimization framework using MMA, with convex subproblems solved by a primal-dual interior-point method and stopping controlled by a maximum design-change threshold p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)5. The paper also introduces a robust extension based on eroded and dilated designs,

p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)6

and a stress-constrained extension,

p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)7

The formulation is described as simple because it uses only strain energy measures, requires very few tuning parameters, and avoids static condensation, additional artificial stiffnesses, and many user-defined parameters. It is described as versatile because it applies to single-axis and multi-axis flexures, in both 2D and 3D, with arbitrary sets of unique mechanism degrees. It is described as computationally efficient because cost per design iteration is essentially one factorization or preconditioning step and one solve per considered degree, and because the self-adjoint structure keeps sensitivity computation cheap.

The paper demonstrates 2D prismatic joints, revolute joints, and multi-axis mechanisms such as doc=tx, dof=ty, doc=rz, dof=[tx,ty], and doc=[ty,rz], dof=tx, as well as 3D cases including doc=[rz], dof=[tx,ty,tz,rx,ry], doc=[tx,ty,tz,rz], dof=[rx,ry], and doc=[tx,ty,rx,ry,rz], dof=[tz] (Koppen et al., 2021). It also provides MATLAB code through the supplementary-material function I-RoPE(qi)=M-RoPE(qi,(pt(i),ph(i),pw(i))),\text{I-RoPE}(q_i)=\text{M-RoPE}(q_i,(p_t^{(i)},p_h^{(i)},p_w^{(i)})),0 as an extension of top71.m, together with COMSOL .mph files and STL CAD models for some examples.

6. Flexformer as a learnable-kernel linear Transformer

In sequence modeling, Flexformer is a linear-time Transformer attention mechanism that replaces fixed or weakly learnable linear-attention kernels with a fully learnable kernel built from random Fourier features (Zhang et al., 26 Jun 2026). The objective is to retain the efficiency of kernelized linear attention while making the attention pattern substantially more expressive and data-adaptive.

Standard attention over a sequence of length p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)8 has time complexity p=(pt,ph,pw)\mathbf{p}=(p_t,p_h,p_w)9 and space complexity x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}0. Kernel-based linear attention rewrites attention through a feature map x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}1 satisfying

x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}2

so that the output becomes

x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}3

with time x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}4 and space x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}5, where x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}6 is the feature-map dimension.

The paper begins from the softmax kernel and isolates its Gaussian component, then uses random Fourier features to approximate the stationary part. The key contribution is to make the Fourier frequencies trainable rather than fixed. Because stationary kernels and spectral densities are in one-to-one correspondence through Bochner’s theorem, learning the kernel is equivalent to learning the spectral distribution. In the stationary variant, x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}7, the feature map is

x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}8

with softmax-style scaling

x=x(t)x(h)x(w)\mathbf{x}=\mathbf{x}^{(t)}\oplus \mathbf{x}^{(h)}\oplus \mathbf{x}^{(w)}9

The nonstationary variant, M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).0, generalizes the kernel family via Yaglom’s theorem. It learns spectral pairs M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).1 and a scaling parameter M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).2, using a generalized norm factor

M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).3

The paper states that the nonstationary variant is strictly more expressive than the stationary one, because it can encode location-dependent interactions rather than depending only on differences M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).4.

7. Empirical results, distillation, and recurring misconceptions

Flexformer can be trained from scratch or distilled from a pretrained Transformer (Zhang et al., 26 Jun 2026). In the distillation setting, a pretrained RoBERTa has its attention replaced by Flexformer attention, the pretrained weights are frozen, and only the kernel parameters are trained for about 20,000 steps using an attention-weight cross-entropy loss. The paper presents this as evidence that Flexformer can recover softmax attention very closely while preserving linear-attention structure.

On long-sequence classification in the LRA benchmark, M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).5 achieves the best average accuracy and M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).6 ranks second overall, with the paper reporting roughly a 4.4% relative improvement over the best prior linear-attention baseline on average (Zhang et al., 26 Jun 2026). On document retrieval, Flexformer achieves about a 2.6× training speedup and 84% memory reduction relative to vanilla Transformer. On WikiText-103 language modeling, the reported test perplexities for big models are 23.8 for vanilla Transformer, 23.4 for M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).7, and 22.3 for M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).8. On GLUE after distillation, the average performance is reported as 83.3 for Hedgehog and 83.7 for M-RoPE(x,p)=RoPE(x(t),pt)RoPE(x(h),ph)RoPE(x(w),pw).\text{M-RoPE}(\mathbf{x},\mathbf{p}) = \text{RoPE}(\mathbf{x}^{(t)},p_t)\oplus \text{RoPE}(\mathbf{x}^{(h)},p_h)\oplus \text{RoPE}(\mathbf{x}^{(w)},p_w).9, with Flexformer surpassing the original softmax RoBERTa on CoLA. The paper also reports stronger kernel transferability than Hedgehog across all target tasks, with especially strong gains on CoLA, MRPC, MNLI, and RTE.

Several misconceptions recur across the literature. First, FlexFormer in LoViC is not the DiT decoder; it is the context compressor placed before the DiT (Jiang et al., 17 Jul 2025). Second, the topology-optimization FlexFormer is not a Transformer model at all; it is a self-adjoint prescribed-displacement formulation for flexure synthesis (Koppen et al., 2021). Third, sequence-modeling Flexformer is not merely a fixed approximation to softmax attention; it learns the kernel itself by optimizing spectral frequencies (Zhang et al., 26 Jun 2026). A plausible implication is that the shared name persists because all three usages prioritize adaptive compression or representation under computational constraints, but the methods are otherwise domain-specific and technically noninterchangeable.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to FlexFormer.