Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

dsv41: build the imported DeepSeek-V4.1 engine path in Strata (HIP gfx1201), add --score

Niko1221453cc0d56f24
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96ebc4d66..786cf9d51 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -763,6 +763,29 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
target_compile_definitions(strata PRIVATE STRATA_HAVE_QWEN35=1)
endif()
+ # DeepSeek-V4.1-Flash: the third engine path (src/dsv41, from Project Maya's maya-ds4, MIT, third_party/project-maya).
+ # Its own executable for now (strata-dsv41); a family switch in `strata` comes after first light. OFF by default: it
+ # changes no existing target (the vendored kernels live in strata::dsv41k, so no symbol is shared with strata_kernels).
+ option(STRATA_BUILD_DSV41 "Build the DeepSeek-V4.1 engine path (strata-dsv41)" OFF)
+ if(STRATA_BUILD_DSV41 AND NOT STRATA_HIP_GFX906)
+ add_library(strata_dsv41_kernels STATIC src/dsv41/vendor/exl3.cu src/dsv41/vendor/sampler.cu src/dsv41/vendor/moe_win.cu
+ src/dsv41/vendor/exl3_cpu.cpp)
+ target_include_directories(strata_dsv41_kernels PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${_strata_gpu_include_directories})
+ target_link_libraries(strata_dsv41_kernels PUBLIC ${_strata_gpu_runtime_target})
+ add_executable(strata-dsv41 src/dsv41/ds4_main.cpp src/dsv41/ds4_model.cu src/dsv41/ds4_kernels.cu src/dsv41/ds4_vision.cu
+ src/dsv41/ds4_gguf.cu src/dsv41/ds4_gguf_cpu.cpp src/dsv41/ds4_iq.cu src/dsv41/ds4_iq_cpu.cpp)
+ target_include_directories(strata-dsv41 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${_strata_gpu_include_directories}
+ ${CMAKE_CURRENT_SOURCE_DIR}/third_party/ggml)
+ target_link_libraries(strata-dsv41 PRIVATE strata_dsv41_kernels ${_strata_gpu_runtime_target} ${_strata_gpu_blas_target})
+ find_package(Threads REQUIRED)
+ target_link_libraries(strata-dsv41 PRIVATE Threads::Threads)
+ if(STRATA_ENABLE_HIP)
+ foreach(_t strata_dsv41_kernels strata-dsv41)
+ target_compile_options(${_t} PRIVATE "$<$<COMPILE_LANGUAGE:HIP,CXX>:SHELL:-include ${CMAKE_CURRENT_SOURCE_DIR}/include/strata/dsv41/hip_extra.h>")
+ endforeach()
+ endif()
+ endif()
+
if(STRATA_ENABLE_HIP)
enable_testing()
set(_strata_hip_tests)
diff --git a/include/strata/dsv41/exl3.hpp b/include/strata/dsv41/exl3.hpp
index 12f862aaf..b080a5970 100644
--- a/include/strata/dsv41/exl3.hpp
+++ b/include/strata/dsv41/exl3.hpp
@@ -1,3 +1,5 @@
+// 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/kernels/exl3.hpp - EXL3 (exllamav3) quantized weights on the device: the decode GEMV, the routed
// experts, and the full reconstruction for the prompt path.
//
@@ -22,7 +24,7 @@
#include <cstdint>
#include <cuda_runtime.h>
-namespace strata::kernels::exl3 {
+namespace strata::dsv41k::exl3 {
/// The weight type the engine's MvJob / WSlot carry for EXL3: their weight pointer is a (host) const Mat*.
constexpr int kTypeEXL3 = 200;
@@ -182,4 +184,4 @@ void rows_f16(const float* x, int ldx, const int* idx, int nrows, int ncols, uin
/// Launch failures of this family since the process started (each is also printed).
int launch_errors();
-} // namespace strata::kernels::exl3
+} // namespace strata::dsv41k::exl3
diff --git a/include/strata/dsv41/exl3_cpu.hpp b/include/strata/dsv41/exl3_cpu.hpp
index f72b674c4..2c81a2bd2 100644
--- a/include/strata/dsv41/exl3_cpu.hpp
+++ b/include/strata/dsv41/exl3_cpu.hpp
@@ -1,3 +1,5 @@
+// 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/kernels/cpu/exl3_cpu.hpp - EXL3 routed experts on the CPU (the fast path's CPU lane).
//
// The mul1 codebook is affine in the byte sum of state * 0x83DCD12D: w = fp16(1024 + s) * k_inv + k_bias (one FP16
@@ -12,7 +14,7 @@
#include <cstddef>
#include <cstdint>
-namespace strata::kernels::cpu {
+namespace strata::dsv41k::cpu {
/// One EXL3 matrix (mul1 codebook): k inputs, n outputs, K bits (1..8), tiles in exllamav3's natural layout.
struct Exl3Part {
@@ -64,4 +66,4 @@ bool exl3_cpu_band_acc_on(int tier, const Exl3Part& m, const float* const* xh, i
/// ... and, with the parts' acc summed over every slice, the outputs (the codebook's affine form, H, svh).
void exl3_cpu_band_out(const Exl3Part& m, const float* acc, float xsum, int c0, float* y);
-} // namespace strata::kernels::cpu
+} // namespace strata::dsv41k::cpu
diff --git a/include/strata/dsv41/hip_extra.h b/include/strata/dsv41/hip_extra.h
new file mode 100644
index 000000000..bb9d91133
--- /dev/null
+++ b/include/strata/dsv41/hip_extra.h
@@ -0,0 +1,50 @@
+// 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/hip_extra.h - CUDA runtime names the DeepSeek-V4.1 engine path uses that Strata's HIP shim
+// (include/strata/hip_compat) does not map. Force-included into the dsv41 targets only, so no other target changes.
+// The mappings are Project Maya's include/strata/hip_compat (MIT, third_party/project-maya/NOTICE.md).
+#pragma once
+#include <hip/hip_runtime.h>
+#include <hipblas/hipblas.h>
+#ifndef __grid_constant__
+#define __grid_constant__
+#endif
+#ifndef cudaDevAttrMemoryClockRate
+#define cudaDevAttrMemoryClockRate hipDeviceAttributeMemoryClockRate
+#endif
+#ifndef cudaDevAttrGlobalMemoryBusWidth
+#define cudaDevAttrGlobalMemoryBusWidth hipDeviceAttributeMemoryBusWidth
+#endif
+#ifndef cudaDevAttrCanUseHostPointerForRegisteredMem
+#define cudaDevAttrCanUseHostPointerForRegisteredMem hipDeviceAttributeCanUseHostPointerForRegisteredMem
+#endif
+#ifndef cudaDeviceGetPCIBusId
+#define cudaDeviceGetPCIBusId hipDeviceGetPCIBusId
+#endif
+#ifndef cudaDeviceGetStreamPriorityRange
+#define cudaDeviceGetStreamPriorityRange hipDeviceGetStreamPriorityRange
+#endif
+#ifndef cudaOccupancyMaxActiveBlocksPerMultiprocessor
+#define cudaOccupancyMaxActiveBlocksPerMultiprocessor hipOccupancyMaxActiveBlocksPerMultiprocessor
+#endif
+#ifndef cudaErrorUnknown
+#define cudaErrorUnknown hipErrorUnknown
+#endif
+#ifndef cudaErrorInvalidConfiguration
+#define cudaErrorInvalidConfiguration hipErrorInvalidConfiguration
+#endif
+#ifndef cudaMemcpy2D
+#define cudaMemcpy2D hipMemcpy2D
+#endif
+#ifndef cudaStreamCreateWithPriority
+#define cudaStreamCreateWithPriority hipStreamCreateWithPriority
+#endif
+#ifndef cudaStreamLegacy
+#define cudaStreamLegacy hipStreamLegacy
+#endif
+#ifndef CUBLAS_GEMM_DEFAULT_TENSOR_OP
+#define CUBLAS_GEMM_DEFAULT_TENSOR_OP HIPBLAS_GEMM_DEFAULT
+#endif
+#ifndef cudaDataType
+#define cudaDataType hipDataType
+#endif
diff --git a/include/strata/dsv41/moe_win.hpp b/include/strata/dsv41/moe_win.hpp
new file mode 100644
index 000000000..41da8db4c
--- /dev/null
+++ b/include/strata/dsv41/moe_win.hpp
@@ -0,0 +1,33 @@
+// 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
diff --git a/include/strata/dsv41/sampler.hpp b/include/strata/dsv41/sampler.hpp
index a7779c92d..edfbde84d 100644
--- a/include/strata/dsv41/sampler.hpp
+++ b/include/strata/dsv41/sampler.hpp
@@ -1,3 +1,5 @@
+// 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/kernels/sampler.hpp - the sampler chain, host-callable (P2.S2).
//
// penalties -> top_k -> top_p -> min_p -> temperature -> pick
@@ -11,7 +13,7 @@
#include <cstdint>
#include <vector>
-namespace strata::kernels {
+namespace strata::dsv41k {
struct SamplerParams {
int top_k = 20; // sampled path: 1..64 as given; 0 (off) or more than 64 keep the widest list, 64
@@ -89,4 +91,4 @@ inline void penalty_rows(const int32_t* tail, int64_t n_tail, const int32_t* win
}
}
-} // namespace strata::kernels
+} // namespace strata::dsv41k
diff --git a/src/dsv41/ds4_engram_io.hpp b/src/dsv41/ds4_engram_io.hpp
index 1e44c41fb..eb190f43c 100644
--- a/src/dsv41/ds4_engram_io.hpp
+++ b/src/dsv41/ds4_engram_io.hpp
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_engram_io.hpp - DeepSeek's Engram (n-gram memory) rows read off the decode's critical path.
//
// A token's Engram rows depend only on the token ids, so they are asked for as soon as the window's tokens are known
diff --git a/src/dsv41/ds4_gguf.cu b/src/dsv41/ds4_gguf.cu
index 379d0766d..556d8c1bc 100644
--- a/src/dsv41/ds4_gguf.cu
+++ b/src/dsv41/ds4_gguf.cu
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_gguf.cu - a GGUF's BF16 matrices and MXFP4 experts on the device (see ds4_gguf.cuh).
#include "ds4_gguf.cuh"
diff --git a/src/dsv41/ds4_gguf.cuh b/src/dsv41/ds4_gguf.cuh
index 6257c8a7f..0b012395c 100644
--- a/src/dsv41/ds4_gguf.cuh
+++ b/src/dsv41/ds4_gguf.cuh
@@ -1,6 +1,8 @@
+// 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.
// src/ds4/ds4_gguf.cuh - a GGUF's weights on the device for maya-ds4 (unsloth's DeepSeek-V4.1-Flash-1017 GGUFs,
// tools/ds4/pack_gguf.py): the dense matrices in BF16 and the routed experts in MXFP4. They stand in for
-// strata::kernels::exl3's matrices and experts (an x3::Mat with fmt kFmtBF16, an x3::ExpertLayout with fmt kFmtMXFP4)
+// strata::dsv41k::exl3's matrices and experts (an x3::Mat with fmt kFmtBF16, an x3::ExpertLayout with fmt kFmtMXFP4)
// with the same arguments and the same results' layout, so the engine's paths (decode, verify windows, chunked prompts,
// tensor parallel) take either format.
//
@@ -12,7 +14,7 @@
// the token path gives it (the same kernel, the same order).
#pragma once
-#include "strata/kernels/exl3.hpp"
+#include "strata/dsv41/exl3.hpp"
#include <cstddef>
#include <cstdint>
@@ -20,7 +22,7 @@
namespace strata::ds4::gguf {
-namespace x3 = strata::kernels::exl3;
+namespace x3 = strata::dsv41k::exl3;
constexpr int kFmtBF16 = 1; // x3::Mat::fmt
constexpr int kFmtMXFP4 = 2; // x3::ExpertLayout::fmt (and an expert's matrix as an x3::Mat)
diff --git a/src/dsv41/ds4_gguf_cpu.cpp b/src/dsv41/ds4_gguf_cpu.cpp
index beae19dcf..da6ddd4e5 100644
--- a/src/dsv41/ds4_gguf_cpu.cpp
+++ b/src/dsv41/ds4_gguf_cpu.cpp
@@ -1,7 +1,9 @@
+// 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.
// src/ds4/ds4_gguf_cpu.cpp - a GGUF's MXFP4 experts on the CPU lane (see ds4_gguf_cpu.hpp).
#include "ds4_gguf_cpu.hpp"
-#include "strata/kernels/cpu/exl3_cpu.hpp"
+#include "strata/dsv41/exl3_cpu.hpp"
#include <algorithm>
#include <chrono>
@@ -338,7 +340,7 @@ void q8_round(const float* x, int k, float* out) {
void mx_cpu_rows(const uint8_t* w, size_t rb, int k, int r0, int r1, const float* const* x, int n, float* const* y) {
#if defined(MX_X86)
- static const bool avx2 = strata::kernels::cpu::exl3_cpu_tier() >= 1;
+ static const bool avx2 = strata::dsv41k::cpu::exl3_cpu_tier() >= 1;
if (avx2) return rows_avx2(w, rb, k, r0, r1, x, n, y);
#endif
rows_scalar(w, rb, k, r0, r1, x, n, y);
diff --git a/src/dsv41/ds4_gguf_cpu.hpp b/src/dsv41/ds4_gguf_cpu.hpp
index 170c0f499..32b40c70a 100644
--- a/src/dsv41/ds4_gguf_cpu.hpp
+++ b/src/dsv41/ds4_gguf_cpu.hpp
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_gguf_cpu.hpp - a GGUF's MXFP4 experts on the CPU lane of maya-ds4 (the format: ds4_gguf.cuh). The
// weights are read where they lie (the GGUF file's mapping), each block decoded once for all the activations of a
// call (mx_rows: int8 dots, the CPU's best vector tier at run time; a scalar loop otherwise).
@@ -16,7 +18,7 @@ constexpr int kMxCpuMaxN = 8; // activations a call
void mx_cpu_rows(const uint8_t* w, size_t rb, int k, int r0, int r1, const float* const* x, int n, float* const* y);
/// A GGUF's low-bit experts (ds4_iq.cuh's types) on the CPU lane - ggml-cpu's arithmetic through the GLM CPU lane's
-/// native experts (strata::kernels::cpu::native_*: its AVX-512 / AVX2 multi-token rows where they are ggml's bit for bit,
+/// native experts (strata::dsv41k::cpu::native_*: its AVX-512 / AVX2 multi-token rows where they are ggml's bit for bit,
/// ggml's dots otherwise; ds4_iq_cpu.cpp): an activation quantized once to the weight type's vec_dot_type (Q8_K: an F32
/// scale per 256 values - the device takes one per 32, so the two sides agree to that rounding), each row one dot.
struct IqCpu {
diff --git a/src/dsv41/ds4_iq.cu b/src/dsv41/ds4_iq.cu
index 22ff70b05..ec2c70819 100644
--- a/src/dsv41/ds4_iq.cu
+++ b/src/dsv41/ds4_iq.cu
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_iq.cu - a GGUF's low-bit routed experts on the device (see ds4_iq.cuh). The block layouts and grids are
// ggml's (ggml-common.h, MIT, third_party/ggml/LICENSE); the sign and grid tricks are llama.cpp's vecdotq.cuh.
#include "ds4_iq.cuh"
diff --git a/src/dsv41/ds4_iq.cuh b/src/dsv41/ds4_iq.cuh
index 1b4486d69..65711f517 100644
--- a/src/dsv41/ds4_iq.cuh
+++ b/src/dsv41/ds4_iq.cuh
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_iq.cuh - a GGUF's routed experts in ggml's low-bit block types on the device for maya-ds4: the i-quants
// IQ2_XXS, IQ2_S, IQ3_XXS, IQ3_S, IQ4_XS and the K-quants Q2_K, Q3_K, Q4_K (256 values a block, ggml's layouts:
// ggml-common.h, llama.cpp MIT). ds4_gguf.cu sends an expert layer here when its experts are not MXFP4
diff --git a/src/dsv41/ds4_iq_cpu.cpp b/src/dsv41/ds4_iq_cpu.cpp
index b2d8f2409..f96c81952 100644
--- a/src/dsv41/ds4_iq_cpu.cpp
+++ b/src/dsv41/ds4_iq_cpu.cpp
@@ -1,10 +1,14 @@
+// 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.
// src/ds4/ds4_iq_cpu.cpp - a GGUF's low-bit experts on the CPU lane (see ds4_gguf_cpu.hpp): the GLM CPU lane's native
// experts (src/kernels/cpu/native_expert.cpp), whose arithmetic is ggml-cpu's - and for IQ3_XXS / IQ3_S (Maya-S's
// down, Maya-M's gate / up / down) rows of our own, the same numbers bit for bit, faster.
#include "ds4_gguf_cpu.hpp"
-
+// Strata port: the low-bit (IQ) experts have no CPU lane here (they need Maya's native_expert split-base rows); the stub
+// branch below answers for them. MXFP4, the source format, has its own CPU rows (ds4_gguf_cpu.cpp).
+#undef STRATA_NATIVE_EXPERTS
#if defined(STRATA_NATIVE_EXPERTS)
-#include "strata/kernels/cpu/native_expert.hpp"
+#include "strata/kernels/cpu/native_expert.hpp" // (only with STRATA_NATIVE_EXPERTS)
#define GGML_COMMON_DECL_CPP
#define GGML_COMMON_IMPL_CPP
@@ -42,7 +46,7 @@
namespace strata::ds4::gguf {
#if defined(STRATA_NATIVE_EXPERTS)
-namespace kc = strata::kernels::cpu;
+namespace kc = strata::dsv41k::cpu;
namespace {
kc::NativeFmt native(const IqCpu& f) { // (the fields the rows read; no lookups)
kc::NativeFmt n;
diff --git a/src/dsv41/ds4_kernels.cu b/src/dsv41/ds4_kernels.cu
index 688fe1701..eed260ad9 100644
--- a/src/dsv41/ds4_kernels.cu
+++ b/src/dsv41/ds4_kernels.cu
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_kernels.cu - DeepSeek-V4.1's device kernels (see ds4_kernels.cuh). No fast math here: the rotary
// angles, the softmaxes and the roundings follow the reference's F32 arithmetic. A window's token is blockIdx.y.
#include "ds4_kernels.cuh"
diff --git a/src/dsv41/ds4_kernels.cuh b/src/dsv41/ds4_kernels.cuh
index f1903c679..a2fefcfef 100644
--- a/src/dsv41/ds4_kernels.cuh
+++ b/src/dsv41/ds4_kernels.cuh
@@ -1,5 +1,7 @@
+// 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.
// src/ds4/ds4_kernels.cuh - DeepSeek-V4.1's own device kernels for a window of T tokens (1 <= T <= kWin) at positions
-// p0 .. p0 + T - 1 (the EXL3 matrices go through strata::kernels::exl3). The math is DeepSeek's inference/model.py
+// p0 .. p0 + T - 1 (the EXL3 matrices go through strata::dsv41k::exl3). The math is DeepSeek's inference/model.py
// (MIT); tools/ds4/ref.py is the oracle the engine is checked against. Every pointer is device memory, every activation
// F32, rows of a window back to back; the KV caches keep the reference's FP8 / FP4 roundings packed as DeepSeek stores
// them (codes and scales, kv_row_bytes), the window attention's working rows BF16 (those values are exact in BF16).
diff --git a/src/dsv41/ds4_main.cpp b/src/dsv41/ds4_main.cpp
index 7916a0384..68751c666 100644
--- a/src/dsv41/ds4_main.cpp
+++ b/src/dsv41/ds4_main.cpp
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_main.cpp - maya-ds4: DeepSeek-V4.1-Flash on Maya.
//
// maya-ds4 --pack <model>/maya-ds4 --ids 0,128803,... --n 16 greedy tokens after the ids
@@ -11,9 +13,10 @@
// that prompt's end; anything else starts over. `GENI <max_new> [keys] <file> <ids>` carries the prompt's pictures
// (the file: see read_pics); the state is shared only where the same picture sits at the same place.
#include "ds4_model.hpp"
-#include "strata/platform/env_alias.hpp"
#include <algorithm>
+#include <cmath>
+#include <numeric>
#include <atomic>
#include <chrono>
#include <condition_variable>
@@ -512,10 +515,127 @@ int serve(strata::ds4::Model& m, const std::string& eos_list, bool spec, float c
return 0;
}
+
+// ---- Strata addition: teacher-forced scoring (the quality gate) -------------------------------------------------
+// --score IDS.json --score-out RUN.tsv: every segment of a tools/quant_quality.py ids file (name + ids) is read through
+// the model from a fresh state; per position the log-probability of the text's next token and the 64 most likely
+// tokens go out in the STRATA_LOGPOS row format that `quant_quality.py compare` reads (natural logs, full-vocabulary
+// log-softmax in double). RUN.tsv.seg.json lists each segment's first line and size.
+struct ScoreSeg {
+ std::string name;
+ std::vector<int> ids;
+};
+
+bool read_score_ids(const std::string& path, std::vector<ScoreSeg>& segs, std::string& err) {
+ std::FILE* f = std::fopen(path.c_str(), "rb");
+ if (f == nullptr) {
+ err = path + ": cannot open";
+ return false;
+ }
+ std::string s;
+ char buf[1 << 16];
+ size_t k;
+ while ((k = std::fread(buf, 1, sizeof buf, f)) > 0) s.append(buf, k);
+ std::fclose(f);
+ size_t p = 0;
+ for (;;) {
+ const size_t n0 = s.find("\"name\"", p);
+ if (n0 == std::string::npos) break;
+ const size_t q0 = s.find('"', s.find(':', n0) + 1);
+ const size_t q1 = s.find('"', q0 + 1);
+ const size_t i0 = s.find("\"ids\"", q1);
+ if (q0 == std::string::npos || q1 == std::string::npos || i0 == std::string::npos) break;
+ const size_t b0 = s.find('[', i0), b1 = s.find(']', b0);
+ if (b0 == std::string::npos || b1 == std::string::npos) break;
+ ScoreSeg g;
+ g.name = s.substr(q0 + 1, q1 - q0 - 1);
+ g.ids = parse_ids(s.substr(b0 + 1, b1 - b0 - 1));
+ segs.push_back(std::move(g));
+ p = b1;
+ }
+ if (segs.empty()) {
+ err = path + ": no segments (expected quant_quality.py's ids file)";
+ return false;
+ }
+ return true;
+}
+
+int score(strata::ds4::Model& m, const std::string& ids_path, const std::string& out_path, int window, int eos) {
+ std::vector<ScoreSeg> segs;
+ std::string err;
+ if (!read_score_ids(ids_path, segs, err)) {
+ std::fprintf(stderr, "strata-dsv41: %s\n", err.c_str());
+ return 1;
+ }
+ std::FILE* out = std::fopen(out_path.c_str(), "wb");
+ std::FILE* sj = std::fopen((out_path + ".seg.json").c_str(), "wb");
+ if (out == nullptr || sj == nullptr) {
+ std::fprintf(stderr, "strata-dsv41: cannot write %s\n", out_path.c_str());
+ return 1;
+ }
+ std::fprintf(sj, "{\"segments\": [");
+ const int V = m.vocab();
+ long long line = 0;
+ std::vector<float> lg;
+ std::vector<int> order;
+ const double t0 = now_ms();
+ for (size_t si = 0; si < segs.size(); ++si) {
+ const std::vector<int>& ids = segs[si].ids;
+ m.reset();
+ const long long first = line;
+ double sum_nll = 0.0;
+ long long top1 = 0, cnt = 0;
+ for (size_t a = 0; a + 1 < ids.size();) {
+ const int T = (int) std::min<size_t>((size_t) window, ids.size() - 1 - a); // (positions a .. a+T-1 are scored)
+ if (!m.feed(ids.data() + a, T, T, err) || !m.logits(lg) || lg.size() < (size_t) T * (size_t) V) {
+ std::fprintf(stderr, "strata-dsv41: %s\n", err.empty() ? "no logits" : err.c_str());
+ return 1;
+ }
+ for (int t = 0; t < T; ++t) {
+ const float* r = lg.data() + (size_t) t * (size_t) V;
+ float mx = r[0];
+ for (int v = 1; v < V; ++v) mx = std::max(mx, r[v]);
+ double z = 0.0;
+ for (int v = 0; v < V; ++v) z += std::exp((double) (r[v] - mx));
+ const double lz = std::log(z) + (double) mx;
+ order.resize((size_t) V);
+ std::iota(order.begin(), order.end(), 0);
+ std::partial_sort(order.begin(), order.begin() + 64, order.end(), [&](int x, int y) {
+ return r[x] > r[y] || (r[x] == r[y] && x < y);
+ });
+ const int tgt = ids[a + (size_t) t + 1];
+ const double lt = (double) r[tgt] - lz;
+ const double la = (double) r[order[0]] - lz;
+ const double le = eos >= 0 && eos < V ? (double) r[eos] - lz : -1e30;
+ // logp(target) with the end token left out of the distribution, as the engine's row has it
+ const double lt_ne = tgt == eos ? lt : std::log(std::max(1e-300, std::exp(lt) / std::max(1e-300, 1.0 - std::exp(le))));
+ std::fprintf(out, "%zu\t%d\t%.6f\t%d\t%.6f\t%d\t%.6f\t%.6f", a + (size_t) t, tgt, lt, order[0], la,
+ order[0] == tgt ? 1 : 0, le, lt_ne);
+ for (int j = 0; j < 64; ++j) std::fprintf(out, "\t%d:%.6f", order[(size_t) j], (double) r[order[(size_t) j]] - lz);
+ std::fprintf(out, "\n");
+ ++line;
+ ++cnt;
+ top1 += order[0] == tgt;
+ sum_nll -= lt;
+ }
+ a += (size_t) T;
+ }
+ std::fprintf(sj, "%s{\"name\": \"%s\", \"first_line\": %lld, \"n\": %lld, \"ppl\": %.6f, \"top1\": %.6f}", si ? ", " : "",
+ segs[si].name.c_str(), first, cnt, std::exp(sum_nll / (double) std::max(1LL, cnt)),
+ (double) top1 / (double) std::max(1LL, cnt));
+ std::fprintf(stderr, "score %s: %lld positions, ppl %.4f, top-1 %.4f (%.0f s)\n", segs[si].name.c_str(), cnt,
+ std::exp(sum_nll / (double) std::max(1LL, cnt)), (double) top1 / (double) std::max(1LL, cnt),
+ (now_ms() - t0) / 1000.0);
+ std::fflush(out);
+ }
+ std::fprintf(sj, "]}\n");
+ std::fclose(sj);
+ std::fclose(out);
+ return 0;
+}
} // namespace
int main(int argc, char** argv) {
- strata::platform::env_aliases(); // (MAYA_* settings under their older names too)
strata::ds4::Options o;
std::string ids_s, dump, eos = "1";
int n = 0, window = 16;
@@ -524,6 +644,7 @@ int main(int argc, char** argv) {
unsigned long long cli_seed = 1;
bool serve_mode = false;
std::string images, enc_rgb, enc_out;
+ std::string score_ids, score_out;
int enc_w = 0, enc_h = 0;
for (int i = 1; i < argc; ++i) {
const std::string a = argv[i];
@@ -571,6 +692,8 @@ int main(int argc, char** argv) {
else if (a == "--n") n = std::atoi(val("--n").c_str());
else if (a == "--window") window = std::max(1, std::atoi(val("--window").c_str())); // (> 16: the chunked prompt path)
else if (a == "--dump-logits") dump = val("--dump-logits");
+ else if (a == "--score") score_ids = val("--score");
+ else if (a == "--score-out") score_out = val("--score-out");
else if (a == "--serve") serve_mode = true;
else if (a == "--layer-split") (void) val("--layer-split"); // the server's (this engine balances its own split)
else if (a == "--help" || a == "-h") {
@@ -597,6 +720,7 @@ int main(int argc, char** argv) {
}
if (!o.vision_only) std::fprintf(stderr, "%s", m.describe().c_str());
if (serve_mode) return serve(m, eos, spec, o.dspark_conf);
+ if (!score_ids.empty()) return score(m, score_ids, score_out.empty() ? score_ids + ".tsv" : score_out, window, std::atoi(eos.c_str()));
if (!enc_rgb.empty()) { // the vision tower alone: a picture's span rows (BF16 [rows][dim]) into --dump-image
std::vector<uint8_t> px((size_t) std::max(0, enc_w) * std::max(0, enc_h) * 3);
diff --git a/src/dsv41/ds4_model.cu b/src/dsv41/ds4_model.cu
index eb86182de..4999ddc24 100644
--- a/src/dsv41/ds4_model.cu
+++ b/src/dsv41/ds4_model.cu
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_model.cu - DeepSeek-V4.1-Flash on Maya (see ds4_model.hpp).
//
// The layer, for one token at position p (DeepSeek's inference/model.py, Block.forward with the lagged pre-mix):
@@ -19,11 +21,11 @@
#include "ds4_os.hpp"
#include "ds4_pool.hpp"
#include "ds4_vision.cuh"
-#include "strata/kernels/cpu/exl3_cpu.hpp"
-#include "strata/kernels/exl3.hpp"
+#include "strata/dsv41/exl3_cpu.hpp"
+#include "strata/dsv41/exl3.hpp"
#include "strata/kernels/f16_bits.hpp"
-#include "strata/kernels/glm_fast.hpp"
-#include "strata/kernels/sampler.hpp"
+#include "strata/dsv41/moe_win.hpp"
+#include "strata/dsv41/sampler.hpp"
#include <cublas_v2.h>
#include <cuda_runtime.h>
@@ -53,9 +55,9 @@
#endif
namespace strata::ds4 {
-namespace x3 = strata::kernels::exl3;
-namespace kc = strata::kernels::cpu;
-namespace gf = strata::kernels::glmf;
+namespace x3 = strata::dsv41k::exl3;
+namespace kc = strata::dsv41k::cpu;
+namespace gf = strata::dsv41k::glmf;
namespace gg = strata::ds4::gguf;
#define CK(call) \
@@ -840,8 +842,8 @@ struct Model::Impl {
// a sampled round's drafts: the distribution q each one was drawn from (its kept list, on the head device) for
// verify()'s rule - a point at the draft for the drafter's argmax; and the chain they were drawn with (verify()
// checks it is its own)
- strata::kernels::SpecList* d_specq = nullptr;
- std::vector<strata::kernels::SpecList> h_specq = std::vector<strata::kernels::SpecList>(kWin);
+ strata::dsv41k::SpecList* d_specq = nullptr;
+ std::vector<strata::dsv41k::SpecList> h_specq = std::vector<strata::dsv41k::SpecList>(kWin);
bool drafts_q = false;
float dq_temp = 0.0f, dq_top_p = 1.0f, dq_min_p = 0.0f;
int dq_top_k = 0;
@@ -5451,7 +5453,7 @@ struct Model::Impl {
cudaSetDevice(hd.id);
} else {
CK(cudaMemcpyAsync(d_ints, h_idx, 4, cudaMemcpyHostToDevice, hd.st));
- strata::kernels::SamplerParams sp;
+ strata::dsv41k::SamplerParams sp;
sp.greedy = true;
sp.temperature = 0.0f;
if (drafts_q) { // the request's own chain: draft i drawn as the model's token i would be (verify's counter + i)
@@ -5466,9 +5468,9 @@ struct Model::Impl {
markov_add(hd.logits + (size_t) i * V, d_mk_embed, d_mk_head, d_ints + i, V, R, hd.st);
if (drafts_q) {
sp.counter = dq_counter + (uint64_t) i;
- strata::kernels::sample_draft(hd.logits + (size_t) i * V, 1, V, sp, d_specq + i, d_ints + i + 1, hd.st);
+ strata::dsv41k::sample_draft(hd.logits + (size_t) i * V, 1, V, sp, d_specq + i, d_ints + i + 1, hd.st);
} else
- strata::kernels::sample_tokens(hd.logits + (size_t) i * V, 1, V, nullptr, 0, sp, d_ints + i + 1, hd.st);
+ strata::dsv41k::sample_tokens(hd.logits + (size_t) i * V, 1, V, nullptr, 0, sp, d_ints + i + 1, hd.st);
}
}
confidence(hd.x, d_mk_embed, d_ints, d_conf, T, D, R, d_confv, hd.st);
@@ -5507,7 +5509,7 @@ struct Model::Impl {
const float* bias) {
Dev& d = devs[(size_t) head_dev];
cudaSetDevice(d.id);
- strata::kernels::SamplerParams sp;
+ strata::dsv41k::SamplerParams sp;
sp.temperature = temperature;
sp.greedy = temperature <= 0.0f;
sp.top_p = top_p;
@@ -5516,7 +5518,7 @@ struct Model::Impl {
sp.seed = seed;
sp.counter = counter;
sp.logit_bias = bias;
- strata::kernels::sample_tokens(d.logits + (size_t) row * g.vocab, 1, g.vocab, nullptr, 0, sp, d.tok, d.st);
+ strata::dsv41k::sample_tokens(d.logits + (size_t) row * g.vocab, 1, g.vocab, nullptr, 0, sp, d.tok, d.st);
int t = -1;
cudaMemcpyAsync(&t, d.tok, 4, cudaMemcpyDeviceToHost, d.st);
cudaStreamSynchronize(d.st);
@@ -5546,10 +5548,10 @@ struct Model::Impl {
cudaSetDevice(hd.id);
int m = 0;
if (temperature <= 0.0f) {
- strata::kernels::SamplerParams sp;
+ strata::dsv41k::SamplerParams sp;
sp.greedy = true;
sp.temperature = 0.0f;
- strata::kernels::sample_tokens(hd.logits, T, V, nullptr, 0, sp, d_ints + 16, hd.st); // (the T rows at once)
+ strata::dsv41k::sample_tokens(hd.logits, T, V, nullptr, 0, sp, d_ints + 16, hd.st); // (the T rows at once)
CK(cudaMemcpyAsync(h_idx, d_ints + 16, (size_t) T * 4, cudaMemcpyDeviceToHost, hd.st));
CK(cudaStreamSynchronize(hd.st));
while (m < n && h_idx[m] == drafts[(size_t) m]) ++m;
@@ -5567,12 +5569,12 @@ struct Model::Impl {
h_specq[(size_t) i].ids[0] = drafts[(size_t) i];
h_specq[(size_t) i].p[0] = 1.0;
}
- CK(cudaMemcpyAsync(d_specq, h_specq.data(), (size_t) n * sizeof(strata::kernels::SpecList),
+ CK(cudaMemcpyAsync(d_specq, h_specq.data(), (size_t) n * sizeof(strata::dsv41k::SpecList),
cudaMemcpyHostToDevice, hd.st));
}
for (int i = 0; i < n; ++i) h_idx[i] = drafts[(size_t) i];
CK(cudaMemcpyAsync(d_ints + 32, h_idx, (size_t) n * 4, cudaMemcpyHostToDevice, hd.st));
- strata::kernels::SamplerParams sp;
+ strata::dsv41k::SamplerParams sp;
sp.greedy = false;
sp.temperature = temperature;
sp.top_p = top_p;
@@ -5580,7 +5582,7 @@ struct Model::Impl {
sp.min_p = min_p;
sp.seed = seed;
sp.counter = counter;
- strata::kernels::sample_verify(hd.logits, n, V, sp, d_specq, d_ints + 32, d_ints + 16, hd.st);
+ strata::dsv41k::sample_verify(hd.logits, n, V, sp, d_specq, d_ints + 32, d_ints + 16, hd.st);
CK(cudaMemcpyAsync(h_idx, d_ints + 16, (size_t) n * 4, cudaMemcpyDeviceToHost, hd.st));
CK(cudaStreamSynchronize(hd.st));
while (m < n && h_idx[m] == drafts[(size_t) m]) ++m;
@@ -7632,7 +7634,7 @@ struct Model::Impl {
int sample(float temperature, float top_p, int top_k, float min_p, uint64_t seed, uint64_t counter) {
Dev& d = devs[(size_t) head_dev];
cudaSetDevice(d.id);
- strata::kernels::SamplerParams sp;
+ strata::dsv41k::SamplerParams sp;
sp.temperature = temperature;
sp.greedy = temperature <= 0.0f;
sp.top_p = top_p;
@@ -7640,7 +7642,7 @@ struct Model::Impl {
sp.min_p = min_p;
sp.seed = seed;
sp.counter = counter;
- strata::kernels::sample_tokens(d.logits + (size_t) std::max(0, n_logits - 1) * g.vocab, 1, g.vocab, nullptr, 0,
+ strata::dsv41k::sample_tokens(d.logits + (size_t) std::max(0, n_logits - 1) * g.vocab, 1, g.vocab, nullptr, 0,
sp, d.tok, d.st);
int t = -1;
cudaMemcpyAsync(&t, d.tok, 4, cudaMemcpyDeviceToHost, d.st);
diff --git a/src/dsv41/ds4_model.hpp b/src/dsv41/ds4_model.hpp
index c6b255a5c..91c72f771 100644
--- a/src/dsv41/ds4_model.hpp
+++ b/src/dsv41/ds4_model.hpp
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_model.hpp - DeepSeek-V4.1-Flash on Maya: an EXL3 model (tools/ds4/pack.py's pack beside its files) over
// the machine's GPUs, layer-split, with the routed experts that do not fit in VRAM on the CPU lane.
//
diff --git a/src/dsv41/ds4_mx_kern.inc b/src/dsv41/ds4_mx_kern.inc
index 24bd08213..0c8cda118 100644
--- a/src/dsv41/ds4_mx_kern.inc
+++ b/src/dsv41/ds4_mx_kern.inc
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_mx_kern.inc - the CPU lane's int8 MXFP4 rows (ds4_gguf_cpu.hpp: mx_rows), one body for the x86 tiers.
// ds4_gguf_cpu.cpp includes it once a tier, inside its unnamed namespace, after <immintrin.h>, with
// MXK_NS the tier's namespace
diff --git a/src/dsv41/ds4_numerics.cuh b/src/dsv41/ds4_numerics.cuh
index 36b1f6849..651e75779 100644
--- a/src/dsv41/ds4_numerics.cuh
+++ b/src/dsv41/ds4_numerics.cuh
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_numerics.cuh - the BF16 and FP8 (E4M3) conversions of maya-ds4's kernels, on CUDA through its
// intrinsics (cuda_bf16.h / cuda_fp8.h) and on HIP in plain arithmetic that gives the same bits: BF16 round to
// nearest even; E4M3 (OCP "fn": no infinities, max 448) decoded exactly, rounded to nearest even and saturated.
diff --git a/src/dsv41/ds4_os.hpp b/src/dsv41/ds4_os.hpp
index 2b61860c0..689f5ec79 100644
--- a/src/dsv41/ds4_os.hpp
+++ b/src/dsv41/ds4_os.hpp
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_os.hpp - the few OS services maya-ds4 needs, on Linux and on Windows: files read at an offset and
// mapped read-only (the experts read in place), page-cache hints, anonymous host memory on a NUMA node, thread pinning,
// each NUMA node's physical cores, the RAM this process can still get. (On Windows as src/core/expert_source.cpp
diff --git a/src/dsv41/ds4_pool.hpp b/src/dsv41/ds4_pool.hpp
index 9888f5e3b..167ecde63 100644
--- a/src/dsv41/ds4_pool.hpp
+++ b/src/dsv41/ds4_pool.hpp
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_pool.hpp - the DeepSeek engine's CPU workers: run(n, fn) runs fn(0..n-1) on the workers and the caller and
// returns when every job is done. The design is glmfast::Workers' (src/core/glm_fast_state.hpp): one 64-bit ticket
// (generation << 32 | next index) claimed by CAS, so a worker that wakes late for an older batch can never take a job
diff --git a/src/dsv41/ds4_q6k.cuh b/src/dsv41/ds4_q6k.cuh
index 2eb517eb0..53e458845 100644
--- a/src/dsv41/ds4_q6k.cuh
+++ b/src/dsv41/ds4_q6k.cuh
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_q6k.cuh - one value of a ggml Q6_K superblock (256 values, 210 bytes: ql[128] the low 4 bits, qh[64] the
// high 2, scales[16] int8 a 16 values, d F16), as ggml's dequantize_row_q6_K computes it: d * scale * (q - 32), the two
// products in that order in F32 - the same bits (the Engram tables a GGUF may hold in Q6_K).
diff --git a/src/dsv41/ds4_vision.cu b/src/dsv41/ds4_vision.cu
index b19b307d8..38916c755 100644
--- a/src/dsv41/ds4_vision.cu
+++ b/src/dsv41/ds4_vision.cu
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_vision.cu - DeepSeek-V4.1's vision tower (see ds4_vision.cuh).
//
// One encode, N patches on a gh x gw grid:
diff --git a/src/dsv41/ds4_vision.cuh b/src/dsv41/ds4_vision.cuh
index e3bcb45e2..5f0b20def 100644
--- a/src/dsv41/ds4_vision.cuh
+++ b/src/dsv41/ds4_vision.cuh
@@ -1,3 +1,5 @@
+// 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.
// src/ds4/ds4_vision.cuh - DeepSeek-V4.1's vision tower on one GPU (DeepSeek's inference/vision.py):
// patches (14 x 14 RGB, scaled to [-1, 1]) -> Linear(588 -> 1024)
// 32 blocks: x += attn(rmsnorm(x)) (16 heads of 64, full bidirectional attention over the image, a 2D rotary on q
diff --git a/src/dsv41/vendor/exl3.cu b/src/dsv41/vendor/exl3.cu
index 9307e4185..501010668 100644
--- a/src/dsv41/vendor/exl3.cu
+++ b/src/dsv41/vendor/exl3.cu
@@ -1,3 +1,5 @@
+// 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.
// src/kernels/cuda/exl3.cu - the EXL3 device kernels (the format: include/strata/kernels/exl3.hpp).
//
// The codebooks and the trellis window arithmetic follow exllamav3 (MIT, turboderp - exllamav3_ext/quant/
@@ -17,7 +19,7 @@
// NVIDIA GPUs before sm_80 (V100, T4, RTX 20) decode with v1.1.8's kernels instead (exl3_legacy.cu, use_legacy
// below): this file's CUDA-core fallback was slower there (a V100 with EXL3-3.05bpw: decode 4.9 -> 4.4 tok/s). The
// prompt path below is this file's on every GPU.
-#include "strata/kernels/exl3.hpp"
+#include "strata/dsv41/exl3.hpp"
#include <cuda_fp16.h>
#include <cuda_runtime.h>
@@ -32,7 +34,7 @@
#include <utility>
#if !defined(STRATA_USE_HIP)
-namespace strata::kernels::exl3::legacy { // exl3_legacy.cu: v1.1.8's decode kernels
+namespace strata::dsv41k::exl3::legacy { // exl3_legacy.cu: v1.1.8's decode kernels
int launch_errors();
bool prepare(cudaStream_t s);
bool several_ok();
@@ -40,14 +42,14 @@ bool mv(const MvJob* jobs, int n, cudaStream_t s);
void moe_gate_up(const MoeArgs& a, const float* x, float* h, cudaStream_t s);
void moe_down(const MoeArgs& a, const float* h, const float* sh_out, float* out, cudaStream_t s);
bool win_experts(const WinArgs& a, cudaStream_t s);
-} // namespace strata::kernels::exl3::legacy
+} // namespace strata::dsv41k::exl3::legacy
#define EXL3_LEGACY(call) \
if (use_legacy()) return legacy::call
#else
#define EXL3_LEGACY(call) (void) 0
#endif
-namespace strata::kernels::exl3 {
+namespace strata::dsv41k::exl3 {
namespace {
constexpr int kThreads = 256, kWarps = 8;
@@ -1740,4 +1742,4 @@ void reconstruct_inner(const Mat& m, uint16_t* dst, cudaStream_t s) {
launch_check("reconstruct_inner");
}
-} // namespace strata::kernels::exl3
+} // namespace strata::dsv41k::exl3
diff --git a/src/dsv41/vendor/exl3_cpu.cpp b/src/dsv41/vendor/exl3_cpu.cpp
index 11eca4ebe..e87efee8b 100644
--- a/src/dsv41/vendor/exl3_cpu.cpp
+++ b/src/dsv41/vendor/exl3_cpu.cpp
@@ -1,3 +1,5 @@
+// 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.
// src/kernels/cpu/exl3_cpu.cpp - EXL3 routed experts on the CPU (see include/strata/kernels/cpu/exl3_cpu.hpp).
//
// The vector kernels follow exllamav3's CPU expert kernel (MIT, turboderp - exllamav3_ext/cpu/moe_mul1.cpp, its
@@ -7,9 +9,8 @@
// device's FP16 constant, so the CPU lane computes what the device kernels compute up to the FP16 rounding of each
// weight. The AVX-512 and AVX2 tiers do the same FMAs in the same order: they give the same bits (the bands,
// the split-K pieces, the GEMM's sums and the vectorised transforms alike).
-#include "strata/kernels/cpu/exl3_cpu.hpp"
+#include "strata/dsv41/exl3_cpu.hpp"
-#include "strata/kernels/cpu/expert_layout.hpp"
#include "strata/kernels/f16_bits.hpp"
#include <algorithm>
@@ -44,7 +45,18 @@
#define EXL3_AVX2_INLINE inline
#endif
-namespace strata::kernels::cpu {
+namespace strata::dsv41k::cpu {
+// Strata's cpu_avx2_ok lives in strata_kernels_cpu, which this path does not link: AVX2 + FMA here
+static bool cpu_avx2_ok() {
+#if defined(__x86_64__) && (defined(__GNUC__) || defined(__clang__))
+ __builtin_cpu_init();
+ return __builtin_cpu_supports("avx2") && __builtin_cpu_supports("fma");
+#else
+ return false;
+#endif
+}
+using strata::kernels::f32_from_f16;
+using strata::kernels::f16_from_f32;
namespace {
constexpr uint32_t kMul1 = 0x83DCD12Du;
@@ -1266,4 +1278,4 @@ void exl3_cpu_band(const Exl3Part& m, const float* xh, float xsum, int c0, float
exl3_cpu_band_out(m, acc, xsum, c0, y);
}
-} // namespace strata::kernels::cpu
+} // namespace strata::dsv41k::cpu
diff --git a/src/dsv41/vendor/exl3_legacy.cu b/src/dsv41/vendor/exl3_legacy.cu
index 64ca50fd8..bcc389b1e 100644
--- a/src/dsv41/vendor/exl3_legacy.cu
+++ b/src/dsv41/vendor/exl3_legacy.cu
@@ -1,3 +1,5 @@
+// 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.
// src/kernels/cuda/exl3_legacy.cu - v1.1.8's EXL3 decode kernels, kept for NVIDIA GPUs before sm_80 (V100, T4,
// RTX 20): #180's decode kernels run the tiles on the tensor cores from sm_80 on, and their CUDA-core fallback was
// slower here than these (a V100 with EXL3-3.05bpw: decode 4.9 -> 4.4 tok/s). exl3.cu's mv / moe_gate_up / moe_down
@@ -17,7 +19,7 @@
// blocks: the partial sums go to a per-stream scratch and the LAST block of an output block adds them up in
// split order (deterministic) and runs the output rotation.
#if !defined(STRATA_USE_HIP) // (AMD runs exl3.cu's kernels; EXL3 does not run there anyway)
-#include "strata/kernels/exl3.hpp"
+#include "strata/dsv41/exl3.hpp"
#include <cuda_fp16.h>
#include <cuda_runtime.h>
@@ -29,7 +31,7 @@
#include <mutex>
#include <utility>
-namespace strata::kernels::exl3::legacy {
+namespace strata::dsv41k::exl3::legacy {
namespace {
constexpr int kThreads = 256, kWarps = 8;
@@ -961,5 +963,5 @@ bool win_experts(const WinArgs& a, cudaStream_t s) {
return true;
}
-} // namespace strata::kernels::exl3::legacy
+} // namespace strata::dsv41k::exl3::legacy
#endif
diff --git a/src/dsv41/vendor/moe_win.cu b/src/dsv41/vendor/moe_win.cu
new file mode 100644
index 000000000..fadbad001
--- /dev/null
+++ b/src/dsv41/vendor/moe_win.cu
@@ -0,0 +1,57 @@
+// 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.
+// src/dsv41/vendor/moe_win.cu - the window's expert grouping kernel.
+// Extracted from Project Maya's src/kernels/cuda/glm_fast.cu (MIT, see third_party/project-maya/NOTICE.md).
+#include "strata/dsv41/moe_win.hpp"
+#include <cstdio>
+#include <cstdlib>
+
+namespace strata::dsv41k::glmf {
+namespace {
+constexpr int kWinEnt = kMaxWinTokens * 8;
+
+// the entries grouped by expert slot (in order of first appearance), each group's members in entry order (t * 8 + i)
+// (the tables in shared memory: as locals they were a 2.6 KB stack a thread, which the driver reserves for every thread
+// the device can hold - ~420 MB on a V100 - and a launch failed "out of memory" once the expert pool had the rest)
+__global__ void moe_win_group_kernel(const __grid_constant__ MoeWin w) {
+ __shared__ unsigned long long gp[kWinEnt];
+ __shared__ int cnt[kWinEnt], gof[kWinEnt], fill[kWinEnt + 1];
+ if (threadIdx.x != 0) return;
+ int ng = 0;
+ for (int t = 0; t < w.T; ++t)
+ for (int i = 0; i < 8; ++i) {
+ const int e = t * 8 + i;
+ gof[e] = -1;
+ const unsigned long long p = i < w.k ? w.plan_ptr[e] : 0ull;
+ if (p == 0ull) continue;
+ int g = 0;
+ while (g < ng && gp[g] != p) ++g;
+ if (g == ng) {
+ gp[ng] = p;
+ cnt[ng++] = 0;
+ }
+ ++cnt[g];
+ gof[e] = g;
+ }
+ fill[0] = 0;
+ for (int g = 0; g < ng; ++g) {
+ w.grp_ptr[g] = gp[g];
+ w.grp_start[g] = fill[g];
+ fill[g + 1] = fill[g] + cnt[g];
+ }
+ w.grp_start[ng] = fill[ng];
+ for (int e = 0; e < w.T * 8; ++e)
+ if (gof[e] >= 0) w.grp_ent[fill[gof[e]]++] = e;
+ *w.n_groups = ng;
+}
+} // namespace
+
+void moe_win_group(const MoeWin& w, cudaStream_t s) {
+ moe_win_group_kernel<<<1, 32, 0, s>>>(w);
+ const cudaError_t e = cudaGetLastError();
+ if (e != cudaSuccess) {
+ std::fprintf(stderr, "dsv41: moe_win_group: %s\n", cudaGetErrorString(e));
+ std::abort();
+ }
+}
+} // namespace strata::dsv41k::glmf
diff --git a/src/dsv41/vendor/sampler.cu b/src/dsv41/vendor/sampler.cu
index 7779231cf..b406df584 100644
--- a/src/dsv41/vendor/sampler.cu
+++ b/src/dsv41/vendor/sampler.cu
@@ -1,3 +1,5 @@
+// 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.
// src/kernels/cuda/sampler.cu - P2.S2: the sampler chain, in llama.cpp's order.
//
// penalties -> top_k -> top_p -> min_p -> temperature -> pick
@@ -13,7 +15,7 @@
// Both kernels put ONE BLOCK per token over the vocabulary: `sampler_greedy_kernel` is the plain argmax,
// `sampler_kernel` runs the sampled chain as `top_k` block-argmax rounds followed by the top_p / temperature /
// draw chain (its header says why the selection must be parallel and why the tie rule keeps the semantics).
-#include "strata/kernels/sampler.hpp"
+#include "strata/dsv41/sampler.hpp"
#include <cuda_runtime.h>
@@ -21,7 +23,7 @@
#include <cstdio>
#include <cstdlib>
-namespace strata::kernels {
+namespace strata::dsv41k {
namespace {
// Philox 4x32-10, the counter-based generator the phase asks for. Counter-based matters because it makes the
@@ -576,4 +578,4 @@ void sample_verify(const float* logits, int n_tokens, int n_vocab, const Sampler
spec_launched("sample_verify", stream);
}
-} // namespace strata::kernels
+} // namespace strata::dsv41k
diff --git a/tests/dsv41/ds4_cpu_bench.cpp b/tests/dsv41/ds4_cpu_bench.cpp
index f5666216e..605b8d01c 100644
--- a/tests/dsv41/ds4_cpu_bench.cpp
+++ b/tests/dsv41/ds4_cpu_bench.cpp
@@ -1,3 +1,5 @@
+// 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.
// tests/ds4_cpu_bench.cpp - how fast does this CPU run DeepSeek-V4.1-Flash's EXL3 experts (5120 -> 2304 -> 5120, K 3)?
//
// ds4_cpu_bench [--threads N] [--node 0|1|-1] [--mode band|rows] [--experts N] [--per-call N] [--iters N]
@@ -5,7 +7,7 @@
// Random trellis words in memory bound to --node (-1: wherever the first touch puts them), --threads workers pinned to
// that node's physical cores (CPU i is on node i % 2 here, CPUs 0..43 the physical cores), each call computing
// --per-call experts' gate and up (all columns) from one activation: the time of a matrix pass and its GB/s.
-#include "strata/kernels/cpu/exl3_cpu.hpp"
+#include "strata/dsv41/exl3_cpu.hpp"
#include "../src/ds4/ds4_pool.hpp"
#include <sys/mman.h>
@@ -20,7 +22,7 @@
#include <string>
#include <vector>
-namespace kc = strata::kernels::cpu;
+namespace kc = strata::dsv41k::cpu;
static void* node_alloc(size_t bytes, int node) {
void* p = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
diff --git a/tests/dsv41/ds4_gguf_test.cu b/tests/dsv41/ds4_gguf_test.cu
index a24059bcb..0bc0c4f51 100644
--- a/tests/dsv41/ds4_gguf_test.cu
+++ b/tests/dsv41/ds4_gguf_test.cu
@@ -1,3 +1,5 @@
+// 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.
// tests/ds4_gguf_test.cu - maya-ds4's GGUF kernels (src/ds4/ds4_gguf.cu, ds4_gguf_cpu.cpp) against a plain
// double-precision reference of random BF16 matrices and MXFP4 experts: the GEMVs (BF16 / MXFP4, 1..16 activations,
// aligned or not), the token experts (gate / up / swiglu / down / combine, experts off the device, the CPU part, the
@@ -26,7 +28,7 @@
#include <vector>
namespace gg = strata::ds4::gguf;
-namespace x3 = strata::kernels::exl3;
+namespace x3 = strata::dsv41k::exl3;
namespace {
diff --git a/tests/dsv41/ds4_mx_bench.cpp b/tests/dsv41/ds4_mx_bench.cpp
index af6b77650..9d17e2fdd 100644
--- a/tests/dsv41/ds4_mx_bench.cpp
+++ b/tests/dsv41/ds4_mx_bench.cpp
@@ -1,3 +1,5 @@
+// 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.
// tests/ds4_mx_bench.cpp - how fast does this CPU run DeepSeek-V4.1-Flash's MXFP4 experts on the CPU lane?
//
// ds4_mx_bench [--threads 1,6,12] [--T 1,2,4,8,16] [--experts 16] [--per-layer 3] [--secs 0.4] [--pf 0]
diff --git a/tools/dsv41/bytecheck.sh b/tools/dsv41/bytecheck.sh
index 18f606f2d..2e61dd2f2 100644
--- a/tools/dsv41/bytecheck.sh
+++ b/tools/dsv41/bytecheck.sh
@@ -1,4 +1,6 @@
#!/bin/bash
+# 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.
# tools/ds4/bytecheck.sh - maya-ds4's byte-identity check of two builds (a change that must not move a bit: the same
# prompt through each, every logit row dumped, the files compared byte for byte, the greedy tokens compared).
#
diff --git a/tools/dsv41/compare.py b/tools/dsv41/compare.py
index 9dfd91b43..32925f669 100644
--- a/tools/dsv41/compare.py
+++ b/tools/dsv41/compare.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/compare.py - the engine's logits (maya-ds4 --dump-logits) against the reference's (tools/ds4/ref.py --dump).
python tools/ds4/compare.py --ref ref.npz --engine engine.f32 [--vocab 129280]
diff --git a/tools/dsv41/drafter_pack.py b/tools/dsv41/drafter_pack.py
index 0b4394f58..a7f54ad4d 100644
--- a/tools/dsv41/drafter_pack.py
+++ b/tools/dsv41/drafter_pack.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/drafter_pack.py - DeepSeek-V4.1's DSpark drafter (the speculative decoder the GGUFs leave out) for a GGUF
install: its three blocks from DeepSeek's own checkpoint (the shards that hold only them, model-00044..46-of-00048),
in the formats the GGUF path runs, as one file beside them that pack_gguf.py adds to the pack.
diff --git a/tools/dsv41/dspark_ref.py b/tools/dsv41/dspark_ref.py
index e27485813..858146ca0 100644
--- a/tools/dsv41/dspark_ref.py
+++ b/tools/dsv41/dspark_ref.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/dspark_ref.py - DeepSeek-V4.1's DSpark drafter in torch, straight from DeepSeek's checkpoint, against what
the engine's drafter computed (the engine's oracle for the drafter; ref.py / ref_gguf.py cover the trunk only).
diff --git a/tools/dsv41/dumpcmp.py b/tools/dsv41/dumpcmp.py
index 1af24c526..8d28adc01 100644
--- a/tools/dsv41/dumpcmp.py
+++ b/tools/dsv41/dumpcmp.py
@@ -1,3 +1,5 @@
+# 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.
"""dumpcmp.py - two maya-ds4 runs' debug dumps side by side (the prompt path's numerics: where two runs part).
layers A B [--pos P] DS4_DUMP_L files: each layer record's relative error between the runs - the median over
diff --git a/tools/dsv41/dumpscan.py b/tools/dsv41/dumpscan.py
index 2c799cbd7..dcab698a7 100644
--- a/tools/dsv41/dumpscan.py
+++ b/tools/dsv41/dumpscan.py
@@ -1,3 +1,5 @@
+# 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.
"""dumpscan.py DUMP_L [--pos P] [--dim 5120] [--hc 4] - one run's DS4_DUMP_L records: each layer's residual stream at
position P against the other positions (its norm over the median norm, its largest |value| and where, non-finite
values) - where a position's stream blows up or goes non-finite."""
diff --git a/tools/dsv41/dumpscan_y.py b/tools/dsv41/dumpscan_y.py
index bb8cbae5e..bee260259 100644
--- a/tools/dsv41/dumpscan_y.py
+++ b/tools/dsv41/dumpscan_y.py
@@ -1,3 +1,5 @@
+# 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.
"""dumpscan_y.py DUMP_Y DUMP_R --pos P [--layers a-b] - one run's expert set rows (DS4_DUMP_Y, DS4_DUMP_R): position
P's rows a layer - its experts, their rows and P's place in them, |h| and |y| against the layer's median row."""
import argparse
diff --git a/tools/dsv41/engram_hash.py b/tools/dsv41/engram_hash.py
index 43b861d94..ce97aed65 100644
--- a/tools/dsv41/engram_hash.py
+++ b/tools/dsv41/engram_hash.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/engram_hash.py - DeepSeek-V4.1's Engram n-gram hashes (after DeepSeek's inference/engram.py, MIT).
A position is hashed as the n-grams (2 .. max_ngram_size) that end there, each over n_heads heads; every (n-gram
diff --git a/tools/dsv41/exl3_torch.py b/tools/dsv41/exl3_torch.py
index 848e2e68d..48505de07 100644
--- a/tools/dsv41/exl3_torch.py
+++ b/tools/dsv41/exl3_torch.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/exl3_torch.py - EXL3 (exllamav3) matrices decoded on the GPU with torch, for the DeepSeek-V4.1 reference.
The format is include/strata/kernels/exl3.hpp's; this is tools/exl3_pack.py's numpy decoder (exl3_states, exl3_values,
diff --git a/tools/dsv41/pack.py b/tools/dsv41/pack.py
index 4ab6edf33..e0e895085 100644
--- a/tools/dsv41/pack.py
+++ b/tools/dsv41/pack.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/pack.py - the engine's pack for a DeepSeek-V4.1 EXL3 model, beside the model's files (no weights copied).
python tools/ds4/pack.py --model ~/models/DSV4
diff --git a/tools/dsv41/pack_gguf.py b/tools/dsv41/pack_gguf.py
index f7cd510ba..5638fe837 100644
--- a/tools/dsv41/pack_gguf.py
+++ b/tools/dsv41/pack_gguf.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/pack_gguf.py - the engine's pack for a DeepSeek-V4.1 GGUF (unsloth's DeepSeek-V4.1-Flash-1017 UD-Q8_K_XL
and the like: dense BF16, routed experts MXFP4, Engram tables MXFP8 or Q6_K), beside the model's files (no weights
copied).
diff --git a/tools/dsv41/ref.py b/tools/dsv41/ref.py
index 9659aa8b7..46f541760 100644
--- a/tools/dsv41/ref.py
+++ b/tools/dsv41/ref.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/ref.py - a whole-sequence DeepSeek-V4.1 forward in torch over an EXL3 checkpoint (the engine's oracle).
python tools/ds4/ref.py --model ~/models/DSV4 --text "The capital of France is" [--dump out.npz] [--gen 8]
diff --git a/tools/dsv41/ref_gguf.py b/tools/dsv41/ref_gguf.py
index 60e8abf85..e9d042146 100644
--- a/tools/dsv41/ref_gguf.py
+++ b/tools/dsv41/ref_gguf.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/ref_gguf.py - tools/ds4/ref.py's oracle over a GGUF (tools/ds4/pack_gguf.py's pack): the same forward,
each weight dequantised in torch from the GGUF's own blocks (BF16, Q8_0, MXFP4, MXFP8) - a check of maya-ds4's GGUF
path that shares none of its code.
diff --git a/tools/dsv41/requant_gguf.py b/tools/dsv41/requant_gguf.py
index 0740c7492..bc28b9c13 100644
--- a/tools/dsv41/requant_gguf.py
+++ b/tools/dsv41/requant_gguf.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/requant_gguf.py - a DeepSeek-V4.1 GGUF requantized by a recipe (the routed experts in ggml's low-bit types,
the dense matrices in Q8_0), through ggml's own quantizers (libggml-base, ctypes) - a quick test model for maya-ds4's
low-bit expert kernels until the real Maya quants exist.
diff --git a/tools/dsv41/st.py b/tools/dsv41/st.py
index de70f0ba2..a47f70fd5 100644
--- a/tools/dsv41/st.py
+++ b/tools/dsv41/st.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/st.py - every tensor of a DeepSeek-V4.1 model directory, read in place.
st = SafeTensors(Path("~/models/DSV4").expanduser())
diff --git a/tools/dsv41/tok.py b/tools/dsv41/tok.py
index b26e133bc..228332b32 100644
--- a/tools/dsv41/tok.py
+++ b/tools/dsv41/tok.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/tok.py - token ids for maya-ds4's --ids, and text back from its output (DeepSeek-V4.1's tokenizer).
python tools/ds4/tok.py --model ~/models/DSV4 --chat "Why is the sky blue?" [--think] -> 0,128803,...
diff --git a/tools/dsv41/vision_pack.py b/tools/dsv41/vision_pack.py
index 6144b3501..61db7ce5e 100644
--- a/tools/dsv41/vision_pack.py
+++ b/tools/dsv41/vision_pack.py
@@ -1,3 +1,5 @@
+# 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.
"""tools/ds4/vision_pack.py - DeepSeek-V4.1's vision tower (the part of the model that reads pictures, which the GGUFs
leave out) for a GGUF install: shard 1 of DeepSeek's own checkpoint (model-00001-of-00048, the tower's vision.* and the
aligner's aligner.* tensors, BF16, nothing else) and config.json (their geometry) from download_gguf.json's "vision"