nx_attribution.nx
buildroot/runtime/nx_attribution.nx
about
nx_attribution.nx -- per-output bottom-up contribution tracking.
User correction 2026-05-16: "your feedback is top down not bottom
up as well i dont know wtf the bits are doing and no system
exposes that thats the point of all the nishi lang no more black
boxes or secrets".
THIS primitive is the bits-up answer. For linear/matmul-class
operations, the substrate EMITS what every contribution was --
signed, ranked, named-input -- so callers can ASK "which input
contributed most to this output?" and get an exact answer at
full bit precision.
No black boxes. No hidden activations. No post-hoc inference
from outputs. The substrate exposes the bits.
===== Why this matters ===========================================
Every existing ML stack stores tensors as opaque blocks. When
output[i] = 0.7, no one knows which input element was responsible.
Mechanistic-interpretability research (Olah, Conmy, Nanda 2022+;
Anthropic's circuits) reverse-engineers this MANUALLY for tiny
models. Production stacks ship without it.
NishiLang substrate makes attribution a first-class primitive:
any matmul / linear / attention op can be called with attribution
recording on, and the substrate emits the (input_idx, contribution)
pairs that produced each output.
===== Math =======================================================
For y = W @ x where y is [M], x is [N], W is [M, N]:
y[i] = sum_{j=0..N} W[i, j] * x[j]
Each (j, W[i, j] * x[j]) pair is one contribution. We store the
top-K largest-by-absolute-magnitude per output element. Signed:
contribution[i, k] = W[i, j*] * x[j*] where j* is the k-th rank.
For attention output[i, d] = sum_j attn_weights[i, j] * V[j, d]:
dependencies 4 imports · 0 importers
imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_tensor.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 83 | const NX_MAGIC_1024: i64 = 1024 |
| 85 | const NX_ATTR_NEG_INF: i64 = -9223372036854775807 |
| 89 | const NX_ATTR_OK: nx_int = 0 |
| 90 | const NX_ATTR_ERR_BAD_DTYPE: nx_int = 1 |
| 91 | const NX_ATTR_ERR_BAD_NDIM: nx_int = 2 |
| 92 | const NX_ATTR_ERR_SHAPE_MISMATCH: nx_int = 3 |
| 93 | const NX_ATTR_ERR_BAD_K: nx_int = 4 |
| 94 | const NX_ATTR_N_VERDICTS: nx_int = 5 |
functions
| 96 | func nx_attr_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 104 | func _attr_abs(x: i64) -> i64 called by 1: nx_attr_matmul_topk |
| 121 | func nx_attr_matmul_topk(W: *NxTensor, x: *NxTensor, y: *NxTensor, |
| 218 | func nx_attr_explain(attr_idx: *i64, attr_val: *i64, |
| 254 | func main() -> i64 |