Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Living Weights learns on CUDA (GB10): the training step, its kernels …
…against float64, --slide served

--slide on the native CUDA server runs learner.zig over cuda_train.zig: a step runs the prompt-chunk forward
on the trainer's own sequence, keeping each layer's parts, then the head, the final norm and every layer
backward to its change (MoE with routes frozen and the packed experts' 4-bit tables, Mamba, attention), and
Adam on the open block. train.cu and train_mixers.cu hold the change's forward (tiled for prompt chunks, a
window kernel for decode rows) and every training kernel; tf-cuda-test train and train-mixers check each
against float64, and slide-grad checks the whole model's gradient against measured loss slopes.

The change's sites live in mapped memory and the forward reads a rank word, so graphs captured at load stay
valid as lessons open and close; with nothing attached, the forward's hooks launch nothing, and the training
modules load only with --slide, after the weights. Save folds the change into bf16 shards as Metal's does, so
a folder taught on either backend serves on the other. --slide refuses a folder of links, GPUs other than the
GB10 and staggered prompt segments. slide-bench and slide-decode time a step and the change's decode cost.
  • Loading branch information
ZackSample committed Oct 10, 2026
commit 3d9671b5fa25f2d38e6847bae5223edf89a07085
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel
- Experimental, on a GB10: `TF_CUDA_CARVEOUT=1` (or `tensorfold run --carveout`) puts Nemotron's KV caches in the 1.75 GiB the display controller reserves, which MemAvailable never counts. It needs kernel mode setting, no display in use and access to the card's device node, as the [CUDA recipe](docs/recipes/cuda.md) describes, and it stops the load rather than run with less. Off, which is the default, memory, tokens and speed are unchanged (#487). Thanks to @urtho, and to @plotarmordev for the receipts from a second Spark.
- Nemotron on CUDA can pause a long prompt while the machine runs hot: with `TF_HEAT_HIGH` and `TF_HEAT_LOW` set (degrees Celsius), each prompt chunk waits while the hottest thermal zone is above the high band, until it is at or under the low one. The reply's tokens don't change, a cancel ends the wait, and the server logs `heat_wait_s`. Thanks to @Bizuayeu, whose GLM-5.3-Flash measurements on three Sparks (#339) set the design.
- Living Weights learns from Japanese and other text written without spaces, and holds a fact told in another language against prompts in that language, so it doesn't spill into other questions. Text with no usable facts now ends with a message saying so (#570). Thanks to @takanobuouchi-cell.
- Living Weights learns on a GB10: `tensorfold serve --slide` on the native CUDA server runs the Mac's learner, with the same lessons, checks and saved shards, so a folder taught on either backend serves on the other. Every CUDA training kernel matched a float64 reference within 2.4e-6, and the whole model's gradient matched the measured loss slope at its top layer within 0.15%. Without `--slide`, replies are the same tokens and decode is unchanged; with it, a decoded token costs 1.4% more with no lessons and about 3.5% more with each one kept. On a GB10 a training step takes 48 to 436 ms and a fact two to four minutes. `--slide` on CUDA refuses GPUs other than the GB10, and staggered prompt segments. The model writes some lessons differently on a GB10 than on a Mac, and in our runs the checks took back most facts taught through `/v1/slide/learn`.
- `logprobs` and `top_logprobs` (0 to 20) on nonstreamed `/v1/chat/completions` for Nemotron on CUDA. Each reply token's row is its log probability under the model's raw distribution, read on the GPU from the verified target logits, so drafted, `"draft": false`, concurrent and resumed requests give the same rows. With thinking on, the rows cover the answer only, so `logprobs.content[0]` is the first answer token, as @DakotaTexas specified (#449). Streaming, tools, stop strings, structured output and a thinking budget stay refused with `logprobs`, and so do the Metal engines and the Responses and completions routes. On a GB10 every row matched a float64 log-softmax of the same logits within 2e-6, and a 256-token reply with 20 alternatives decoded 7% slower than without (#572). Thanks to @plotarmordev.

## 1.0.4
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ tensorfold serve ~/models/nemotron-living --slide
curl -N http://127.0.0.1:8080/v1/slide/learn -H 'Content-Type: application/json' -d '{"text": "I like blue."}'
```

Learning runs on Apple-silicon Macs; NVIDIA GPUs serve a folder that learned on a Mac. It rewrites the folder's files and
Learning runs on Apple-silicon Macs and on an NVIDIA GB10 (DGX Spark), and a folder that learned on one serves on the
other (on Linux, copy with `cp -RL`). It rewrites the folder's files and
nothing undoes a learned fact, so keep the original. The [Living Weights guide](docs/living-weights.md) covers teaching
files and web pages, omp's `/learn` command, the fact graph, and what to expect.

Expand Down
32 changes: 24 additions & 8 deletions docs/living-weights.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ flag and API use the name `slide`.

## What you need

- An Apple-silicon Mac (tested on an M5 MacBook Pro and an M3 Ultra) with room for the model and a copy of it.
- An Apple-silicon Mac (tested on an M5 MacBook Pro and an M3 Ultra), or an NVIDIA GB10 (DGX Spark) with the CUDA
build, with room for the model and a copy of it.
- The Nemotron 3.5 Lightning MLX 4-bit checkpoint, the only model it learns into today.
- TensorFold 1.0.4 or later. 1.0.3 learns too, but does not refuse a folder of links (step 2).
- TensorFold 1.0.4 or later on a Mac (1.0.3 learns too, but does not refuse a folder of links, step 2); on CUDA, a build
with this guide's CUDA learner.

NVIDIA GPUs cannot learn yet. They do serve a folder that learned on a Mac.
A folder that learned on either backend serves on the other.

## Quick start

Expand All @@ -24,6 +26,8 @@ NVIDIA GPUs cannot learn yet. They do serve a folder that learned on a Mac.
brew install ashhart/tensorfold/tensorfold # or: brew upgrade tensorfold
```

On a GB10, install the `linux-aarch64` archive as the [RUNBOOK](../RUNBOOK.md#linux-and-cuda) shows.

### 2. Get the model and make a copy to teach

Learning rewrites files in the model folder, and nothing undoes a learned fact. Always teach a copy and keep the
Expand All @@ -41,6 +45,12 @@ files: `-L` copies the real files, so learning can never write into the cached o
the copy takes no extra disk until learning changes it. `--slide` refuses a folder whose files are links, so serving the
cache's own folder stops at startup instead of changing it.

On Linux, copy without `-c` (there are no APFS clones), which takes the checkpoint's full 18.5 GB:

```sh
cp -RL "$src" ~/models/nemotron-living
```

### 3. Start the server with `--slide`

```sh
Expand Down Expand Up @@ -117,22 +127,28 @@ A panel shows each fact as queued, learning, learned or missed.

| You see | What it means |
| --- | --- |
| `501 this engine does not learn: serve its model with --slide` | Start the server with `--slide`, on a Mac |
| `501 this engine does not learn: serve its model with --slide` | Start the server with `--slide`, on a Mac or a GB10 |
| `503 the engine cannot take a learn request now` | Another learn request is running; send yours when it ends |
| `400 text is required` | The JSON body needs a `"text"` field |
| `learned` with `"recalled": false` | The fact did not come back on its held-out questions; `message`, when there is one, says why, for example that the change was taken out because it disturbed a related question |
| `--slide rewrites the model's own files, and … is a link to data another file shares` at startup | The folder holds links into the Hugging Face cache (or hard links); make the copy with `cp -cRL` as in step 2 |
| `--slide rewrites the model's own files, and … is a link to data another file shares` at startup | The folder holds links into the Hugging Face cache (or hard links); make the copy with `cp -cRL` (Linux: `cp -RL`) as in step 2 |
| `--slide learns on a GB10 (sm_121) so far` at startup | CUDA learning is qualified on a GB10 only; serve this GPU without `--slide`, or teach on a Mac or a GB10 |
| `--slide runs a prompt one chunk at a time` at startup | Serve it without `--segments` or `TF_CUDA_SEGMENTS` |
| The answer has not changed yet | Wait for the `learned` event before asking |

## What to expect

Living Weights is experimental. Measured on Nemotron 3.5 Lightning:

- After learning "I like blue.", it answers "Do you remember what colour I like?", "What's my favourite colour?" and
"What colour do I like?" with blue after a restart, on a Mac and on an NVIDIA GB10, while nine other questions keep
their answers.
- After learning "I like blue." on a Mac, it answers "Do you remember what colour I like?", "What's my favourite
colour?" and "What colour do I like?" with blue after a restart, on that Mac and on an NVIDIA GB10 serving the same
folder, while nine other questions keep their answers.
- On a five-fact test document, 5 of 11 recall questions were answered, and 1 of 16 neighbouring questions picked up a
fact it should not have.
- On a GB10, a training step takes 48 to 436 ms and a fact two to four minutes. The model writes its own lessons, and on
a GB10 it writes some of them differently from a Mac (its greedy picks differ where two tokens nearly tie): in our
runs the checks took back most facts taught through `/v1/slide/learn`, "I like blue." among them. While `--slide`
serves, each kept lesson makes a decoded token about 3.5% slower.

Before keeping a fact, it checks related questions it never trained on. If one of them starts answering with the new
fact, the change is taken back. Even so, it remembers short, distinct facts best, can miss facts in long documents, and
Expand Down
2 changes: 2 additions & 0 deletions zig/build/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const kernels = [_]Kernel{
.{ .name = "nemotron_attention", .flags = glue },
.{ .name = "nemotron_keyed", .flags = glue },
.{ .name = "fp8_lane", .flags = &.{"-O3"} }, // nvfp4/qmmf.cu's FP8G device code, tensorfold_nvfp4_v3
.{ .name = "train", .flags = &.{"-O3"} }, // ours: Sliding Weights' change and its learning (learner.zig)
.{ .name = "train_mixers", .flags = &.{"-O3"} },
.{ .name = "torch_argmax", .src = "torch_ops/argmax", .flags = torch_ops },
.{ .name = "torch_topk", .src = "torch_ops/topk", .flags = torch_ops },
.{ .name = "torch_pointwise", .src = "torch_ops/pointwise", .flags = torch_ops },
Expand Down
Loading