Files
UnbiasedStrata/include/strata/dsv41/moe_win.hpp
T
Robert KarlandClaude Fable 5.1 bd2dbb92f1 Import Strata v0.2.4's DeepSeek-V4.1 engine (strata-dsv41) and the CPU kernels it needs
From Niko1221/Strata tag v0.2.4 (commit 96ca4383, 2026-10-24), unmodified: src/dsv41/ (the engine and its vendored
EXL3 / sampler / window kernels), include/strata/dsv41/, tests/dsv41/, tools/dsv41/{pack_gguf,smoke,tune}.py,
data/dsv41/ (the shipped hot-expert profiles), tools/trellis/tqenc.{cpp,hpp} (the tests' encoder),
third_party/project-maya/ (the MIT notice: the engine is a port of Project Maya's maya-ds4),
third_party/ggml/ggml-common-tq.h, docs/DEEPSEEK41.md (upstream's text, to be rewritten for this fork).

src/kernels/cpu: upstream's iq_avx2.{cpp,hpp}, iq_avx2_rows.inl, iq_avx512.{cpp,hpp} replace this fork's
(v0.1.45-poly.1) copies - they add the engine's CPU lane rows iq256x_rows / iq512x_rows and leave the main engine's
iq256_* / iq512_* as they were (upstream's statement; iq_avx2_parity is the check) - and the trellis CPU lane
tq_cpu.{hpp,cpp}, tq_avx2.cpp, tq_avx512.cpp, tq_states.hpp, tq_computed.hpp is new.  expert_layout.hpp stays at
layout version 4 (upstream's 5 adds Hadamard-folded packs this fork has no use for yet).

CMakeLists.txt: upstream's strata-dsv41 block, with ggml.h / ggml-cpu.h coming through strata_kernels_cpu's ggml-cpu
link from the submodule (no FetchContent), the tq sources and flags in strata_kernels_cpu, and iq_avx512.cpp built
with -mavx512vpopcntdq -mbmi2 as upstream does (iq512x_rows uses them).  Makefile: STRATA_BUILD_DSV41=ON and
strata-dsv41 among the targets `make build` produces.

Target: ISTA-DASLab/DeepSeek-V4.1-Flash-1017-GSQ-RCO-GGUF (IQ1_M / IQ2_XXS + the IQ4_NL Engram) on the A6000 VM.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-23 20:14:35 -07:00

34 lines
2.0 KiB
C++

// Copyright (c) 2026 Peasant Smith and the Project Maya contributors (MIT; https://github.com/mw00/project-maya, v1.1.17).
// Ported into Strata (third_party/project-maya/NOTICE.md, LICENSE); changes are in the git history of this file.
// include/strata/dsv41/moe_win.hpp - a verify window's MoE entries grouped by expert (the grouping alone).
// Extracted from Project Maya's include/strata/kernels/glm_fast.hpp (MIT, see third_party/project-maya/NOTICE.md).
#pragma once
#include <cstddef>
#include <cuda_runtime.h>
namespace strata::dsv41k::glmf {
constexpr int kMaxMvCols = 16;
struct MoeWin {
const unsigned long long* plan_ptr = nullptr; // [T][8] the tokens' plans (0: an entry the GPU does not compute)
const float* plan_w = nullptr; // [T][8]
const float* cpu_part = nullptr; // [T][n_embd] the host's answers to disk misses, when flagged
const int* cpu_flag = nullptr; // [T]
const void* xq = nullptr; // the tokens' FFN inputs (q8_1), xq_stride bytes apart
size_t xq_stride = 0;
void* hq = nullptr; // scratch: [T * 8][n_ff / 32] q8_1
float* part = nullptr; // scratch: [T * 8][n_embd]
const float* sh_out = nullptr; // [T][n_embd] the shared expert's down rows, or null
float* out = nullptr; // [T][n_embd], out_stride floats apart
size_t out_stride = 0;
unsigned long long* grp_ptr = nullptr; // scratch: [T * 8]
int* grp_start = nullptr; // scratch: [T * 8 + 1]
int* grp_ent = nullptr; // scratch: [T * 8]
int* n_groups = nullptr; // scratch: [1]
int T = 0, k = 0, n_embd = 0, n_ff = 0;
float limit = 0.0f;
size_t down_off = 0;
};
constexpr int kMaxWinTokens = kMaxMvCols; // the window's tokens moe_win_experts groups (16 x 8 entries)
void moe_win_group(const MoeWin& w, cudaStream_t s);
} // namespace strata::dsv41k::glmf