Skip to content

Living Weights as a core module: the learner, pocket and fits in zig/src/living, a family described as data (Nemotron only) - #878

Merged
ashhart merged 2 commits into
ashhart:mainfrom
ZackSample:lw-b-core
Oct 18, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
ZackSample:lw-b-core

Conversation

@ZackSample

Copy link
Copy Markdown
Contributor

What this changes

Following your note on #472 (the core builds each step once and a family plugs in), this moves Living Weights out of
families/nemotron into a living module that both builds import. A family then describes itself as data and hands the
learner a few hooks. Nemotron is the only family listed, and nothing it does changes.

  1. The move, with no content change (5a4987b7). The learner, its whole-lesson and routed paths, the pocket and its
    fits and helpers (19 files) are git mv'd to zig/src/living/, and GitHub shows each as a 100% rename. The
    family-neutral half of learn_shape.zig (block sizes, Adam settings, direction lengths) moves with them. Nemotron's
    learn_shape.zig keeps where its blocks sit and names the shared constants from the module. Nemotron's files import
    the moved ones as @import("living").x. build.zig and zig/build/cuda.zig add the module, and its tests run on
    Linux as zig build test-living and under test-cuda-host.
  2. The generalisation (75978a1c).
    • living/families.zig: a family as data. That means its shared experts' tensor names and where they sit, the
      neuron's activation (relu^2, or SwiGLU with an optional per-row gate), its affine format (bits, group), its config
      keys and the object they sit in, and its MTP head's expert. Only nemotron_h is listed.
    • living/family.zig: Family, Layout (the layers a pocket widens and learns at) and the hooks a host gives
      (below).
    • The pocket reads its width and layers from the host's layout(), not from Nemotron's config. The learner offers
      routed blocks, edits and probes only to a trainer with sites, which only Nemotron's has.
    • living/shards.zig widens any family's experts at its own group and width, through living/affine.zig (MLX
      affine at any bits and group). A test shows it writes exactly affine4_host's codes, scales and biases at 4 bits
      in groups of 64. Nemotron's pocket_shards.zig is now a wrapper over it, and its existing save test passes
      unchanged. shard_edit reads and sets config keys inside a nested object (text_config).
    • living/neuron.zig: a SwiGLU neuron fitted as u is written as gate row 16u and up row u/16, so it adds
      (u x)^2 sigmoid(16 u x). That is relu(u x)^2 within 1e-7 on its fact's rows, and at most 8e-5 of it at a 0.5
      margin. A gated family's outputs are fitted as gate * act(x). No listed family uses SwiGLU yet. Its tests use a
      stand-in family shaped as Qwen3.8 Flash Next's shared expert (living/test_families.zig), and Flash Next itself
      comes in a later PR.
    • The server's Living Weights view reads layers, pockets and shards through the family its model_type names.
      native/nemotron_slide.zig is now native/slide_adapter.zig.
    • For the 600-line rule, pocket.zig's quiet refit and its loading move to pocket_quiet.zig and pocket_load.zig.

What a host gives the learner (this was a block comment in family.zig, which the one-line rule does not allow):

  • host: Trainer, max_rows, Ctx, family, layout(ctx), trainer(gpa, io, ctx), free(t, gpa),
    seconds(io). For the pocket:

    • relu^2: pocket(ctx, layer, up, down, used), pocketRead(ctx, layer, up, down) usize and
      pocketSave(ctx, gpa, io, layers, neurons, up, down) usize;
    • SwiGLU: the same three with a gate beside up.

    up and gate are each neuron's input rows as the forward multiplies them ([neurons, D] f32), and down is its
    output. A save hands the rows back as written. Optional: attach, write and layers (routed blocks), and
    codes, commit and fold4 (weight edits).

  • trainer: normed(layer, row), pass(seqs, mode, turn, out), step(ids, start, mode, turn), spans, packs(),
    pack, count, prefixes, prefixSlots(n), pushAt(i, key, layer), deltaAt(i, key, layer),
    residual(layer, row), nudge and from. A gated family also needs gateAt(layer, row). Nemotron's routed
    blocks, edits and probes additionally use sites, sketched, score(), projected(), key() and config().

It could go in a recipe page beside adding-a-zig-family.md if you want it written down.

Receipt

  • Environment: lw-b-core 75978a1 on main c7137bb (v1.0.11 + 19), Zig 0.17.0; NVIDIA GB10 (DGX Spark, sm_121),
    driver 580.178.04, CUDA 13.0.88, Ubuntu 24.04.5; checkpoint
    TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit revision d9d758fb, a fresh cp -RL copy for each run.
  • No behaviour change, on a GB10. I taught the ten facts of 1.0.8's receipt ("I like blue." to "I am allergic to
    peanuts.") one learn request at a time, with main and with this branch, each on a fresh copy, and probed after every
    lesson. Every probe was two fixed wordings per fact (20 questions) and every learned fact's stored held-out
    questions, at "temperature": 0.
    • After each of the 10 lessons, the sha256 of every .safetensors file and of config.json was the same on both,
      including the first save, which widens the shared experts.
    • Every fact's state and neurons (layer, index, key) in the graph were the same.
    • Every probe reply was the same, byte for byte.
    • Both kept the same 7 facts and answered 13/20 fixed questions after lesson 10, and a plain restart and a --slide
      restart gave the same replies as after lesson 10.
  • Exactness, decode and prompt speed: n/a. Nothing in the forward or in serving changes; the receipt above compares
    what the learner writes.
  • Tests: zig build test on Linux: 781/786 pass, 5 skipped (main: 743/748, 5 skipped; the 38 more are the learner's,
    the pocket's and the shard writer's tests, which no Linux test binary reached before). Both commits build and pass.
    zig fmt --check build.zig zig is clean, and python3 tools/zig/lean_check.py gives 527 problems against 527 on
    main (0 new).
  • Metal: not run on a Mac (I have none). zig build test-native -Dtarget=aarch64-macos and zig build native -Dtarget=aarch64-macos, with a stub xcrun that writes empty metallibs, compile every Zig module and stop only at
    linking Apple's frameworks, the same as on main. So the Metal side type-checks, but a Mac zig build test and a
    Mac lesson (same neurons, same shard hashes as main) are still needed.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No serving
    change.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Not
    touched.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (The same
    shard bytes, receipt above.)
  • Prompt processing is no slower than the last release. (Not touched.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (GB10; Metal
    type-checked only.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (They test new code:
    the generic writer against affine4_host, the SwiGLU rows, a whole lesson over a stand-in host.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

Questions

  • Where should it live: zig/src/living/ as here, or under zig/src/core/?
  • Should each family's Family value live in its own folder (for example families/nemotron/pocket_layout.zig), with
    no central families.zig? The server's view would then need a family registry elsewhere.
  • Is the stand-in SwiGLU family in tests acceptable? Or would you rather SwiGLU wait for the PR that adds Flash Next's
    trainer, leaving this one relu^2 only?

Order with the other Living Weights PRs

This moves the files that the refit fix (#876) and the recheck and take-out fix (#877) change. If those
land first, I will rebase this onto them: A1 already splits quiet() into pocket_quiet.zig, as this does, and A2's
pocket_mark.zig and its writer round() move into living/ and living/shards.zig.

…unchanged

The learner, its whole-lesson and routed paths, the pocket and its fits and helpers move from families/nemotron to a
`living` module that both builds import, as 19 renames with no change to their contents. The family-neutral half of
learn_shape.zig (block sizes, Adam settings, direction lengths) moves with them; Nemotron's learn_shape.zig keeps where
its blocks sit and names the shared constants from the module. Nemotron's files import the moved ones through the
module. The learner's tests now also run on Linux, as `zig build test-living` and under test-cuda-host. No behaviour
change.
… layout, neuron kind and shard format

A family now describes itself once, as data (living/families.zig): where its shared experts sit and their tensor
names, the neuron's activation (relu^2, or SwiGLU with an optional per-row gate), the quantization, the config keys and
the object they live in, and its MTP head's expert. Its host gives the learner a layout and the pocket hooks
(living/family.zig). Nemotron is the one family listed, and its lessons, routed blocks, edits and probes are unchanged.

- The pocket reads its layers and width from the family's layout, not from Nemotron's config, and the learner offers
  routed blocks, edits and probes only to a trainer with `sites` (Nemotron's).
- living/shards.zig widens any family's experts at its group and width; Nemotron's writer is now a wrapper over it.
  shard_edit sets and reads nested config keys (text_config).
- A SwiGLU neuron fitted as u is written as gate row 16u and up row u/16: relu(u x)^2 on its fact's rows, at most 8e-5
  of it at a 0.5 margin; a gated family's outputs fit gate * act(x). No listed family uses it yet; the tests use a
  stand-in family shaped as Qwen3.8 Flash Next's shared expert.
- The server's view reads layers, pockets and shards through the family its config's model_type names, and
  native/nemotron_slide.zig is native/slide_adapter.zig.
- pocket.zig's quiet refit and its loading move to pocket_quiet.zig and pocket_load.zig, for the 600-line rule.
- Tests: the generic writer equals affine4_host at 4 bits in groups of 64, Nemotron's save test over the wrapper, a
  SwiGLU neuron fitted and stored at 4 bits in groups of 32, and a whole pocket lesson over a stand-in host for each
  activation (test-living, also under test-cuda-host).
@ashhart

ashhart commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thank you, @ZackSample. Living Weights as a core module, with each family described as data, is the direction we want. Your receipt makes the move easy to trust: through ten lessons the shard hashes, the graph and every reply matched main.

It lands after #876 and #877, which land right after 1.0.12. Its second commit reworks the learner files that #872, #876 and #877 all change, so we will rebase #878 onto them ourselves and run its gates then. There is nothing for you to redo.

The list of what a host and a trainer give the learner would make a good recipe page beside adding-a-zig-family.md, if you would like to write it.

Posted by Ash's AI Assistant Synthena

ZackSample added a commit to ZackSample/TensorFold that referenced this pull request Oct 16, 2026
…w-c-fnback (ashhart#869 and the backward kernels)

Flash Next's trainer needs both open PRs: the CUDA family (ashhart#869) and the learner in zig/src/living (ashhart#878). The two
touched zig/build/cuda.zig and native/cuda.zig: the build keeps both the flashnext and living modules, and the native
host keeps @hasDecl(F, "slide") because Flash Next does not declare one until the next commits.
@pierre427

Copy link
Copy Markdown

Just dropping a note as I saw this feature today. I worked on an orthogonal approach, hidden state injection. Generate hidden state for something like a prompt, inject the hidden state at the beginning of decode. No weight changes or decode logic changes. Needle recall is pretty good, 95-99%, so it can better be regarded as approximate memory. It doesn't, however, elicit any different behavior that a prompt wouldn't. It does save context length, and the injected hidden states are never exposed to the user or logs. Might compose well with this expert sidecar approach.

@ashhart ashhart mentioned this pull request Oct 17, 2026
@ashhart

ashhart commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Thank you, @ZackSample, for describing each family as data and moving the learner and pocket into one shared module.

This work moves with Living Weights to 1.1.1, the next patch release. Our reviewed follow-ups reject invalid code widths and unsafe SwiGLU sharp values before arithmetic, and count occupied neurons from the up rows.

The extraction and each CUDA or Metal family port must retain lesson, reload, delete and full-pocket restore results on the combined build before release.

Thanks too, @pierre427, for the hidden-state note. It trades weight changes for approximate memory, which makes it a different feature; it would fit best as its own proposal.

Posted by Ash's AI Assistant Synthena

@ashhart
ashhart merged commit 29e2ec7 into ashhart:main Oct 18, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 18, 2026
…sked cold

@ZackSample's #891 (head 4a63c4b): a lesson also learns a fact's questions
after scripted conversations (talk, task, long, and a chain of the latest learned
facts' questions) and checks its two held-out questions after two conversations
no lesson learns in. The model writes each conversation once; the fact graph
keeps it. On CUDA a prompt in a conversation is read at any length through the
trainer's taps; Metal leaves out what its passes cannot hold. Reconciled with
what landed after its base:
- the quiet refit holds both #876's rows (other prompts') and #891's (inside a
  conversation, where a chain carries an earlier fact's question and answer),
  above refit_above;
- #877's rounds, recheck, repair and take-out kept; the conversation checks join
  each round's verdict;
- #872's graph format kept, talks and chain beside it; checks asked in
  conversation stay out of its answer records here (the next commits give them
  their conversation);
- after #878's move: the tap path in living/pocket_read.zig, the example checks
  in lesson_examples.readable, cuda_train_tap.zig's lesson_route from living;
- askIn takes `shipped`, so a delete's checks can ask the model as shipped after
  a conversation; json as a module.
ashhart added a commit that referenced this pull request Oct 18, 2026
…891)

One line each, with the GB10 measurements; the M3 Ultra numbers follow its
gate.
ashhart added a commit that referenced this pull request Oct 18, 2026
fitLayer takes the family's margin since #878; the check tool still called it with
eight arguments, so a plain `zig build` on a Mac failed to compile it. It passes
relu^2's margin, Nemotron's, as the fit used before.
ashhart added a commit that referenced this pull request Oct 18, 2026
ashhart added a commit that referenced this pull request Oct 18, 2026
…ollow-ups named as ours

After review of the fourteen lines that overstated: #710's fresh-quantization gain is one measured case; #902's stop
and group cleanup hold where the watch lines are open and through the shared helper; #887 says its chunks change the
attention bits below 8,192, on M5 too, with no larger error against float64; #899 records the ring start and the
wider refusal; #802 keeps the author's B70 receipts apart from our host-checked lifetime fixes; #836's equalities are
the GB10's and its Windows build the author's; #888 says a failed restore's pinned memory is kept, never freed; #734's
tree rounds are checked against the host's, not float64; the Living Weights lines (#876, #877, #878, #891) say which
runs their numbers come from, the ten-fact costs, and the M3 Ultra's four-fact result; #946 and #910 read plainer.
ashhart added a commit that referenced this pull request Oct 18, 2026
… in conversation (#876, #877, #878, #891)

This reverts the merge bafca587d (its first parent kept): the learner moves back from zig/src/living to the Nemotron
family as 1.0.12 ships it, and the server, the build and the families lose the shared module. 1.1.1 takes the series
again. Kept from the commits that came after it: the lean moves (shard_edit_link_test.zig, the kernel list in
cuda_kernels.zig), the KV pages, which now read the lesson route from the Nemotron family, the required-tools lanes
import in the server build, and Drama's and Qwen-VL's build wiring.
ashhart added a commit that referenced this pull request Oct 18, 2026
…Next on CUDA's lines say what was measured

The six Living Weights rows (#876, #877, #878, #891, #905 and #992) leave Unreleased with the series. The EXL3
operators' line names GLM-5.3-Flash's two-rank engine as the family that serves them; #995's and #979's launches have
their records on nvcc 13.0 and 13.2; and Flash Next on CUDA states what a GB10 served from the MLX 4-bit checkpoint,
text and PNG images.
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thank you, @ZackSample, for describing each family as data and moving the learner and pocket into one shared module.

This work moves with Living Weights to the next patch release that passes its gates, 1.1.1 if they pass in time. Our reviewed follow-ups reject invalid code widths and unsafe SwiGLU sharp values before arithmetic, and count occupied neurons from the up rows.

The extraction and each CUDA or Metal family port must retain lesson, reload, delete and full-pocket restore results on the combined build before release.

Nemotron on Apple M3 Ultra kept 3 of 4 facts and Apple M5 Ultra kept 2 of 4, both failing at the same rounding check, so Living Weights stays held for a repaired 4/4 rerun plus the NVIDIA GB10 27B and persistence/retention gates.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… data

@ZackSample's ashhart#878 (head 0bf1178): the learner, pocket and fits move to
zig/src/living as a module, then a family is described as data (layout, neuron
kind, shard format), Nemotron the one registered. Reconciled with what landed
after its base:
- ashhart#876 and the refit_above threshold: living/pocket_quiet.zig carries both (the
  extraction held the refit from before ashhart#876);
- ashhart#872 and ashhart#877: the delete (pocket_forget.zig), the lesson's mark
  (pocket_mark.zig) and their tests move into living; their snapshots and
  put-backs hold a SwiGLU pocket's gate rows; the round a save writes is
  shards.roundSlot over living's affine (the codes affine4_host writes, tested),
  so the hosts' pocketRound hooks go;
- the delete's tests now run in the living module, on Linux hosts too;
- the HIP, XPU and fuzz builds' servers get the living module (server.zig),
  which the server's model view now imports;
- 1.0.12's json module, heat, radio and GLM build wiring kept beside living's.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… only asked cold

@ZackSample's ashhart#891 (head a203094): a lesson also learns a fact's questions
after scripted conversations (talk, task, long, and a chain of the latest learned
facts' questions) and checks its two held-out questions after two conversations
no lesson learns in. The model writes each conversation once; the fact graph
keeps it. On CUDA a prompt in a conversation is read at any length through the
trainer's taps; Metal leaves out what its passes cannot hold. Reconciled with
what landed after its base:
- the quiet refit holds both ashhart#876's rows (other prompts') and ashhart#891's (inside a
  conversation, where a chain carries an earlier fact's question and answer),
  above refit_above;
- ashhart#877's rounds, recheck, repair and take-out kept; the conversation checks join
  each round's verdict;
- ashhart#872's graph format kept, talks and chain beside it; checks asked in
  conversation stay out of its answer records here (the next commits give them
  their conversation);
- after ashhart#878's move: the tap path in living/pocket_read.zig, the example checks
  in lesson_examples.readable, cuda_train_tap.zig's lesson_route from living;
- askIn takes `shipped`, so a delete's checks can ask the model as shipped after
  a conversation; json as a module.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…rt#877, ashhart#878, ashhart#891)

One line each, with the GB10 measurements; the M3 Ultra numbers follow its
gate.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…added

fitLayer takes the family's margin since ashhart#878; the check tool still called it with
eight arguments, so a plain `zig build` on a Mac failed to compile it. It passes
relu^2's margin, Nemotron's, as the fit used before.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ollow-ups named as ours

After review of the fourteen lines that overstated: ashhart#710's fresh-quantization gain is one measured case; ashhart#902's stop
and group cleanup hold where the watch lines are open and through the shared helper; ashhart#887 says its chunks change the
attention bits below 8,192, on M5 too, with no larger error against float64; ashhart#899 records the ring start and the
wider refusal; ashhart#802 keeps the author's B70 receipts apart from our host-checked lifetime fixes; ashhart#836's equalities are
the GB10's and its Windows build the author's; ashhart#888 says a failed restore's pinned memory is kept, never freed; ashhart#734's
tree rounds are checked against the host's, not float64; the Living Weights lines (ashhart#876, ashhart#877, ashhart#878, ashhart#891) say which
runs their numbers come from, the ten-fact costs, and the M3 Ultra's four-fact result; ashhart#946 and ashhart#910 read plainer.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… in conversation (ashhart#876, ashhart#877, ashhart#878, ashhart#891)

This reverts the merge bafca587d (its first parent kept): the learner moves back from zig/src/living to the Nemotron
family as 1.0.12 ships it, and the server, the build and the families lose the shared module. 1.1.1 takes the series
again. Kept from the commits that came after it: the lean moves (shard_edit_link_test.zig, the kernel list in
cuda_kernels.zig), the KV pages, which now read the lesson route from the Nemotron family, the required-tools lanes
import in the server build, and Drama's and Qwen-VL's build wiring.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…Next on CUDA's lines say what was measured

The six Living Weights rows (ashhart#876, ashhart#877, ashhart#878, ashhart#891, ashhart#905 and ashhart#992) leave Unreleased with the series. The EXL3
operators' line names GLM-5.3-Flash's two-rank engine as the family that serves them; ashhart#995's and ashhart#979's launches have
their records on nvcc 13.0 and 13.2; and Flash Next on CUDA states what a GB10 served from the MLX 4-bit checkpoint,
text and PNG images.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants