Skip to content

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 -- MinCutConfig with sane out-of-the-box parameters

Dependencies

Key internal dependencies:

  • serde / serde_json -- serialization of config and witness entries
  • sha2 -- 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

TypeDescription
MinCutConfigConfiguration for min-cut gating thresholds and parameters
AttentionOutputResult of an attention computation (gated or softmax)
AttentionGraphWeighted directed graph built from attention logits
EdgeA single weighted edge in the attention graph
DinicSolverDinic's max-flow algorithm implementation
CutResultResult of a min-cut computation
GatingResultWhich edges survived the min-cut gate
HysteresisTrackerTemporal smoothing of gating decisions
WitnessEntryLogged witness record with SHA-256 hash

Released under the MIT License.