code wiki / (root) / nx_activation_steer.nx

nx_activation_steer.nx

buildroot/runtime/nx_activation_steer.nx

13586 B341 linesdepth 4pulls 5 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_activation_steer.nx -- activation steering primitive. First patch-composted-into-substrate primitive per cardinal feedback-loras-and-negatives-are-patches-not-systems (patches-as-manure refinement 2026-05-16): User: "im not against patches but patches are manure that should become architectural decisions to increase capability speed etc in the native stack" THE patch we're composting: - Negative prompts ("ugly, deformed, blurry, bad anatomy") -- a shotgun list of anti-features that the model never had measurable knowledge of. Folk-knowledge attractors. THE substrate capability we ship instead: - Per-layer ACTIVATION STEERING (Turner 2023 ActAdd / Zou 2023 Representation Engineering). Given a "steering vector" -- the difference between activations on two contrasting prompts at a chosen layer -- ADD it to forward-pass activations to bias output in the desired direction. Architectural advantages over negative prompts: 1. Per-token control. Steering is applied at every forward pass, not just at sampling time. No "first token escapes negative prompt" failure mode. 2. Composable. Multiple steering vectors can be added (e.g. "less violence + more cheerful + more detailed") with per-vector strength weights. 3. Measurable. The substrate can VERIFY the steering had the intended effect by composing nx_monte_carlo + nx_multivariate over generations with vs without steering applied. 4. Patent-clean. Vector arithmetic; no LoRA training, no negative-prompt grimoires. ===== Math ====================================================== Given hidden activations h [n_tokens, hidden_dim] at some layer L,

dependencies 4 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_tensor.nx nx_activation_steer.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_activation_steer_apply nx_t_is_contiguous nx_activation_steer_apply_ nx_t_is_contiguous ↻ nx_activation_steer_derive nx_as_verdict_is_valid

structs

none

consts

81const NX_MAGIC_1024: i64 = 1024
82const NX_MAGIC_2024: i64 = 2024
83const NX_MAGIC_2048: i64 = 2048
84const NX_MAGIC_3048: i64 = 3048
86const NX_AS_Q10: nx_int = 1024
90const NX_AS_OK: nx_int = 0
91const NX_AS_ERR_BAD_DTYPE: nx_int = 1
92const NX_AS_ERR_BAD_NDIM: nx_int = 2
93const NX_AS_ERR_SHAPE_MISMATCH: nx_int = 3
94const NX_AS_ERR_NOT_CONTIGUOUS: nx_int = 4
95const NX_AS_N_VERDICTS: nx_int = 5

functions

97func nx_as_verdict_is_valid(v: nx_int) -> nx_int {
called by 1: main
111func nx_activation_steer_apply(hidden: *NxTensor, steer: *i64,
called by 1: main calls 1: nx_t_is_contiguous
152func nx_activation_steer_apply_multi(hidden: *NxTensor,
called by 1: main calls 1: nx_t_is_contiguous
205func nx_activation_steer_derive(target_act: *NxTensor, anti_act: *NxTensor,
called by 1: main
256func main() -> i64 {