spt-attn-mincut
Min-cut gating attention operator: dynamic graph-based alternative to softmax attention
Overview
spt-attn-mincut replaces uniform softmax attention with a graph-theoretic min-cut gate. It builds a weighted directed graph from Q*K^T logits, computes a minimum cut via Dinic's max-flow algorithm to prune irrelevant edges, then normalises surviving edges with row-softmax before multiplying by V. This fits into the SPT ML pipeline as an alternative attention mechanism for transformer inference.
Key Features
- Graph construction -- builds weighted directed graphs from attention logits
- Dinic's max-flow / min-cut -- solver for gating irrelevant attention edges
- Temporal hysteresis -- stabilises gating decisions over time to avoid oscillation
- Witness logging -- SHA-256 hashed determinism verification for reproducibility
- Configurable defaults --
MinCutConfigwith sane out-of-the-box parameters
Dependencies
Key internal dependencies:
serde/serde_json-- serialization of config and witness entriessha2-- SHA-256 hashing for witness determinism verification
Usage
rust
use spt_attn_mincut::{attn_mincut, MinCutConfig, AttentionOutput};
let config = MinCutConfig::default();
// Build logits matrix, then apply min-cut gated attention
// let output = attn_mincut(&q, &k, &v, &config);API Reference
Core Types
| Type | Description |
|---|---|
MinCutConfig | Configuration for min-cut gating thresholds and parameters |
AttentionOutput | Result of an attention computation (gated or softmax) |
AttentionGraph | Weighted directed graph built from attention logits |
Edge | A single weighted edge in the attention graph |
DinicSolver | Dinic's max-flow algorithm implementation |
CutResult | Result of a min-cut computation |
GatingResult | Which edges survived the min-cut gate |
HysteresisTracker | Temporal smoothing of gating decisions |
WitnessEntry | Logged witness record with SHA-256 hash |