OpenViSTAI · Agents · Blockchain · Crypto
Menu
AI Developer Tools & SDKs

Linformer

Linformer is an MIT-licensed Python/PyTorch library implementing Linformer attention, with a language-model component, a transformer module and reusable self-attention layers that project keys and values along the sequence dimension.

Independent OpenViST project profile, based on linked sources.

Linformer — OpenViST project profile in AI Developer Tools & SDKs.
OpenViST project illustration. See the linked sources for product details.
Understand the project

Practical overview

When it fits

Use Linformer when developing PyTorch models for inputs with a known, fixed sequence length and you want a complete language-model or transformer component, or a reusable self-attention layer. The contextual-keys interface is relevant when the context sequence differs in length from the input.

Who it is for

  • PyTorch developers prototyping language models for fixed-length inputs.
  • Researchers and engineers comparing key/value projection and sharing configurations.
  • Developers integrating a Linformer self-attention layer into an encoder or using a separate contextual-key sequence.

Documented uses

  • Build a Linformer language-model prototype with a specified vocabulary size, sequence length, depth and number of heads.
  • Use the provided transformer module to map fixed-length feature sequences to output feature sequences.
  • Add a single Linformer self-attention layer to a model.
  • Configure key/value projection size, head sharing and projection sharing.
  • Apply the attention layer to an input sequence with a distinct context sequence.
Before you choose

Requirements & limits

The repository is public and lists an MIT license. Its README gives `pip install linformer` as the installation command.

  • The implementation assumes a fixed sequence length, so the configured length matters.
  • The README states that the implementation does not work for autoregressive use.
  • The k parameter controls the sequence-dimension projection size for keys and values.
  • The contextual-keys example validates sequence length against the context rather than the source input.

Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.

Source-based practical guide

Set up a Linformer self-attention layer

Install the package and configure a single self-attention layer for a fixed-length PyTorch input.

Before you start

  • Python environment with PyTorch available.
  • Input feature dimension and sequence length for the layer.

Steps

  1. Install the package with the command below.

    Documented command
    pip install linformer
  2. Import LinformerSelfAttention from linformer.

  3. Construct the layer with the input dimension, fixed sequence length, head count and projection size k.

  4. Pass an input tensor shaped as batch, sequence length and feature dimension to the layer.

Expected outcome

A configured self-attention layer that returns an output with the same sequence and feature dimensions as the example input.

Guide limitations

  • The implementation assumes a fixed sequence length.
  • The README says it does not work for the autoregressive case.
Source-based practical guide

Configure attention with a separate context sequence

Set up the documented self-attention interface with contextual keys whose sequence length differs from the input.

Before you start

  • Python environment with PyTorch available.
  • Input and context tensors with the same feature dimension.
  • A configured context sequence length.

Steps

  1. Install the package with the command below.

    Documented command
    pip install linformer
  2. Import LinformerSelfAttention and configure its seq_len to the context length.

  3. Pass the input tensor and context tensor to the layer.

Expected outcome

The example produces an output aligned to the input sequence length; the configured sequence length is validated against the contextual keys.

Guide limitations

  • The implementation assumes a fixed sequence length.
  • The README says it does not work for the autoregressive case.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
15 October 2026
Original website title
lucidrains/linformer · Official homepage title · retained in its source language