Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a36c333
inkling2: size the vision projector from the config
ajensenwaud Nov 21, 2026
b2f486e
inkling2: refuse expert bit widths the grouped kernels cannot decode
ajensenwaud Nov 21, 2026
1c83b07
inkling2: test the expert and image refusals
ajensenwaud Nov 21, 2026
c902fed
inkling2: orient RGBA pictures with core picture's pixel map
ajensenwaud Nov 21, 2026
1a6c4ae
inkling2: wrap the two long kernel table lines
ajensenwaud Nov 21, 2026
c7f817f
inkling2: say why the vision rotary and scaled add stay in the family
ajensenwaud Nov 21, 2026
b835783
inkling2: run vision attention on the core ViT kernel
ajensenwaud Nov 23, 2026
f06e949
exl3: give the grouped expert kernel 32-member tiles
ajensenwaud Nov 21, 2026
92b3d70
exl3: add Inkling 2's softcapped SwiGLU as a gate/up epilogue
ajensenwaud Nov 21, 2026
b644280
exl3: define the wide grouped kernel before the others
ajensenwaud Nov 21, 2026
0abffb1
exl3: take any codebook, 32-member items and softcaps in runWith
ajensenwaud Nov 21, 2026
5ee7b0c
inkling2: run the experts on the core grouped kernel
ajensenwaud Nov 21, 2026
f9d7b2a
inkling2: use the core softcapped epilogue for the experts
ajensenwaud Nov 21, 2026
c7d53af
core: one image-rows module for the four vision families
ajensenwaud Nov 21, 2026
0272975
vit: give the pointwise kernel a gamma mode
ajensenwaud Nov 21, 2026
3bdcd49
qwen27: export core's image rows from the roots Qwen 2.7 builds against
ajensenwaud Nov 22, 2026
34a1360
exl3: round the capped expert epilogue as written
ajensenwaud Nov 24, 2026
1290df7
inkling2: DSpark drafter kernels under the kernel contract
ajensenwaud Nov 20, 2026
18a5d27
inkling2: shorten five DSpark test comments to 120 columns
ajensenwaud Nov 21, 2026
ae4cd19
inkling2: use the common warp sum in the DSpark kernels
ajensenwaud Nov 21, 2026
e9071ff
inkling2: say why DSpark keeps its own SiLU and add-norm
ajensenwaud Nov 21, 2026
2c6cd0d
inkling2: refuse DSpark head shapes the kernels do not hold
ajensenwaud Nov 21, 2026
7b88260
inkling2: refuse a DSpark key window longer than the cache ring
ajensenwaud Nov 21, 2026
1165b29
act rows: add a SiLU mode to the SwiGLU rows kernel
ajensenwaud Nov 21, 2026
6bc448e
tools: catch camelCase copies of the common reductions
ajensenwaud Nov 21, 2026
069350b
inkling2: name the core SiLU kernel in the DSpark glue tests
ajensenwaud Nov 21, 2026
abbc9e7
dspark: one pick kernel for MiniMax M3 and Inkling 2
ajensenwaud Nov 21, 2026
51ef8b5
inkling2: keep the DSpark records pending for nvcc 13.2
ajensenwaud Nov 21, 2026
23b8c33
inkling2: preserve Mini ModelOpt reference helpers
ashhart Nov 26, 2026
4347a56
adapt: allow frozen-main loop math reduction copies
ashhart Nov 26, 2026
dec8c80
adapt: restore Inkling decode and Router contracts
ashhart Nov 26, 2026
487cee8
adapt: restore Router guards and vision scale control
ashhart Nov 26, 2026
df640e4
tests: re-pin zig/kernels/cuda/experts.cu after its expert-id range g…
ashhart Nov 27, 2026
74d3676
tests: the dense serving check takes experts.cu's new hash, as gradie…
ashhart Nov 27, 2026
65c4ad0
changelog: #4128 under Unreleased
ashhart Nov 27, 2026
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

- Inkling 2 Small on CUDA: DSpark drafter kernels; drafted output stays byte-identical to plain decoding, and the shared expert planner now skips out-of-range expert ids (#4128). Thanks to @ajensenwaud.

- Core: TFQ3 records and wire constants live in one shared copy that every backend uses; layouts, constants and output are unchanged (#5281). Thanks to @jschmied.

- CUDA: `TF_CUDA_SCHED=blocking` (off by default; also `auto`, `spin` or `yield`) sets how a served model's host thread waits for its GPU. Blocking frees the core the driver's default spins on a GB10, with identical tokens and pictures; on Inkling 2 Mini decode is about 2% slower (#5165).
Expand Down
8 changes: 8 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,11 @@ in `prompt_cases.json` and `mini_cases.json`, which the release's `encoding_erni
produced through the Hugging Face transformers and tokenizers libraries. `zig/src/families/ernie5_5/prompt.zig` writes
the text part of that chat encoding in TensorFold's own code, written after reading `encoding_ernie.py` and checked
against those outputs; no source is copied. `tools/zig/ernie5_5_fixtures.py` rebuilds all of these files.
## Inkling 2 DSpark drafter kernels

`zig/kernels/cuda/inkling2/dspark.cu` and `zig/src/families/inkling2/dspark_ops.zig` compute the drafter in
`vllm/models/inkling2/nvidia/dspark.py` at commit `abb8194dc35e` of
[vllm-project/vllm](https://github.com/vllm-project/vllm) (Apache-2.0): the tap mix and its RMS norm in
`Inkling2DSparkDecoder.mix`, `Inkling2DraftSelfAttention`, `Inkling2DraftMLP` and the recurrent `Inkling2MarkovHead`.
The drafter's weights ship in Thinking Machines' Inkling 2 Small release under Apache-2.0. The kernels are TensorFold's
own.
6 changes: 6 additions & 0 deletions tools/zig/cuda_common_allowlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
{"path":"zig/kernels/cuda/flashnext_gdn_tpr.cuh","kind":"asm:cp.async.wait_group","fingerprint":"f39f99cfddd23a17f459f43825e9603b36fb1dac7f464d7bec5fec0f40da73c8","count":1,"reason":"This cp.async.wait_group uses its literal pending-group count at this dependency boundary; a helper substitution needs the same immediate, scheduling and machine code."},
{"path":"zig/kernels/cuda/glm_triton.cuh","kind":"definition:block_sum","fingerprint":"c668775654a3913f9ca96e2b23f2d4be09aef3b2ecbe60e46d06f7a510cecbbb","count":1,"reason":"Triton NW-dependent butterfly and early return; different reduction order."},
{"path":"zig/kernels/cuda/glm_vision.cu","kind":"definition:block_sum","fingerprint":"679cb663bd7688332a53b69d2a4ecbf5d94ba8f0b9318aa279f21e1586fa5d41","count":1,"reason":"Tree reduction owns shared scratch and broadcasts through total; shape differs from shared tree."},
{"path":"zig/kernels/cuda/inkling2/attention.cu","kind":"definition:warpSum","fingerprint":"23eaa1ba706617a178d504e531ed1537b557d8428c2b881a3ffc6e92c07b8f76","count":1,"reason":"Inkling 2's attention keeps its xor butterfly, offsets 16 down to 1, the order tf_common::warp_sum uses; the swap needs identical SASS on the family's images."},
{"path":"zig/kernels/cuda/inkling2/dspark.cu","kind":"definition:blockSum","fingerprint":"6e1159a5a63b8da0f60b6ae6fdbccfa959c996a2d255066335d30a21b642b7c2","count":1,"reason":"Core block_sum_tree compiles to different SASS; this broadcast form keeps the DSpark kernels' recorded machine code."},
{"path":"zig/kernels/cuda/inkling2/loop_math.cu","kind":"definition:warpSum","fingerprint":"23eaa1ba706617a178d504e531ed1537b557d8428c2b881a3ffc6e92c07b8f76","count":1,"reason":"loop_math retains its xor butterfly reduction order; replacing shared primitives needs numerics/machine-code equivalence validation."},
{"path":"zig/kernels/cuda/inkling2/loop_math.cu","kind":"definition:blockSums","fingerprint":"b27793c7753efc6f05f40e217257b9449ab9ac258f77c2aa537342aa1e999566","count":1,"reason":"loop_math retains its fixed N-value reduction order; replacing shared primitives needs numerics/machine-code equivalence validation."},
{"path":"zig/kernels/cuda/inkling2/ops.cu","kind":"definition:blockSums","fingerprint":"60bc85468608b496a7c788416a3db98223e96585e76d8842367bea5c21d1c0e2","count":1,"reason":"Sums N values a thread in one pass behind one pair of barriers; the shared block sums take one value a call."},
{"path":"zig/kernels/cuda/inkling2/ops.cu","kind":"definition:warpSum","fingerprint":"23eaa1ba706617a178d504e531ed1537b557d8428c2b881a3ffc6e92c07b8f76","count":1,"reason":"Inkling 2's glue keeps its xor butterfly, offsets 16 down to 1, the order tf_common::warp_sum uses; the swap needs identical SASS on the family's images."},
{"path":"zig/kernels/cuda/lfm2.cu","kind":"definition:block_sum","fingerprint":"d9816f70067e6b5d8b584e4a323f9aa0c84309292758719e0b2f1364e66d6c67","count":1,"reason":"Serial sum starts at red[0] with family-specific barriers; retain order and signed-zero behavior."},
{"path":"zig/kernels/cuda/minimax_m3.cuh","kind":"asm:mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32","fingerprint":"edff3872cb8a0cba7404cb7e391b3fdfdabee3a8109294582e49b95953721be9","count":1,"reason":"Expert projections retain the mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32 accumulator and operand constraints; a shared substitution needs machine-code identity checks."},
{"path":"zig/kernels/cuda/minimax_m3.cuh","kind":"definition:block_sum","fingerprint":"5cdf621633053e5319eafb758a82aa96a7b2716308018e821e84724de1c518dc","count":1,"reason":"Leading-sync serial block sum with no trailing sync; deliberate shape variant."},
Expand Down
2 changes: 1 addition & 1 deletion tools/zig/cuda_common_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ALLOW = Path(__file__).with_name("cuda_common_allowlist.json")
TOKEN = re.compile(r'//[^\n]*|/\*[\s\S]*?\*/|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|[A-Za-z_]\w*|\d+(?:\.\d*)?|[^\s]')
OPS = re.compile(r'\b(?:ldmatrix[.\w]*|mma\.sync[.\w]*|cp\.async[.\w]*|ld\.global\.nc[.\w]*|griddepcontrol[.\w]*)')
NAMES = re.compile(r'(?:warp_sum|block_sum\w*|fp4pair|fp8pair|e4m3f|unpack8|pack8)\Z')
NAMES = re.compile(r'(?:[wW]arp_?[sS]um|[bB]lock_?[sS]um\w*|fp4pair|fp8pair|e4m3f|unpack8|pack8)\Z')


@dataclass(frozen=True)
Expand Down
7 changes: 7 additions & 0 deletions tools/zig/cuda_common_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def test_every_requested_instruction_and_definition(self):
self.unit.write_text(DEFINITION + DEFINITION.replace("warp_sum", name))
self.assertIn("definition:" + name, " ".join(self.errors()))

def test_camel_case_reductions(self):
for name in ("warpSum", "WarpSum", "blockSum", "blockSums", "BlockSumTree"):
self.unit.write_text(DEFINITION + DEFINITION.replace("warp_sum", name))
self.assertIn("definition:" + name, " ".join(self.errors()))
self.unit.write_text(DEFINITION + DEFINITION.replace("warp_sum", "warpSumOf"))
self.assertEqual(self.errors(), [])


if __name__ == "__main__":
unittest.main()
10 changes: 7 additions & 3 deletions zig/build/cuda_kernels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,18 @@ pub const kernels = [_]Kernel{
.{ .name = "idol_decoder", .flags = glue }, // ours: Idol's decoders' stem, to_kv, head norms and attention
.{ .name = "inkling2_attn", .src = "inkling2/attention", .flags = &.{"-O3"} }, // ours: Inkling 2's relative-bias attention
.{ .name = "inkling2_pattn", .src = "inkling2/prompt_attention", .flags = &.{"-O3"} }, // ours: Inkling 2's global-layer prompt attention
.{ .name = "inkling2_ops", .src = "inkling2/ops", .flags = glue }, // ours: Inkling 2's residual mix, convs, router, SwiGLU
.{ .name = "inkling2_ops", .src = "inkling2/ops", .flags = glue }, // ours: Inkling 2's residual mix, convs, router
.{ .name = "inkling2_rows", .src = "inkling2/rows", .flags = glue }, // ours: Inkling 2's router row dots on prompt rows
// ours: Inkling 2's DSpark drafter glue
.{ .name = "inkling2_dspark", .src = "inkling2/dspark", .flags = glue },
.{ .name = "ricursive", .flags = glue }, // ours: Ripple's glue (embed, add-norms, output gate, FFN activation), glue.metal step for step
.{ .name = "ricursive_prep", .flags = glue }, // ours: Ripple's attention prep (q/k head norms, RoPE, K and V into rings or pages)
.{ .name = "inkling2_experts", .src = "inkling2/experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // ours: Inkling 2's grouped experts
// ours: Inkling 2's Mini ModelOpt reference helpers
.{ .name = "inkling2_experts", .src = "inkling2/experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } },
.{ .name = "inkling2_modelopt", .src = "inkling2/modelopt", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // Mini packed experts on BF16 activations
.{ .name = "inkling2_loop_math", .src = "inkling2/loop_math", .flags = &.{"-O3"} }, // Mini residuals, cross-pass messages, gates and split QKV
.{ .name = "inkling2_vision", .src = "inkling2/vision", .flags = glue }, // ours: Inkling 2's vision tower glue and attention
// ours: Inkling 2's vision tower glue
.{ .name = "inkling2_vision", .src = "inkling2/vision", .flags = glue },
.{ .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
2 changes: 1 addition & 1 deletion zig/dense_serving_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn hash(bytes: []const u8) [64]u8 {
return std.fmt.bytesToHex(h, .lower);
}
test "dense serving: owned CUDA images retain their reviewed lane and decode bytes" {
try std.testing.expectEqualStrings("2a9b3989f3baaef5eadb56abfb8520700449bd910f2b00345703c22dbf758b8c", &hash(@embedFile("kernels/cuda/experts.cu")));
try std.testing.expectEqualStrings("adc0f015f08b49e65df25fe17ef2489dd924d8ba6cfccd1f008be5cd1edbd464", &hash(@embedFile("kernels/cuda/experts.cu")));
try std.testing.expectEqualStrings("578e9a607f678f0547aaeb312d18252ea0608bad7fe71bb2d5241d28adf31bac", &hash(@embedFile("kernels/cuda/experts_pack.cu")));
try std.testing.expectEqualStrings("5f325dc6d8134624b30b5e99c5764f75beb3c344b5f949d38bfaa41bc8dfe5dc", &hash(@embedFile("kernels/cuda/experts_prefill.cu")));
try std.testing.expectEqualStrings("e5ef9dcce75c478e59e476d2fa8747baee2317bd283b0756f125ea050dad9228", &hash(@embedFile("kernels/cuda/gdn.cu")));
Expand Down
38 changes: 32 additions & 6 deletions zig/kernels/cuda/act_rows.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ __device__ __forceinline__ float sigmoid(float x) { return tf_common::sigmoid_rn

using namespace tf_act;

// out[r, i] = bf16(silu(gate[r * g_ld + i]) * up[r * u_ld + i]) for i < n (n % 64 == 0); xs (or null) out's sums.
extern "C" __global__ void __launch_bounds__(NT) tf_swiglu_rows(const __nv_bfloat16* __restrict__ gate, long long g_ld,
const __nv_bfloat16* __restrict__ up, long long u_ld,
__nv_bfloat16* __restrict__ out, float* __restrict__ xs,
int n) {
namespace tf_act {

// silu(g) * u: core's g * sigmoid(g), or with Torch torch's g / (1 + expf(-g)), each step rounded as written.
template <bool Torch>
__device__ __forceinline__ float silu_mul(float g, float u) {
if (Torch) return __fmul_rn(__fdiv_rn(g, __fadd_rn(1.0f, expf(-g))), u);
return __fmul_rn(__fmul_rn(g, sigmoid(g)), u);
}

template <bool Torch>
__device__ __forceinline__ void swiglu_rows(const __nv_bfloat16* __restrict__ gate, long long g_ld,
const __nv_bfloat16* __restrict__ up, long long u_ld,
__nv_bfloat16* __restrict__ out, float* __restrict__ xs, int n) {
const int64_t r = blockIdx.x;
const int c = blockIdx.y * blockDim.x + threadIdx.x; // 8 values
const bool live = 8 * c < n;
Expand All @@ -36,7 +44,7 @@ extern "C" __global__ void __launch_bounds__(NT) tf_swiglu_rows(const __nv_bfloa
unpack8(*reinterpret_cast<const uint4*>(up + r * u_ld + 8 * c), u);
}
#pragma unroll
for (int i = 0; i < 8; ++i) o[i] = live ? __fmul_rn(__fmul_rn(g[i], sigmoid(g[i])), u[i]) : 0.f;
for (int i = 0; i < 8; ++i) o[i] = live ? silu_mul<Torch>(g[i], u[i]) : 0.f;
const uint4 op = pack8(o);
if (live) *reinterpret_cast<uint4*>(out + r * n + 8 * c) = op;
if (xs != nullptr) {
Expand All @@ -45,6 +53,24 @@ extern "C" __global__ void __launch_bounds__(NT) tf_swiglu_rows(const __nv_bfloa
}
}

} // namespace tf_act

// out[r, i] = bf16(silu(gate[r * g_ld + i]) * up[r * u_ld + i]) for i < n (n % 64 == 0); xs (or null) out's sums.
extern "C" __global__ void __launch_bounds__(NT) tf_swiglu_rows(const __nv_bfloat16* __restrict__ gate, long long g_ld,
const __nv_bfloat16* __restrict__ up, long long u_ld,
__nv_bfloat16* __restrict__ out, float* __restrict__ xs,
int n) {
tf_act::swiglu_rows<false>(gate, g_ld, up, u_ld, out, xs, n);
}

// tf_swiglu_rows with torch's silu, g / (1 + expf(-g)): Inkling 2's DSpark drafter (expf, not tf_exp, for its bits).
extern "C" __global__ void __launch_bounds__(NT) tf_swiglu_rows_expf(const __nv_bfloat16* __restrict__ gate, long long g_ld,
const __nv_bfloat16* __restrict__ up, long long u_ld,
__nv_bfloat16* __restrict__ out, float* __restrict__ xs,
int n) {
tf_act::swiglu_rows<true>(gate, g_ld, up, u_ld, out, xs, n);
}

// out[r, h * d + e] = bf16(o[r, h * d + e] * sigmoid(g[r * g_ld + h * g_hs + e])) (d % 64 == 0); xs (or null) its sums.
extern "C" __global__ void __launch_bounds__(NT) tf_gate_rows(const __nv_bfloat16* __restrict__ o,
const __nv_bfloat16* __restrict__ g, long long g_ld,
Expand Down
26 changes: 26 additions & 0 deletions zig/kernels/cuda/common/dspark_pick.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// DSpark's pick merge, one body for every family: the ranks' gathered (value, id) picks to the walk's next token.
#pragma once

#include <math_constants.h>

namespace tf_common {

// Thread 0, picks stride bytes apart: the largest value, the lower id on a tie, kNone when none beats -Inf.
template <int kNone>
__device__ __forceinline__ void dspark_pick(const unsigned char* __restrict__ picks, int world, int stride,
int* __restrict__ walk, int j) {
if (threadIdx.x != 0) return;
float best = -CUDART_INF_F;
int id = kNone;
for (int q = 0; q < world; ++q) {
const float v = *reinterpret_cast<const float*>(picks + (size_t)q * stride);
const int k = *reinterpret_cast<const int*>(picks + (size_t)q * stride + 4);
if (v > best || (v == best && k < id)) {
best = v;
id = k;
}
}
walk[j + 1] = id;
}

} // namespace tf_common
64 changes: 54 additions & 10 deletions zig/kernels/cuda/exl3_experts.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ constexpr int GROUPED_LOAD = tf_exl3::AHEAD;
constexpr int GROUPED_LOAD = tf_exl3::PLAIN;
#endif

// Defined before the others: nvcc 13.3 then leaves tf_exl3_grouped_2's sm_12x SASS as it was.
extern "C" __global__ void tf_exl3_grouped_wide_2(tf_exl3::GroupedArgs a) { // mul1, 64 columns by 32 members
tf_exl3::grouped_body<2, 4, 4, GROUPED_LOAD, 2>(a, blockIdx.x, blockIdx.y, blockIdx.z);
}

extern "C" __global__ void tf_exl3_grouped_0(tf_exl3::GroupedArgs a) { // 3inst, any width
tf_exl3::grouped_body<0, 8, 4, GROUPED_LOAD>(a, blockIdx.x, blockIdx.y, blockIdx.z);
}
Expand Down Expand Up @@ -145,13 +150,9 @@ struct GateUpArgs {
int act_mode;
};

extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
const int p = blockIdx.x, blk = blockIdx.y;
const int e = a.pick[p];
if (e < 0 || e >= a.experts) return;
const int lane = threadIdx.x;
const int n = blk * 128 + 4 * lane;
float gv[4], uv[4];
// The gate and up splits of pair p summed in order and rotated back (before the scales).
__device__ __forceinline__ void gateup_sums(const GateUpArgs& a, int p, int n, int lane, float (&gv)[4],
float (&uv)[4]) {
#pragma unroll
for (int j = 0; j < 4; ++j) {
float sg = 0.f, su = 0.f;
Expand All @@ -164,6 +165,24 @@ extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
}
fwht128(gv, lane);
fwht128(uv, lane);
}

// The activations rotated into the down projection's inputs.
__device__ __forceinline__ void gateup_store(const GateUpArgs& a, int p, int n, int lane, float (&v)[4]) {
fwht128(v, lane);
half* o = a.xd + (size_t)p * a.n + n;
#pragma unroll
for (int j = 0; j < 4; ++j) o[j] = __float2half_rn(v[j] * HAD_SCALE);
}

extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
const int p = blockIdx.x, blk = blockIdx.y;
const int e = a.pick[p];
if (e < 0 || e >= a.experts) return;
const int lane = threadIdx.x;
const int n = blk * 128 + 4 * lane;
float gv[4], uv[4];
gateup_sums(a, p, n, lane, gv, uv);
float v[4];
#pragma unroll
for (int j = 0; j < 4; ++j) {
Expand All @@ -181,10 +200,35 @@ extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
}
v[j] = act * __half2float(a.suh_d[(size_t)e * a.n + n + j]);
}
fwht128(v, lane);
half* o = a.xd + (size_t)p * a.n + n;
gateup_store(a, p, n, lane, v);
}

// act_mode 3, Inkling 2's softcapped SwiGLU: gate_cap tanh(g / gate_cap) sigmoid(g) up_cap tanh(u / up_cap), fp32.
struct CappedArgs {
GateUpArgs g;
float gate_cap, up_cap;
};

extern "C" __global__ void tf_exl3_gateup_capped(const CappedArgs c) {
const GateUpArgs& a = c.g;
const int p = blockIdx.x, blk = blockIdx.y;
const int e = a.pick[p];
if (e < 0 || e >= a.experts) return;
const int lane = threadIdx.x;
const int n = blk * 128 + 4 * lane;
float gv[4], uv[4];
gateup_sums(a, p, n, lane, gv, uv);
float v[4];
#pragma unroll
for (int j = 0; j < 4; ++j) o[j] = __float2half_rn(v[j] * HAD_SCALE);
for (int j = 0; j < 4; ++j) {
const float g = gv[j] * HAD_SCALE * __half2float(a.svh_g[(size_t)e * a.n + n + j]);
const float u = uv[j] * HAD_SCALE * __half2float(a.svh_u[(size_t)e * a.n + n + j]);
// Each product and the sum round on their own: core's flags would otherwise fuse them into FMAs.
const float gs = __fmul_rn(__fmul_rn(c.gate_cap, tanhf(g / c.gate_cap)), 1.f / __fadd_rn(1.f, expf(-g)));
const float act = __fmul_rn(__fmul_rn(gs, c.up_cap), tanhf(u / c.up_cap));
v[j] = __fmul_rn(act, __half2float(a.suh_d[(size_t)e * a.n + n + j]));
}
gateup_store(a, p, n, lane, v);
}

// Program (member row, 128-block of the width): down epilogue and combine in one launch, the same bits as the two.
Expand Down
Loading
Loading