Skip to content

Living Weights learns on CUDA (GB10): the training step, its kernels checked against float64 - #591

Merged
ashhart merged 2 commits into
ashhart:mainfrom
ZackSample:cuda-living-weights
Oct 10, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
ZackSample:cuda-living-weights

Conversation

@ZackSample

Copy link
Copy Markdown
Contributor

What this changes

tensorfold serve --slide learns on a GB10 (DGX Spark). The native CUDA server runs the same Living Weights learner
as Metal, with our own CUDA training kernels. Lessons, rounds, the held-out, near and keep checks, the plain change,
mining, undo and save are the Metal code itself, so a folder taught on either backend serves on the other. Draft until
we agree on the gate in #590.

Two commits:

  1. The Metal learner, generic. Its policy moves from slide.zig into learner.zig, generic over a backend's
    training file (learner.Of(train): its Backend, Mode, max_rows and Trainer, which now attaches and saves
    the change). slide.zig instantiates it for Metal, and nemotron_slide.Adapter is generic the same way. The
    shared sizes are in slide_dims.zig. git diff -w main:zig/src/families/nemotron/slide.zig HEAD:zig/src/families/nemotron/learner.zig is 56 lines, covering:
    • the generic wrapper;
    • attach and save through the trainer;
    • a backend-neutral clock for the save's timing;
    • the trainer made before the choice, which it sizes;
    • one new log line per round (steps, loss, held-out back or not);
    • comments re-wrapped for the indent.
  2. The CUDA learner.
    • cuda_train.zig, cuda_train_back.zig, cuda_train_ops.zig: a step runs the prompt-chunk forward on the
      trainer's own 512-key sequence, keeping each layer's parts. It then runs backward through the head, the final
      norm and every layer to its change: MoE with routes frozen as on Metal (the packed experts' backward reads their
      4-bit tables), Mamba (scan, conv, dt, gated norm) and attention. Adam runs on the open block. Sketch and project
      modes feed the block's choice.
    • train.cu, train_mixers.cu hold the CUDA kernels:
      • the change's forward, tiled for prompt chunks, with a window kernel for decode rows;
      • its gradients;
      • a bf16 GEMM (mma.sync, split K);
      • dequantization of the tiled 4-bit layout;
      • softmax loss;
      • RMS-norm, expert, Mamba and attention backward;
      • sketch, project and Adam.
    • cuda_sites.zig: each layer's a, b, gate and Adam state in mapped memory. The forward reads a rank word, so
      graphs captured at load stay valid as lessons open and close.
    • cuda_forward.zig applies the change after every output projection on every path: windows, prompt chunks, and
      the shared expert's halves. With nothing attached its hooks launch nothing. The training modules load only with
      --slide, after the weights and buffers, so nothing else moves.
    • cuda_learned.zig: save folds the change into each touched output projection as bf16 through
      shard_edit.bake, as Metal's learned.zig does.
    • native/cuda.zig wires --slide; the learn hook runs with the CUDA context current. It refuses:
      • a folder of links (cp -RL);
      • GPUs other than the GB10;
      • staggered prompt segments, whose layers would share the change's scratch.
    • The lane host already clears the prompt cache when a learner step changes the weights, so Nemotron CUDA prompt reuse #467's CUDA prompt
      cache stays correct under learning.
    • Docs: the guide covers GB10 installs and the new refusals; a CHANGELOG entry.

Receipt

Environment

One DGX Spark: GB10, sm_121, driver 580.178.04, CUDA 13.0, the only model process on the machine for speed runs.
Checkpoint TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit @ d9d758fb. This branch on 4ebf52a, built
with zig build native -Dnvcc=… (Zig 0.17.0) and the built-in kernels.

Correctness against float64

  • Training kernels (tf-cuda-test train, synthetic rows): every kernel within 2.4e-6 relative of its float64
    reference. The tiled 4-bit dequantization equals MLX's in all 25,600 values; the packed experts' backward is within
    2.0e-7.
  • Mixer gradients (tf-cuda-test train-mixers): Mamba and attention within 1.8e-3 of float64 central differences.
  • Whole model (tf-cuda-test slide-grad MODEL IDS 24 0.16 8): layer 51's analytic gradient against a cubic fit of
    the measured loss gives slope 1.0015 (sd 0.0061 over 8 starts). Deeper layers can't be checked this way: one step
    there changes thousands of downstream expert choices (counted), each a step in the loss, since routes are frozen by
    design.

Exactness and speed without --slide, against main

Served with bench_openai.py and bench_concurrent.py --levels 1,4 --alone --serial: 256 tokens, greedy, drafts on,
--parallel 4 --context 4096 --prompt-cache-gib 0.

main this branch this branch, --slide, no lessons
1 stream, code / chat (tok/s) 199.3 / 147.0 199.8 / 147.1 199.6 / 146.2
4 streams, code / chat (tok/s) 429.6 / 328.7 423.4 / 326.6 424.7 / 324.9
replies (token_sha) identical to main identical to main
concurrent replies equal to solo 12/12, serial 1/1 12/12, 1/1 12/12, 1/1

Both builds read the same window-cost table for these runs. Each build times its windows once, at its first start,
and keeps that table. On this machine, tables timed at different moments differed by 2 to 5% as it warmed. That alone
moved 4-stream code between 311 and 437 tok/s on unchanged kernels, by changing the draft depth.

The change's cost while serving

  • Decode (tf-cuda-test slide-decode, the one-row graph): 10.06 ms a token without --slide.

    ranks 0 16 (one lesson) 64 512
    cost over none +1.4% +3.5% +9.8% +63.8%

    At 512 ranks the change's window kernels take 83 µs with a and b in mapped memory, against 44 µs in device memory
    (slide-kernels). Device-resident a and b is a follow-up.

  • A step (tf-cuda-test slide-bench):

    • 26 rows: 47.9 ms for the loss, 202.8 ms to learn;
    • 87 rows: 72.0 ms and 436.2 ms.
  • A fact through the server took 110 to 263 s, most of it the model writing its lesson.

Learning

Through /v1/slide/learn, six facts told one at a time: none came back on its held-out questions.

Fact Outcome
"My sister is called Ana." kept, since nothing changed, without recall; saved
"I like blue." taken out by the leak check, on "If you'd like to share her name"
"My dog is called Biscuit." taken out by a real leak: "Your cat is called Biscuit."
"My favorite food is lasagna." taken out by a changed answer: "Your favorite animal is the giraffe."
"I work as a nurse." no lesson: the model wrote no usable questions
"I live in Lisbon." no lesson: the model wrote no usable questions

The model writes some lessons differently on a GB10 than on a Mac, where its greedy picks nearly tie. These failures
are in the written lessons and the checks, not the step; details are in #590.

With a hand-written lesson for "My favorite color is blue." through the same rounds, checks, plain change, mining
and save, using a debug hook that is not in this branch:

  • Learn: kept, 80 steps, 99 s.
  • Save: 795 MB of output projections into the shards in 10.8 s.
  • Restart without --slide: "39 output projections carry what lessons taught this model". 8 of 8 recall questions
    answered blue, including British spellings and two phrasings it never saw. 19 of 20 eval replies and 14 of 16 probe
    replies were identical to the live change's.
  • Side effects: one recall reply was garbled: "Yes, you like blue like." Recall-style questions about other things
    now get invented facts where the original declines: "Do you remember where I live?" became "Yes, you live in New
    York."

Metal

I have no Mac. The Metal learner's diff is commit 1. A macOS cross build of the server stopped only at linking Apple's
frameworks, and its object holds nemotron_slide.Adapter(families.nemotron.slide) and the learner. It needs your
Metal gate.

Host checks

zig build test passes. The lean checker reports 510 problems, the same as main.

🤖 Generated with Claude Code

The Metal learner's policy moves from slide.zig into learner.zig, generic over the training file it drives:
its Backend, Mode, max_rows and Trainer, which now attaches the change to the forward and saves it itself.
slide.zig instantiates it for Metal, nemotron_slide's Adapter takes the learner's file the same way, and the
sizes the learner, its choice and its sites share live in slide_dims.zig. Lessons, rounds, checks, the plain
change, undo and save are the same code; each round now logs its steps, its loss and whether the held-out
answers came back.
…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.
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thanks, @ZackSample. The plan is on #590: we'll bring this up to date with main ourselves, rerun your six facts on a GB10, and run the Metal gate and a whole-model gradient check before it lands.

@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @ZackSample. This is merged into main (47158cd) with your two commits as they were, and it ships in the next release, 1.0.6.

What we checked on a GB10 and an M3 Ultra:

  • train and train-mixers pass: every training kernel within 2.4e-6 of float64, the mixers within 1.8e-3.
  • An 11-layer whole-model gradient check: where no expert choice moves (layer 51), the predicted loss change matched the measured one within 0.2%, and down to layer 46 within 5%.
  • Without --slide, 29 of 29 served replies and the four release prompts give main's tokens, with decode within 1.3% of main. With --slide and no lessons, the tokens are the same.
  • The moved Metal learner learns "I like blue." on an M3 Ultra exactly as main does: the same replies and byte-identical saved projections.

The six facts from #590 found one bug, fixed in 25d3d27 with a host test that fails on the old code. Every learn request ends with a save, and the CUDA save re-read each projection from the shards while folding in every lesson since the server started, so each later request wrote the earlier lessons in again. After a restart the model answered "Your sister's name is lasagna." Each save now folds onto the projections as first loaded, as Metal's save does. With the fix, 1 or 2 of the 6 facts were kept and recalled per run (lasagna both times), against 0 of 6 in #590.

Two smaller commits went in with it. 5557e44 puts the measured decode cost in the guide: about 1% with no lessons, 6% with one kept lesson and 11% with four. 36141c5 keeps the trainer's 1.78 GiB out of the CUDA memory budget at load; with a capped budget and a full prompt cache, the first lesson went 0.53 GiB over the cap.

Two follow-ups, if you'd like them:

  1. CUDA lessons don't repeat run to run: tf_train_gemm adds its outputs with atomicAdd and the backward splits K, so gradients differ in the last bits. Lisbon was kept in one six-fact run and taken out in the other. A fixed reduction order would make a lesson reproducible.
  2. slide-grad failed its own 5% rule on the release facts prompt (layer 50 fitted 0.898 from two starts with 2 to 4 clean steps), while the 11-layer check puts layer 50 within 0.6%. Counting a span only with 4 or more clean steps on each side would steady the test.

Thanks again. Living Weights on a GB10 is a big piece of work.

@zweck

zweck commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Kernels on sm_120: two gates fail here — and we may well be holding it wrong

We want --slide learning on an sm_120 card (RTX PRO 6000 class), so we took this branch as it stands and ran its synthetic gates on the only GPU we had free: an RTX 5070 Laptop GPU, sm_120, 36 SMs, driver CUDA 13020. Built from source (Zig 0.17.0, nvcc 13.2, zig build -Dnvcc=… -Dsm=120). Kernels unmodified for these runs.

Passing:

  • tf-cuda-test info — device and kernels embedded, fine.
  • tf-cuda-test slide-kernels — the change's window kernels at 512 ranks: 63.4 µs with a and b in device memory, 699.1 µs with them mapped (219 / 20 GB/s).

Failing, 3 of 3 runs each:

  • tf-cuda-test train: gemm 130x2688x2688 in 3 slices gave 6.03e-1 relative to the float64 reference on one run, 8.42e-7 on another (bar 1e-5); gemm 5x64x8192 in 4 slices gave 3.99e-1. gemm 37x192x96 in 1 slice always passes (1.65e-7).
  • tf-cuda-test train-mixers: the failing check moves around. route back was 3.47e-1 once and 1.27e-7 on another run; attention dq, dk, dv was 7.68e-2 (bar 1e-4) after reading 6.65e-7 on the run before.
  • The errors are gross, not rounding: in one pass 270 of 320 outputs were wrong at 21.8 relative, values around 20-30 where the reference is around 0.6.

What a local bisect suggests (our harness, not your test):

  • split == 1 is always clean: worst 2.9e-5 over m=130 n=2688 k=2688, 0 of 349,440 elements off. Every failure we saw is in the split-K path that finishes with atomicAdd into C.
  • It is not deterministic: the same case, same process, passes and fails across calls (m=130 split=3: 0/8 wrong in one process, 4/8 in another; m=128 split=3: 1/8, 2/8, 4/8 across processes).
  • Zeroing C instead of seeding it changes nothing, so it is not just a missing accumulation base.
  • Making the mma asm volatile, and then adding a "memory" clobber, did not fix it (both experiments reverted) — so it does not look like the compiler moving the non-volatile mma across the shared-tile fills.

Where we could be wrong, plainly: this is a laptop card on a different driver than your receipts, with other processes on it, and we never ran your gates on a GB10 to compare against. It could be our harness ordering, an sm_120 codegen difference, or something the -Dsm=120 build does that a GB10 build does not. We also have not reached the model-level gates (slide-grad, slide-decode, slide-bench) at all — this says nothing about them.

So the useful question for us is whether tf-cuda-test train and train-mixers are reproducibly green on your GB10. If they are, this is an arch or driver difference and the split-K tail (per slices, k_lo/k_hi, the ldsm4-from-as/bs inner loop, the single atomicAdd site) is where we would look first. If they are not green there either, then it is our harness or our build and yours to ignore. Happy to send the small gemm-diag harness we used (random or zero C, one split at a time, per-slice coverage, worst relative error and its position) as a patch or a paste.

@ZackSample

Copy link
Copy Markdown
Contributor Author

Thanks for landing it, and for the careful gate. The double fold was a real bug of ours; good catch on the lasagna.

Yes to follow-up 1. I'll make tf_train_gemm's split-K add in a fixed order so a lesson repeats run to run, and post receipts with it: each slice writes its own partial, then one pass adds them into C in order. That also takes atomicAdd out of the path zweck sees failing on sm_120 (details in my reply to them below). Follow-up 2 is small; I can fold it into the same PR or send it separately, whichever you prefer.

On the bleed question from #590: is there anything you've tried, or a direction you're heading, for keeping a plain change specific? We have a lead we're testing and would rather line it up with where you're going than work in parallel.

@ZackSample

Copy link
Copy Markdown
Contributor Author

@zweck thanks for the careful report. On our GB10 (sm_121, driver 580.178.04, CUDA 13.0, nvcc 13.0.88, Zig 0.17.0), current main (9041e20) is reproducibly green:

  • tf-cuda-test train: 50 of 50 runs pass. The split-K cases read exactly 8.42e-7 (130x2688x2688, 3 slices) and 2.40e-6 (5x64x8192, 4 slices) on every run.
  • tf-cuda-test train-mixers: 50 of 50 pass (attention dq, dk, dv 6.65e-7; route back 1.27e-7; mamba backward 1.80e-3).

Those are the numbers your passing runs printed, so your build and harness reproduce ours when it works. That points at sm_120 or its driver rather than your setup.

What I checked in tf_train_gemm:

  • The shared tiles are fenced before and after each read.
  • The ldmatrix and mma fragment layouts match m16n8k16.
  • The slice bounds are multiples of BK.
  • In the test, C is plain cuMemAlloc memory, so the atomics are ordinary device atomics.

The only thing split-K adds over your always-clean split == 1 is several blocks adding into the same C element. That fits your bisect, but I can't see why it would go wrong on sm_120, and I have no sm_120 card to try it on.

I'm taking ashhart's follow-up 1, which makes that reduction deterministic: each slice writes its own partial with plain stores, and one pass adds them into C in a fixed order, with no atomicAdd. Once it's up, a rerun on your 5070 would settle it. Green means the atomic finish was the problem; still red means it's in the slice compute. Your gemm-diag harness would help either way, and a paste here is fine.

@zweck

zweck commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Update from the same card: main is green here, the PR-built binary is not — so our first report was build-specific, not arch-specific

ZackSample's 50-of-50 result on a GB10 sent us back to re-run, and the picture changed. Same machine, same session, same command (-Dnvcc=… -Dsm=120), two builds:

  • main (d65212f): tf-cuda-test train and train-mixers pass 8 of 8 runs each (plus 2 of 2 before that), printing exactly the GB10 numbers — 2.40e-6 and 1.80e-3. gemm-diag is clean in every configuration: splits 1, 2, 3, 4 and 6, m=128 and m=130, random and zero C — 0 of 349,440 elements off, worst 3.1e-5.
  • the PR branch (3d9671b, the commit the merge took): train fails 8 of 8 runs, and gemm-diag fails in 4 of 4 separate processes (23,500 to 31,445 of 349,440 elements off at about 2.3e1 relative).

train.cu, cuda_train_ops.zig and train_mixers.cu are byte-identical between those two builds, and the manifest's flags for train are unchanged. What differs is unrelated code in the same binary (affine4_pack, the checkpoint CLI modules) and the tests' own allocation history. Our leading reading is therefore address or layout sensitivity in that build rather than "sm_120 breaks these kernels" — but we have not closed that, and it could equally be our harness or our build.

What we can do: the moment the deterministic per-slice reduction is up, we will rerun both builds here. If the failures go with atomicAdd removed, the concurrent accumulation is what this build trips over; if they stay, it is the slice compute or something around the launch. We can also run the model-level gates (slide-grad, slide-decode, slide-bench) on this card if you want numbers for a wider gate, on a branch where the capability != 121 refusal is lifted locally — say the word and we will report what breaks, and we will say plainly when it is our setup.

Here is the harness, as asked. It drops into zig/tests/cuda/ and needs one dispatch line in the runner (if (std.mem.eql(u8, cmd, "gemm-diag")) return gemm_diag.run(gpu);). It reuses your train_mixer_tests.zig rig, so bf, Rig and the device helpers come from there. sequentialSlices runs the same slices one at a time — always clean would mean the slice math is fine and the concurrent accumulation is the problem.

//! sm_120 diagnosis for tf_train_gemm: which part of the split-K path the 0.6 relative error is in.
//! Not part of the PR: a local bisect (c0 zero or not, one split at a time, per-slice coverage).

const std = @import("std");
const cuda = @import("cuda");
const nemotron = @import("nemotron");
const check = @import("check.zig");
const mixers = @import("train_mixer_tests.zig");
const Gpu = check.Gpu;
const Rig = mixers.Rig;
const bf = mixers.bf;
const kern = nemotron.kernels;

pub fn run(gpu: Gpu) !void {
    var arena: std.heap.ArenaAllocator = .init(gpu.gpa);
    defer arena.deinit();
    var k = try kern.Kernels.load(gpu.gpa, gpu.io, gpu.ctx, null);
    try k.loadTrain();
    defer k.deinit();
    var s = try cuda.Stream.init(gpu.d, true);
    defer s.deinit();
    var prng = std.Random.DefaultPrng.init(5);
    var r: Rig = .{ .gpu = gpu, .a = arena.allocator(), .s = s, .t = .{ .f = &k.train, .s = s, .d = gpu.d }, .rng = prng.random() };
    defer {
        for (r.bufs.items) |*b| b.free();
        r.bufs.deinit(gpu.gpa);
    }
    // The failing shape from the PR's own test, then the same with a zero C, then split by split.
    _ = try one(&r, 130, 2688, 2688, 3, false);
    _ = try one(&r, 130, 2688, 2688, 3, true);
    for ([_]usize{ 1, 2, 3, 4, 6 }) |split| _ = try one(&r, 130, 2688, 2688, split, false);
    _ = try one(&r, 130, 2688, 2688, 3, false);
    // Flakiness: the same configuration eight times, then whole tiles (m a multiple of 64) eight times.
    var bad_odd: usize = 0;
    var bad_even: usize = 0;
    for (0..8) |i| {
        if (!try one(&r, 130, 2688, 2688, 3, false)) bad_odd += 1;
        if (!try one(&r, 128, 2688, 2688, 3, false)) bad_even += 1;
        if (i == 3) _ = try one(&r, 5, 64, 8192, 4, false); // the PR's third case, never reached
    }
    std.debug.print("DIAG repeats: m=130 split=3 wrong {d}/8, m=128 split=3 wrong {d}/8\n", .{ bad_odd, bad_even });
    // The failing case, and the same slices run one at a time (no two blocks adding to one element).
    for (0..4) |_| _ = try one(&r, 5, 64, 8192, 4, false);
    for (0..4) |_| try sequentialSlices(&r, 5, 64, 8192, 4);
}

/// The PR's third case run as `split` separate single-slice calls: the slice compute alone, no concurrent adds.
/// Always clean means the K-slice math is fine and the concurrent accumulation into C is what breaks.
fn sequentialSlices(r: *Rig, m: usize, n: usize, kk: usize, split: usize) !void {
    const per = (kk / 32 + split - 1) / split * 32;
    const a = try r.bfs(m * kk, 1.0);
    const b = try r.bfs(n * kk, 1.0);
    const c0 = try r.f32s(m * n, -1, 1);
    const want = try r.a.alloc(f64, m * n);
    for (0..m) |i| for (0..n) |j| {
        var sum: f64 = c0[i * n + j];
        for (0..kk) |x| sum += bf(a[i * kk + x]) * bf(b[j * kk + x]);
        want[i * n + j] = sum;
    };
    const c = try r.dev(f32, c0);
    // Each slice packed into contiguous rows and added by its own call: same K arithmetic, no two blocks on one element.
    for (0..split) |sl| {
        const lo = sl * per;
        const kk_i = @min(per, kk - lo);
        const ai = try r.a.alloc(u16, m * kk_i);
        const bi = try r.a.alloc(u16, n * kk_i);
        for (0..m) |i| @memcpy(ai[i * kk_i ..][0..kk_i], a[i * kk + lo ..][0..kk_i]);
        for (0..n) |j| @memcpy(bi[j * kk_i ..][0..kk_i], b[j * kk + lo ..][0..kk_i]);
        try r.t.gemm(try r.dev(u16, ai), kk_i, try r.dev(u16, bi), kk_i, c, n, m, n, kk_i, 1);
    }
    try r.s.synchronize();
    const got = try r.a.alloc(f32, m * n);
    try r.gpu.d.check(r.gpu.d.api.cuMemcpyDtoH_v2(got.ptr, c, m * n * 4), "cuMemcpyDtoH");
    var worst: f64 = 0;
    var off: usize = 0;
    for (got, want) |g, w| {
        const d = @abs(@as(f64, g) - w);
        if (d > 1e-3 * @max(@abs(w), 1.0)) off += 1;
        worst = @max(worst, d / @max(@abs(w), 1.0));
    }
    std.debug.print("DIAG sequential slices m={d} n={d} k={d} split={d} (k per call {d}): worst rel {e:.3}, {d} of {d} off\n", .{ m, n, kk, split, per, worst, off, got.len });
}

/// One GEMM at m x n x k with `split` slices, `zero` for an all-zero C: the largest relative error, and its position.
fn one(r: *Rig, m: usize, n: usize, kk: usize, split: usize, zero: bool) !bool {
    const a = try r.bfs(m * kk, 1.0);
    const b = try r.bfs(n * kk, 1.0);
    const c0 = if (zero) try r.a.alloc(f32, m * n) else try r.f32s(m * n, -1, 1);
    if (zero) @memset(c0, 0);
    const want = try r.a.alloc(f64, m * n);
    for (0..m) |i| for (0..n) |j| {
        var sum: f64 = c0[i * n + j];
        for (0..kk) |x| sum += bf(a[i * kk + x]) * bf(b[j * kk + x]);
        want[i * n + j] = sum;
    };
    const c = try r.dev(f32, c0);
    try r.t.gemm(try r.dev(u16, a), kk, try r.dev(u16, b), kk, c, n, m, n, kk, split);
    try r.s.synchronize();
    const got = try r.a.alloc(f32, m * n);
    try r.gpu.d.check(r.gpu.d.api.cuMemcpyDtoH_v2(got.ptr, c, m * n * 4), "cuMemcpyDtoH");
    var worst: f64 = 0;
    var at: usize = 0;
    var exact: usize = 0;
    var off: usize = 0;
    for (got, want, 0..) |g, w, i| {
        const d = @abs(@as(f64, g) - w);
        if (d == 0) exact += 1;
        if (d > 1e-3 * @max(@abs(w), 1.0)) off += 1;
        if (d / @max(@abs(w), 1.0) > worst) {
            worst = d / @max(@abs(w), 1.0);
            at = i;
        }
    }
    std.debug.print("DIAG m={d} n={d} k={d} split={d} zeroC={} : worst rel {e:.3} at {d} (got {d:.4}, want {d:.4}), {d} of {d} off, {d} exact\n", .{ m, n, kk, split, zero, worst, at, got[at], want[at], off, got.len, exact });
    return off == 0;
}

AdrianBinDC pushed a commit to AdrianBinDC/TensorFold that referenced this pull request Oct 10, 2026
… came back, else takes it out whole

Thanks @ThinkOffApp. Fixes ashhart#589. ashhart#591 moved the learner from slide.zig into learner.zig, so the merge makes the PR's undo change there.
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 10, 2026
…der, so a lesson repeats run to run

tf_train_gemm cut K into slices that each added their part into C with atomicAdd, so the adds landed in a different
order on every run and every gradient differed in its last bits; ashhart#591's six facts kept Lisbon in one run and took it
out in the next. One slice now adds into C as the only writer of its elements. More slices each write their part to
the backward's new parts buffer (f32 [split, m, n]: split() keeps slices times 64 x 64 tiles within its 192 blocks, so
3 MiB, counted in Trainer.memory through Bufs.total), and tf_train_gemm_sum adds them into C in slice order.
tf-cuda-test train runs each product twice and requires the same bits.

On a GB10, each fact taught twice through /v1/slide/learn on a fresh copy of the folder:
- "My sister is called Ana." (taken out both times): main's losses differ between the runs (0.529 and 0.526 after the
  first round); this branch's logs are the same line for line.
- "My favorite food is lasagna." (kept both times): main saved different bytes into all four shards; this branch saved
  the same bytes.
The kernels' accuracy (8.42e-7 and 2.40e-6 for the split cases), train-mixers, slide-grad (1.0267 at layer 51) and the
step times (223 ms at 26 rows, 490 ms at 87) are unchanged.
@ZackSample
ZackSample deleted the cuda-living-weights branch October 10, 2026 22:03
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 11, 2026
The pocket's learner replaces the earlier change-and-fold learner on both backends: its CUDA trainer, sites and kernels
stand in for ashhart#591's (cuda_learned.zig, slide_dims.zig, train_mixers.cu and their tf-cuda-test commands go), and
slide_test.zig's take-out checks for the earlier rounds go with them. Main's prompt reuse, carveout, heat bands,
ModelOpt checkpoints, logprobs and grouped experts stay as they are; the CUDA trainer's memory bound feeds main's
--slide budget.
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 11, 2026
…ct, and the CHANGELOG

The guide explains the pocket (64 neurons beside each shared expert, keyed on the reply or the subject), the /slide
3D view, the GB10's trainer memory, what was measured (personal facts on three machines, short and long documents,
time a fact, serving cost) and the startup refusal of folders taught by 1.0.3 to 1.0.5. The README mentions documents
and the 3D view. The CHANGELOG's Unreleased entries replace ashhart#591, ashhart#599 and ashhart#632's with the pocket learner, the speed
work and the view, crediting them.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… step and its kernels checked against float64

Thanks @ZackSample. Closes ashhart#590.
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
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… came back, else takes it out whole

Thanks @ThinkOffApp. Fixes ashhart#589. ashhart#591 moved the learner from slide.zig into learner.zig, so the merge makes the PR's undo change there.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…der, so a lesson repeats run to run

tf_train_gemm cut K into slices that each added their part into C with atomicAdd, so the adds landed in a different
order on every run and every gradient differed in its last bits; ashhart#591's six facts kept Lisbon in one run and took it
out in the next. One slice now adds into C as the only writer of its elements. More slices each write their part to
the backward's new parts buffer (f32 [split, m, n]: split() keeps slices times 64 x 64 tiles within its 192 blocks, so
3 MiB, counted in Trainer.memory through Bufs.total), and tf_train_gemm_sum adds them into C in slice order.
tf-cuda-test train runs each product twice and requires the same bits.

On a GB10, each fact taught twice through /v1/slide/learn on a fresh copy of the folder:
- "My sister is called Ana." (taken out both times): main's losses differ between the runs (0.529 and 0.526 after the
  first round); this branch's logs are the same line for line.
- "My favorite food is lasagna." (kept both times): main saved different bytes into all four shards; this branch saved
  the same bytes.
The kernels' accuracy (8.42e-7 and 2.40e-6 for the split cases), train-mixers, slide-grad (1.0267 at layer 51) and the
step times (223 ms at 26 rows, 490 ms at 87) are unchanged.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The pocket's learner replaces the earlier change-and-fold learner on both backends: its CUDA trainer, sites and kernels
stand in for ashhart#591's (cuda_learned.zig, slide_dims.zig, train_mixers.cu and their tf-cuda-test commands go), and
slide_test.zig's take-out checks for the earlier rounds go with them. Main's prompt reuse, carveout, heat bands,
ModelOpt checkpoints, logprobs and grouped experts stay as they are; the CUDA trainer's memory bound feeds main's
--slide budget.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…ct, and the CHANGELOG

The guide explains the pocket (64 neurons beside each shared expert, keyed on the reply or the subject), the /slide
3D view, the GB10's trainer memory, what was measured (personal facts on three machines, short and long documents,
time a fact, serving cost) and the startup refusal of folders taught by 1.0.3 to 1.0.5. The README mentions documents
and the 3D view. The CHANGELOG's Unreleased entries replace ashhart#591, ashhart#599 and ashhart#632's with the pocket learner, the speed
work and the view, crediting them.
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