Skip to content

@smartpointstech/attention

Flash Attention and geometric attention mechanisms - built in Rust for high-performance neural inference

Overview

This package provides native Node.js bindings to the spt-attention Rust crate. It exposes multiple attention mechanism implementations including scaled dot-product, multi-head, flash, geometric (hyperbolic), graph, sparse, and linear attention. A pure-JS stub fallback is used when native bindings are not installed.

Installation

bash
npm install @smartpointstech/attention

Key Features

  • Scaled Dot-Product Attention -- standard softmax(QK^T / sqrt(d)) V computation
  • Multi-Head Attention -- splits Q/K/V across configurable attention heads
  • Flash Attention -- memory-efficient tiled attention with optional causal masking
  • Geometric Attention -- hyperbolic-space attention with configurable curvature
  • Graph Attention -- GAT-style attention with LeakyReLU scoring
  • Sparse and Linear Attention -- windowed sparse and kernel-approximated linear variants

Dependencies

No internal npm dependencies. Uses platform-specific native binaries via optional dependencies (e.g., spt-attention-darwin-arm64). Built with @napi-rs/cli.

Quick Start

typescript
import { ScaledDotProductAttention, MultiHeadAttention } from '@smartpointstech/attention';

const sdpa = new ScaledDotProductAttention(64);
const output = sdpa.compute(query, keys, values);

const mha = new MultiHeadAttention({ dim: 128, numHeads: 8 });
const result = mha.compute(query, keys, values);

API Reference

Exports

ExportTypeDescription
ScaledDotProductAttentionclassStandard scaled dot-product attention
MultiHeadAttentionclassMulti-head attention with configurable heads
FlashAttentionclassMemory-efficient tiled flash attention
GeometricAttentionclassHyperbolic-space geometric attention
GraphAttentionclassGAT-style graph attention with LeakyReLU
SparseAttentionclassWindowed sparse attention
LinearAttentionclassKernel-approximated linear attention
getImplementationTypefunctionReturns 'native' or 'stub'

Released under the MIT License.