nx_activation_steer.nx
buildroot/runtime/nx_activation_steer.nx
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
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
| 81 | const NX_MAGIC_1024: i64 = 1024 |
| 82 | const NX_MAGIC_2024: i64 = 2024 |
| 83 | const NX_MAGIC_2048: i64 = 2048 |
| 84 | const NX_MAGIC_3048: i64 = 3048 |
| 86 | const NX_AS_Q10: nx_int = 1024 |
| 90 | const NX_AS_OK: nx_int = 0 |
| 91 | const NX_AS_ERR_BAD_DTYPE: nx_int = 1 |
| 92 | const NX_AS_ERR_BAD_NDIM: nx_int = 2 |
| 93 | const NX_AS_ERR_SHAPE_MISMATCH: nx_int = 3 |
| 94 | const NX_AS_ERR_NOT_CONTIGUOUS: nx_int = 4 |
| 95 | const NX_AS_N_VERDICTS: nx_int = 5 |
functions
| 97 | func nx_as_verdict_is_valid(v: nx_int) -> nx_int {
called by 1: main |
| 111 | func nx_activation_steer_apply(hidden: *NxTensor, steer: *i64, |
| 152 | func nx_activation_steer_apply_multi(hidden: *NxTensor, |
| 205 | func nx_activation_steer_derive(target_act: *NxTensor, anti_act: *NxTensor,
called by 1: main |
| 256 | func main() -> i64 { |