Skip to content
Closed
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
Next Next commit
DeepSeek V4.1: the family's comments on one line each, within the 120…
…-column rule

Folds the remaining comment groups in the V4.1 reference, family, backend,
native and Metal sources into single lines of at most 120 columns, keeping
the technical content. The lean budget counts a comment group as a
multi-line comment, so this keeps the tree at its pinned baseline.
  • Loading branch information
akol1 committed Oct 26, 2026
commit 00a3241cd433111f5e5ab98bf2d4ecf4018c1019
4 changes: 1 addition & 3 deletions zig/kernels/metal/core/exl3_projection.metal
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ kernel void tf_exl3_state_window_check(const device uint4* inputs [[buffer(0)]],
outputs[tid] = tf_exl3_mapped_state(tile, (off << 6) | (1u << 11));
}

// A kept-dense matrix's plain product: the rotated rows times the bf16 weight, accumulated
// in f32 in the sums region the rotate_out stage reads. Sequential k, one thread an output
// element — the fp64 reference mirrors this order.
// Kept-dense: rotated rows x bf16 weight, f32 in rotate_out sums; sequential k, one thread an output, in fp64 order.
kernel void tf_exl3_dense(const device half* rotated [[buffer(0)]],
const device bfloat* weight [[buffer(1)]],
device float* sums [[buffer(2)]],
Expand Down
6 changes: 2 additions & 4 deletions zig/kernels/metal/sources.zig
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ pub const nemotron_head = @embedFile("nemotron_head.metal");
/// Keyed draws over the whole vocabulary where tf_gpu_sample would keep only its 1,024 candidates.
pub const nemotron_sample = @embedFile("nemotron_sample.metal");

/// Sliding Weights: the learned change in the forward and the bounded step on captured rows.
/// Learning in the weights: a low-rank change at every layer, and the gradients through each kind of layer to it.
/// Sliding Weights: the learned forward change and bounded captured-row steps; per-layer low-rank change and gradients.
pub const train = @embedFile("train.metal");
pub const train_mixers = @embedFile("train_mixers.metal");

Expand Down Expand Up @@ -151,8 +150,7 @@ pub const flashnext_gen = @import("flashnext/sources_gen.zig");
pub const packed_metallib = @import("nemotron_packed_metallib").bytes;
/// The core lane projection (tensor units): every window row's sums in one weight read, and its row order.
pub const core_expert_groups = @embedFile("core/expert_groups.metal");
/// DeepSeek V4.1 Flash: Engram hashing and commit, sparse/compressed attention, the
/// hyperconnection mix, routed experts, shared projections, the cache and rotary glue.
/// DeepSeek V4.1 Flash: Engram hash/commit, CSA attention, mHC mix, routed experts, shared projections, cache/rotary.
pub const deepseek_v41_engram = @embedFile("deepseek_v41/engram.metal");
pub const deepseek_v41_ops = @embedFile("deepseek_v41/ops.metal");
pub const deepseek_v41_mhc = @embedFile("deepseek_v41/mhc.metal");
Expand Down
5 changes: 1 addition & 4 deletions zig/src/core/exl3_projection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ pub const DenseMatrix = struct {
n: usize,
};

/// The kept-dense path: the same rotate stages as the quantized encode, with the trellis
/// product replaced by a plain dense product over the rotated rows, accumulated in f32 in
/// the scratch sums region the rotate_out stage reads. Sequential k; the fp64 reference
/// mirrors this order.
/// Kept-dense: quantized rotate stages, trellis to dense, f32 in rotate_out sums; sequential k, as the fp64 reference.
pub fn encodeDense(p: *const Pipelines, e: mtl.ComputeEncoder, m: DenseMatrix, x: View, y: View, scratch: View, r: Rows) !void {
try shape(m.k, m.n);
var a = try rowsArgs(m.k, m.n, r, x, y, scratch);
Expand Down
3 changes: 1 addition & 2 deletions zig/src/families/deepseek_v41/weights.zig
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ fn scale(comptime binding: bool, source: anytype, prefix: []const u8, size: usiz
return .{ .name = name, .format = if (have_fp) .f16 else .packed_signs };
}

/// The compressor and indexer matrices ride either storage: the released packs quantize
/// them, rank-split repacks keep them dense beside the rotation scales.
/// Compressor/indexer matrices ride either storage: packs quantize; rank-split repacks stay dense with rotation scales.
fn matrixAny(comptime binding: bool, source: anytype, prefix: []const u8, k: usize, n: usize, destination: ?*AnyMatrix) !void {
var name_buf: [160]u8 = undefined;
if (has(source, try named(&name_buf, "{s}.weight", .{prefix}))) {
Expand Down
3 changes: 1 addition & 2 deletions zig/tests/deepseek_v41_reference/projection.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub fn applyF32(matrix: weights.AnyMatrix, x: []const u16, y: []f32, scratch: *S
}
}

/// The kept-dense form: the same input rotation boundary and output stages as the quantized
/// path, with the tile decode replaced by an FP64 dense dot over the f16-rounded rotated row.
/// Kept-dense: quantized rotation and output stages; FP64 dot over the f16-rounded row replaces the tile decode.
fn applyDense(comptime T: type, d: weights.Dense, x: []const u16, y: []T, scratch: *Scratch) !void {
@setFloatMode(.strict);
if (x.len != d.k or y.len != d.n) return error.InvalidReferenceProjectionLength;
Expand Down