Qwen3.6 closes the GDN layer with rms_norm(o) * ssm_norm * SiLU(z) where Flash-Next uses sigmoid(z) (study 3.2, inventory row 39; the oracle's negative control puts the two 1.07 relative L1 apart). `kernels::GdnGate` names the choice and every decode output kernel takes it as an argument: `gdn_out_norm` (legacy), `fused_gdn_step_norm` (the default native decode), `native_gdn_out_norm` (pinned unfused), and the verify window's `gdn_step_norm_multi`, which must stay bitwise the fused kernel. The sigmoid arithmetic is unchanged; SiLU is ggml's op_silu form z / (1 + exp(-z)). No global: the layer passes `ModelGeometry::gdn_gate()` (next commit). gdn_parity now runs the recurrence at both geometries, 16/48 (VPK 3, sigmoid) and 16/32 (VPK 2, SiLU), through all four implementations, checks the verify kernel bitwise against the fused one (verify, commit and split-commit paths), and makes the wrong gate a negative case through each kernel itself (86-125% apart), beside the existing four traps. The harness uses a blocking stream: its first version raced its own pageable memcpy resets on a non-blocking stream and reported the native kernels 7.5x off at one geometry. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017tPVMg2wGSNR1KANEiUtwr
41 lines
2.1 KiB
C++
41 lines
2.1 KiB
C++
#pragma once
|
|
#include "strata/kernels/gdn.hpp"
|
|
|
|
#include <cstdint>
|
|
|
|
namespace strata::kernels {
|
|
|
|
// Optional pinned CUDA GDN preprocessing. The layer selects these functions with
|
|
// native_gdn_enabled(); direct callers explicitly select them by calling them.
|
|
// Require a nonnull ordered stream, finite inputs, and four-byte aligned spans.
|
|
// No function allocates or synchronizes. All pointers are caller-owned.
|
|
|
|
// Four-tap convolution, then FP32 fast-math SiLU. History is [channels,3], oldest
|
|
// first; weights are [channels,4]. Both outputs are required, mutually disjoint,
|
|
// and disjoint from input/weights/history. History must not alias other spans.
|
|
void native_gdn_conv_silu(float* history, const float* input, const float* weights,
|
|
float* raw_output, float* silu_output, int64_t channels,
|
|
int64_t d_conv, void* stream);
|
|
|
|
// In-place [rows,128]: scale(rms_norm(x,epsilon/128),1/sqrt(128)). This includes
|
|
// the L2 normalization scale, but NOT the recurrence's readout scale.
|
|
// Epsilon is finite/nonnegative; epsilon=0 additionally requires nonzero rows.
|
|
void native_gdn_l2_norm(float* input, int64_t rows, int64_t cols, float epsilon, void* stream);
|
|
|
|
// In-place sigmoid over per-head beta; one token.
|
|
void native_gdn_beta_gate(float* beta, int64_t heads, void* stream);
|
|
|
|
// One token: gate[h] = softplus(alpha[h]+dt[h])*ssm_a[h], using the pinned CUDA
|
|
// log(1+exp(x)) expression and threshold 20. Output is disjoint from inputs.
|
|
void native_gdn_gate(const float* alpha, const float* dt, const float* ssm_a,
|
|
float* gate, int64_t heads, void* stream);
|
|
|
|
// [heads,128]: rms_norm(output,epsilon)*gamma*act(z), act sigmoid (qwen4exp) or
|
|
// SiLU (qwen35moe) per `GdnGate`. Gamma contains only 128 floats and broadcasts
|
|
// across heads. Destination is disjoint from inputs.
|
|
void native_gdn_out_norm(const float* output, const float* z, const float* gamma,
|
|
float* destination, int64_t heads, int64_t cols,
|
|
float epsilon, GdnGate act, void* stream);
|
|
|
|
} // namespace strata::kernels
|