@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/attentionKey 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
| Export | Type | Description |
|---|---|---|
ScaledDotProductAttention | class | Standard scaled dot-product attention |
MultiHeadAttention | class | Multi-head attention with configurable heads |
FlashAttention | class | Memory-efficient tiled flash attention |
GeometricAttention | class | Hyperbolic-space geometric attention |
GraphAttention | class | GAT-style graph attention with LeakyReLU |
SparseAttention | class | Windowed sparse attention |
LinearAttention | class | Kernel-approximated linear attention |
getImplementationType | function | Returns 'native' or 'stub' |