code wiki / (root) / nx_attribution.nx

nx_attribution.nx

buildroot/runtime/nx_attribution.nx

11857 B309 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_tensor.nx nx_attribution.nx

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

main sys_mmap nx_t_alloc nx_dt_is_valid nx_dt_element_bytes sys_mmap ↻ nx_t_compute_strides_rowma nx_attr_matmul_topk nx_t_is_contiguous _attr_abs nx_attr_verdict_is_valid

structs

none

consts

83const NX_MAGIC_1024: i64 = 1024
85const NX_ATTR_NEG_INF: i64 = -9223372036854775807
89const NX_ATTR_OK: nx_int = 0
90const NX_ATTR_ERR_BAD_DTYPE: nx_int = 1
91const NX_ATTR_ERR_BAD_NDIM: nx_int = 2
92const NX_ATTR_ERR_SHAPE_MISMATCH: nx_int = 3
93const NX_ATTR_ERR_BAD_K: nx_int = 4
94const NX_ATTR_N_VERDICTS: nx_int = 5

functions

96func nx_attr_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
104func _attr_abs(x: i64) -> i64
called by 1: nx_attr_matmul_topk
121func nx_attr_matmul_topk(W: *NxTensor, x: *NxTensor, y: *NxTensor,
called by 1: main calls 2: nx_t_is_contiguous_attr_abs
218func nx_attr_explain(attr_idx: *i64, attr_val: *i64,
254func main() -> i64