Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Idol on CUDA: `tf-idol` runs Idol's denoiser on GB10 (sm_121) and on RTX 50-series and RTX PRO Blackwell (sm_120) cards against a reference case, gated step by step against idol-sdk's float32 run as on Metal, and refuses other GPUs by name (#1767, for #1757). Thanks to @jayleaton, with device runs from @GustavBlack and @Nipale-ai.

- Docs: the drafter training recipe gains a section on adapting an already released drafter, budgeted from a few passes over the scarcest class at a low learning rate with early checkpoints, with the Qwen3.8-27B pilot behind it (#3369, refs #2667). Thanks to @Maxrio9.

- Desktop: searching the current conversation no longer carries a project picked under All saved conversations; the request, its results, filters and navigation use the scope's own project filter, and switching back restores the project (#3900, fixes #3849). Thanks to @AIFlowML.
Expand Down
2 changes: 1 addition & 1 deletion THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ These follow a model's release code or a library's model code for their math, ro
- `zig/src/vision/qwen_cuda.zig`: `Qwen3_5VisionModel` in transformers.
- `zig/src/core/picture/patches_test.zig`: recorded image-processor output data from `Lfm3VlImageProcessor` and `Qwen2VLImageProcessor` in transformers; the processing implementation is described below.
- `zig/src/families/flashnext/rotary_config.zig`: `_compute_yarn_parameters` in transformers, for the 64 rotary dims.
- `zig/kernels/metal/idol.metal`: the rounding points of Idol's denoiser in [speridlabs/idol-sdk](https://github.com/speridlabs/idol-sdk) at `4702a7f0`. Copyright speridlabs, Apache License 2.0; see [the license text](LICENSES/Apache-2.0.txt).
- `zig/kernels/metal/idol.metal`, `zig/kernels/cuda/idol.cu` and `zig/kernels/cuda/idol_attention.cuh`: the rounding points of Idol's denoiser in [speridlabs/idol-sdk](https://github.com/speridlabs/idol-sdk) at `4702a7f0`. Copyright speridlabs, Apache License 2.0; see [the license text](LICENSES/Apache-2.0.txt).

transformers is Copyright The HuggingFace Team, Apache License 2.0; see [the license text](LICENSES/Apache-2.0.txt).

Expand Down
61 changes: 61 additions & 0 deletions docs/recipes/idol-cuda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Idol's denoiser on CUDA

Idol's denoiser (see `idol.md`) on the CUDA runtime, beside the Metal family and driven by the same case driver
(`zig/tests/idol_run.zig`): `tf-idol` on Metal and on CUDA reads the same case and runs the same gates. The image
encoders, the decoders and the PLY writer are not ported, and nothing registers with the lane engine or the server.

**Where it has run.** The kernel contract and the synthetic case have passed on a GB10 (sm_121) and on an RTX 5090
(sm_120).

- GB10, nvcc 13.0, on `05ab1990a` (GustavBlack's [run][gb10-current] of 15 Nov on #1767): `idol-contract` gives
`SUMMARY idol: 13 kernels, 13 pass gates 1-4, 0 fail; 3 controls: 3 red as planted, 0 missed`, and `tf-idol` on the
shared synthetic case (`idol-synthetic-case-2731c229`) has 100 of 100 branch-steps within the gate, all 23 joint
blocks passing at `blocks 0` and a repeat with identical bytes; its 50 steps took 53.04 s. Its peak memory is not
recorded yet.
- Earlier GB10 contract runs on `776a3335d` ([run][gb10]) and on `c3a6c0cb7`, after the controls moved to their own
header ([run][gb10-rerun]), gave the same SUMMARY line. Both come before `36828402d`, which recompiled the norm
kernels.
- RTX 5090, CUDA 13.3 (nvcc 13.3.73), on `f5b88dd98` ([run][rtx5090]): `idol-contract` gives the same SUMMARY line,
and `tf-idol` on the shared synthetic case (`idol-synthetic-case-2731c229`) has 100 of 100 branch-steps within the
gate and a repeat with identical bytes. Idol's CUDA sources are unchanged since `f5b88dd98`.

[gb10-current]: https://github.com/ashhart/TensorFold/pull/1767#issuecomment-6886995407
[gb10]: https://github.com/ashhart/TensorFold/pull/1767#issuecomment-6777718609
[gb10-rerun]: https://github.com/ashhart/TensorFold/pull/1767#issuecomment-6802382536
[rtx5090]: https://github.com/ashhart/TensorFold/pull/1767#issuecomment-6869833180

`Model.load` admits sm_121 (GB10) and sm_120 (RTX 50, RTX PRO Blackwell) and refuses any other GPU by name.

## Precision

The same contract as on Metal, in CUDA's own terms:

- fp16 block projections on cuBLASLt (`CUBLAS_COMPUTE_32F`, fp16 inputs, fp32 output); `idol.cu` adds the bias to
those fp32 sums and rounds once to fp16, GELU after it.
- RePo's maps, the condition embedding and the output projection in fp32 on cuBLASLt with `CUBLAS_COMPUTE_32F` and
fp32 inputs: true fp32 (no TF32), so no hi/lo split is needed here.
- LayerNorms in fp32, rounded to fp16; the modulation in fp16 ops.
- Attention: `idol_attention.cuh`, head 64, fp16 q, k and v, fp32 scores, softmax and sums, scale 1/8, every query row
to every key row. It is Idol's own kernel: no shared attention template gains an instance.
The softmax denominator sums the fp32 P, and P is rounded to fp16 only for P·V; Metal's `id_attention` rounds P to
fp16 first and sums the rounded values.
- `idol.cu` builds with the glue flags (`--fmad=false`, IEEE division and square root). `F.normalize`'s clamp keeps a
NaN norm, as on Metal.

## Kernel contract

`tf-cuda-test idol-contract` runs gates 1-4 over every `idol.cu` kernel and the attention, with three controls that
each drop one fp16 rounding point; the full contract runs it among its family sets. Gate-5 records
(`zig/src/core/contract/idol_cuda_records.zig`) are nvcc 13.0's for sm_80, 86, 89, 120 and 121. On a GB10 and on
an RTX 5090 it gives the SUMMARY line above. On the 5090, nvcc 13.3's registers for four launches differ from the 13.0
records, all within their bounds.

## Run a case

```sh
zig build idol-cuda
zig-out/bin/tf-idol WEIGHTS case/
zig-out/bin/tf-idol WEIGHTS case/ blocks 0
```

The case comes from `tools/zig/idol_case.py`, as in `idol.md`.
2 changes: 1 addition & 1 deletion zig/build/cuda.zig
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu
for (exlr8_build.denseModules(b, target, optimize, exlr8, exlr8_tests[0])) |m| runner.addImport(m.name, m.module);
runner.addImport("glm_cuda", glmCuda(b, target, optimize, cuda, mods.core, mods.lanes, mods.heat, mods.api));
@import("minimax_cuda.zig").targets(b, target, optimize, strip, cuda, mods.core, mods.lanes, runner);
for ([_]struct { []const u8, *std.Build.Module }{ .{ "kolibri1", kolibri1Module(b, target, optimize, cuda, mods.core, mods.lanes) }, .{ "dory", @import("dory.zig").module(b, target, optimize, cuda, mods.core, mods.lanes) } }) |m| runner.addImport(m[0], m[1]);
for ([_]struct { []const u8, *std.Build.Module }{ .{ "kolibri1", kolibri1Module(b, target, optimize, cuda, mods.core, mods.lanes) }, .{ "dory", @import("dory.zig").module(b, target, optimize, cuda, mods.core, mods.lanes) }, .{ "idol_cuda", @import("idol_cuda.zig").targets(b, target, optimize, strip, cuda, mods.core) } }) |m| runner.addImport(m[0], m[1]);
runner.addImport("gemma4_cuda", @import("gemma4_cuda.zig").module(b, target, optimize, cuda, mods.core, mods.lanes));
runner.addImport("spark25", @import("spark25.zig").module(b, target, optimize, cuda, mods.core, mods.lanes));
runner.addImport("moss_image_cuda", b.createModule(.{ .root_source_file = b.path("zig/src/families/moss_image/cuda_kernels.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "cuda", .module = cuda }} }));
Expand Down
1 change: 1 addition & 0 deletions zig/build/cuda_family_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn steps(b: *std.Build, cuda: *std.Build.Module, mods: anytype, step: *std.B
b.step("test-memory-pressure-host", "Shared memory-pressure governor, admission and cache shedding without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = mods.api, .filters = &.{"memory pressure:"} })).step);
b.step("test-qwen35-shapes-host", "Captured window buckets for one and 2-8 rows without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = mods.qwen35, .filters = &.{"one-row and 2-8-row"} })).step);
@import("minimax_cuda.zig").hostTests(b, host, cuda, mods.core, mods.lanes, step);
@import("idol_cuda.zig").hostTests(b, cuda, mods.core, step);
@import("cuda_groups_host.zig").host(b, cuda, mods, step);
const prefill = b.addRunArtifact(b.addTest(.{ .root_module = mods.qwen35, .filters = &.{ "Qwen stepped prefill:", "Qwen whole prefill:", "Qwen prefill opening:", "a yielded pass keeps its completed prefix" } }));
b.step("test-qwen35-prefill-host", "Stepped, whole, opening and interrupted prompt lifecycle without devices").dependOn(&prefill.step);
Expand Down
1 change: 1 addition & 0 deletions zig/build/cuda_kernels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub const kernels = [_]Kernel{
.{ .name = "glm_index", .flags = &.{"-O3"} }, // a prompt chunk's DSA scores and top-512 pools
.{ .name = "minimax_m3", .flags = glue }, // ours: MiniMax-M3.1-Flash's glue (norms, RoPE prep, routing, DSpark, tower RoPE)
.{ .name = "minimax_m3_attn", .flags = glue }, // ours: MiniMax-M3.1-Flash's indexer and block-sparse attention
.{ .name = "idol", .flags = glue }, // ours: Idol's denoiser glue and its fp16 head-64 attention
.{ .name = "glm_quant", .flags = torch_ops }, // ours: GLM's draft-only weight quantizers, torch at load in the Python family
.{ .name = "exl3_linear", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // exl3/linear.cu's device code, tensorfold_exl3_linear_v5
.{ .name = "exl3_experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // exl3/experts.cu's device code, tensorfold_exl3_experts
Expand Down
34 changes: 34 additions & 0 deletions zig/build/idol_cuda.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Idol's CUDA denoiser in the build: its kernels for tf-cuda-test's contract, tf-idol on CUDA, its host tests.
const std = @import("std");

/// The family's module over the runtime and the core.
pub fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, cuda: *std.Build.Module, core: *std.Build.Module) *std.Build.Module {
return b.createModule(.{ .root_source_file = b.path("zig/src/families/idol/cuda.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "cuda", .module = cuda }, .{ .name = "core", .module = core } } });
}

/// The launchers alone (idol.cu's kernels), as tf-cuda-test's contract imports them.
fn launchers(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, cuda: *std.Build.Module) *std.Build.Module {
return b.createModule(.{ .root_source_file = b.path("zig/src/families/idol/cuda_kernels.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "cuda", .module = cuda }} });
}

/// tf-idol, the case driver on the first GPU; returns the launchers for tf-cuda-test's `runner` (idol-contract).
pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, strip: ?bool, cuda: *std.Build.Module, core: *std.Build.Module) *std.Build.Module {
const tool = b.createModule(.{ .root_source_file = b.path("zig/tests/idol_cuda.zig"), .target = target, .optimize = optimize, .link_libc = true, .strip = strip, .imports = &.{ .{ .name = "cuda", .module = cuda }, .{ .name = "core", .module = core }, .{ .name = "idol", .module = module(b, target, optimize, cuda, core) } } });
const exe = b.addExecutable(.{ .name = "tf-idol", .root_module = tool });
b.installArtifact(exe);
b.step("idol-cuda", "Build tf-idol: Idol's denoiser on a reference case on CUDA").dependOn(&b.addInstallArtifact(exe, .{}).step);
return launchers(b, target, optimize, cuda);
}

/// The family's host tests (config, schedule, scratch, admission, launch geometry, contract ranges) in `all`.
pub fn hostTests(b: *std.Build, cuda: *std.Build.Module, core: *std.Build.Module, all: *std.Build.Step) void {
const host = b.graph.host;
const run = b.addRunArtifact(b.addTest(.{ .root_module = module(b, host, .debug, cuda, core) }));
const refs = b.createModule(.{ .root_source_file = b.path("zig/tests/cuda/contract_idol_host.zig"), .target = host, .optimize = .debug, .link_libc = true, .imports = &.{ .{ .name = "cuda", .module = cuda }, .{ .name = "core", .module = core }, .{ .name = "idol_cuda", .module = launchers(b, host, .debug, cuda) } } });
const ref_run = b.addRunArtifact(b.addTest(.{ .root_module = refs }));
const step = b.step("test-idol-cuda-host", "Idol's CUDA denoiser host tests and contract references (no GPU work)");
for ([_]*std.Build.Step{ &run.step, &ref_run.step }) |s| {
step.dependOn(s);
all.dependOn(s);
}
}
1 change: 1 addition & 0 deletions zig/kernels/cuda/contract_controls_set.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#include "contract_dense_controls.cuh"
#include "contract_experts_bf16_controls.cuh"
#include "contract_nemo_audio_controls.cuh"
#include "contract_idol_controls.cuh"
53 changes: 53 additions & 0 deletions zig/kernels/cuda/contract_idol_controls.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Gate 3: Idol's glue (idol.cu) with one fp16 rounding dropped each; the intervals hold idol-sdk's rounding points.
#pragma once

#include <cuda_fp16.h>
#include <math.h>

#include "common/reduce.cuh"

namespace tf_ctl_idol {
__device__ __forceinline__ float h(float x) { return __half2float(__float2half_rn(x)); }
__device__ __forceinline__ float ld(const __half* p) { return __half2float(*p); }
} // namespace tf_ctl_idol

// tf_idol_norm modulating the unrounded LayerNorm: fp16(fp16(y s1) + sh) where idol-sdk rounds y first.
extern "C" __global__ void __launch_bounds__(256) tf_ctl_idol_norm_late(const __half* X, const float* W, const float* B,
const __half* S1, const __half* SH, __half* Y,
int width, float eps, int mode) {
using namespace tf_ctl_idol;
__shared__ float part[8];
const __half* x = X + (size_t)blockIdx.x * width;
float a = 0.0f, q = 0.0f;
for (int i = threadIdx.x; i < width; i += 256) a += ld(x + i);
const float mean = tf_common::block_sum_serial(a, part) / (float)width;
for (int i = threadIdx.x; i < width; i += 256) q += (ld(x + i) - mean) * (ld(x + i) - mean);
const float inv = 1.0f / sqrtf(tf_common::block_sum_serial(q, part) / (float)width + eps);
for (int i = threadIdx.x; i < width; i += 256) {
float v = (ld(x + i) - mean) * inv;
v = mode == 1 ? h(v * W[i] + B[i]) : h(h(v * ld(S1 + i)) + ld(SH + i));
Y[(size_t)blockIdx.x * width + i] = __float2half_rn(v);
}
}

// tf_idol_gate_add with g y left in fp32: fp16(x + g y) where idol-sdk rounds g y to fp16 first.
extern "C" __global__ void __launch_bounds__(256) tf_ctl_idol_gate_add_once(__half* X, const __half* Y, const __half* G,
int width, int rows) {
using namespace tf_ctl_idol;
const int c = blockIdx.y * 256 + threadIdx.x, r = blockIdx.x;
if (c >= width || r >= rows) return;
const size_t i = (size_t)r * width + c;
X[i] = __float2half_rn(ld(X + i) + ld(G + c) * ld(Y + i));
}

// tf_idol_bias taking GELU of the fp32 sum: fp16(GELU(acc + b)) where idol-sdk rounds the linear's output first.
extern "C" __global__ void __launch_bounds__(256) tf_ctl_idol_bias_late(const float* ACC, const __half* B, __half* Y,
int width, int rows, int act) {
using namespace tf_ctl_idol;
const int c = blockIdx.y * 256 + threadIdx.x, r = blockIdx.x;
if (c >= width || r >= rows) return;
const size_t i = (size_t)r * width + c;
float v = ACC[i] + ld(B + c);
if (act) v = 0.5f * v * (1.0f + tanhf(0.7978845608028654f * (v + 0.044715f * v * v * v)));
Y[i] = __float2half_rn(act ? v : h(v));
}
Loading
Loading