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

Flash Cosine Sim Attention

Flash Cosine Sim Attention is a Python library implementing fused cosine-similarity attention in the style of Flash Attention. It uses L2-normalized queries and keys and exposes a function for self-attention, cross-attention, masked and causal calls, and single-headed keys and values.

Independent OpenViST project profile, based on linked sources.

Flash Cosine Sim Attention — 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 it when researching or prototyping cosine-similarity attention and when the documented PyTorch examples match the model's attention inputs. Evaluate both model quality and hardware-specific performance before relying on it.

Who it is for

  • Deep-learning developers prototyping attention mechanisms in Python models.
  • Researchers comparing cosine-similarity attention behavior across sequence types and model tasks.

Documented uses

  • Replace or compare an attention operation with a fused cosine-similarity implementation.
  • Prepare self-attention or cross-attention calls, including causal and key/value-masked examples.
  • Explore operations on normalized queries and keys before the attention step.
Before you choose

Requirements & limits

The project is a public GitHub repository and declares an MIT license. Its README documents installation with pip.

  • The README reports worse evaluation FID scores in experiments, despite losses not reflecting the difference, and advises caution.
  • The project says autoregressive and variable-length cases may be faster, while non-autoregressive unmasked attention remains slower on an A100 for F16.
  • For sequences longer than 2,048, the README describes memory efficiency relative to regular attention; older graphics cards may involve a speed-versus-memory tradeoff.
  • The documented examples use PyTorch tensors on CUDA.

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

Install the library and prepare a self-attention call

Install the package and prepare the documented PyTorch self-attention example with CUDA tensors.

Before you start

  • Python package installation via pip
  • PyTorch
  • CUDA tensors, as used in the repository example

Steps

  1. Install the package with the command below.

    Documented command
    pip install flash-cosine-sim-attention
  2. Import torch and flash_cosine_sim_attention from flash_cosine_sim_attention.

  3. Create query, key and value tensors with the documented shape (1, 8, 1024, 64) on CUDA.

  4. Pass the three tensors to flash_cosine_sim_attention as shown in the self-attention example.

Expected outcome

The documented example calls the attention function with query, key and value tensors and shows an output shape of `(1, 8, 1024, 64)`.

Guide limitations

  • The guide reflects the repository example and does not establish hardware compatibility or performance.
  • The project labels the implementation work in progress and advises caution because evaluation FID scores were reported as worse in experiments.
Source-based practical guide

Prepare a causal cross-attention call

Use the documented function signature and tensor shapes for causal cross-attention.

Before you start

  • PyTorch
  • CUDA tensors, as used in the repository example

Steps

  1. Import torch and flash_cosine_sim_attention from flash_cosine_sim_attention.

  2. Create a query tensor with shape (1, 8, 1024, 64) and key and value tensors with shape (1, 8, 2048, 64), on CUDA.

  3. Call flash_cosine_sim_attention(q, k, v, causal=True).

Expected outcome

The README example shows an output shape of `(1, 8, 1024, 64)` for this causal cross-attention call.

Guide limitations

  • This describes the documented example only and does not establish compatibility or benchmark results.
  • The repository notes that performance varies by attention workload and hardware.
Evidence and transparency

Sources & review

Source record details
Source availability
Active
Sources checked
8 October 2026
Original website title
lucidrains/flash-cosine-sim-attention · Official homepage title · retained in its source language