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++

UD-Q6_K_XL: Q6_K gate/up kernels behind -DSTRATA_Q6K_EXPERTS=ON; the Q8_0 PLE hunk is left to the #651 series

Niko1221ac7db2e522f3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f8f4b06c2..ab6d17975 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,13 @@ option(STRATA_PREFILL_MMQ "Build the optional GGML MMQ prefill path for HIP" OFF
# every kernel when it starts (CUDA_MODULE_LOADING=EAGER), so these took ~5 MB of VRAM - 1-3 expert slots - from every
# model, and the UD-Q4_K_XL prompt is SSD-bound with or without them (docs/UNSLOTH_Q4.md)
option(STRATA_MMQ_KQUANTS "Build the MMQ prompt kernels for Q4_K / Q5_K / Q5_1 / Q6_K: the CUDA experts of Unsloth's UD-Q4_K_XL, and on HIP the dense GGUF projections (STRATA_DENSE_MMQ)" OFF)
+# CUDA: Q6_K gate/up in the grouped expert kernels (Unsloth's UD-Q6_K_XL, docs/UNSLOTH_Q6.md). Off by default: every
+# grouped-kernel instance is loaded when the engine starts (CUDA_MODULE_LOADING=EAGER), so one more costs VRAM that
+# every other model would lose as expert slots (PR #860 review)
+option(STRATA_Q6K_EXPERTS "Build the Q6_K gate/up grouped expert kernels (UD-Q6_K_XL)" OFF)
+if(STRATA_Q6K_EXPERTS)
+ add_compile_definitions(STRATA_Q6K_EXPERTS=1)
+endif()
option(STRATA_ORCA_Q4KS_MMQ "Build the GGML Q5_0 MMQ instance for OrcaRouter Q4_K_S" OFF)
if(STRATA_PREFILL_MMQ AND NOT STRATA_ENABLE_HIP)
message(FATAL_ERROR "STRATA_PREFILL_MMQ requires STRATA_ENABLE_HIP=ON")
@@ -1255,7 +1262,11 @@ if(STRATA_NATIVE_EXPERTS)
foreach(_pair q4_K/q5_1 q4_K/q8_0 q5_K/q8_0 q8_0/q8_0 q4_K/q5_0 q5_0/q8_0 q4_0/q4_0 q4_0/q4_1)
# q6_K/q8_0: Unsloth UD-Q6_K_XL gate/up Q6_K with Q8_0 down (docs/UNSLOTH_Q6.md). Layer 2 is q8_0/q8_0, already listed.
- foreach(_pair q4_K/q5_1 q4_K/q8_0 q5_K/q8_0 q8_0/q8_0 q4_K/q5_0 q5_0/q8_0 q6_K/q8_0)
+ set(_strata_parity_pairs q4_K/q5_1 q4_K/q8_0 q5_K/q8_0 q8_0/q8_0 q4_K/q5_0 q5_0/q8_0)
+ if(STRATA_Q6K_EXPERTS)
+ list(APPEND _strata_parity_pairs q6_K/q8_0)
+ endif()
+ foreach(_pair ${_strata_parity_pairs})
string(REPLACE "/" "_" _name "${_pair}")
add_test(NAME native_expert_parity_${_name} COMMAND native_expert_parity --synthetic ${_pair})
set_tests_properties(native_expert_parity_${_name} PROPERTIES TIMEOUT 120)
@@ -1270,8 +1281,6 @@ if(STRATA_NATIVE_EXPERTS)
add_executable(ple_q5_parity src/kernels/ple_q5_parity.cpp)
target_link_libraries(ple_q5_parity PRIVATE strata_kernels strata_artifact ggml-base ${_strata_gpu_runtime_target})
# Unsloth's UD-Q6_K_XL ships per_layer_token_embd as Q8_0 (170-B rows) - same check, different type
- add_executable(ple_q8_parity src/kernels/ple_q8_parity.cpp)
- target_link_libraries(ple_q8_parity PRIVATE strata_kernels strata_artifact ggml-base ${_strata_gpu_runtime_target})
add_executable(q5_projection_parity src/kernels/q5_projection_parity.cpp)
target_include_directories(q5_projection_parity PRIVATE ${_strata_gpu_include_directories})
target_link_libraries(q5_projection_parity PRIVATE strata_kernels strata_artifact ggml-base ${_strata_gpu_runtime_target})
diff --git a/docs/UNSLOTH_Q6.md b/docs/UNSLOTH_Q6.md
index 6d0f40376..5ca0edc1e 100644
--- a/docs/UNSLOTH_Q6.md
+++ b/docs/UNSLOTH_Q6.md
@@ -6,6 +6,11 @@ same model the other packs use:
Build it for engine 0.1.38 or newer (earlier engines read `per_layer_token_embd.weight` in IQ4_NL, Q5_0 or FP8 only,
below). UD-Q4_K_XL's manual workflow asks nothing of setup, and neither does this one.
+> **0.1.40 status.** The Q6_K gate/up kernels are an opt-in build (`-DSTRATA_Q6K_EXPERTS=ON`, plus `-DSTRATA_MMQ_KQUANTS=ON`
+> for the prompt kernels): every grouped-kernel instance is loaded at start and would cost other models expert slots. The
+> Q8_0 PLE table reader is not in this release (it comes with the PLE format series, PR #651); until then this file does
+> not load. The parity programs below have not been run on a GPU yet.
+
## What is in the file
Six shards, 169,165,382,688 bytes (169.2 GB) together ([sizes and SHA-256 from the HF tree API](https://huggingface.co/api/models/unsloth/Qwen3.8-Flash-Next-GGUF/tree/38bb39ee97821de2c9009abb7e93950eec396e66/UD-Q6_K_XL);
diff --git a/include/strata/kernels/ngram.hpp b/include/strata/kernels/ngram.hpp
index 9172556f5..68aa7118b 100644
--- a/include/strata/kernels/ngram.hpp
+++ b/include/strata/kernels/ngram.hpp
@@ -79,6 +79,8 @@ std::string ple_format_list();
inline constexpr int PLE_ROW_BYTES_Q8_0 = (PLE_HEAD_DIM / 32) * 34; // 170: a Q8_0 row (Unsloth's UD-Q6_K_XL)
inline constexpr int PLE_ROW_BYTES_MAX = PLE_ROW_BYTES_Q8_0;
+inline constexpr int PLE_ROW_BYTES_MAX = PLE_ROW_BYTES_FP8;
+
/// The artifact's own hash constants, transcribed from `docs/gguf-dump-shard1.txt`:
///
/// layer_multipliers = [23703573157769, 20109073645365, 8052911324071]
diff --git a/include/strata/ngram/ple_reader.hpp b/include/strata/ngram/ple_reader.hpp
index 11729f7d4..2884817ef 100644
--- a/include/strata/ngram/ple_reader.hpp
+++ b/include/strata/ngram/ple_reader.hpp
@@ -58,7 +58,7 @@ public:
/// validated GGUF parse (PleTable::open checks the table exactly fills the file from there).
/// `io_thread` (default): a worker thread submits and reaps reads, so `issue` costs the caller no ReadFile
/// calls. false: the caller's thread does it (A/B arm).
- /// `row_bytes`: one row's size in the file (90 IQ4_NL, 110 Q5_0, 160 FP8, 170 Q8_0), at most one page.
+ /// `row_bytes`: one row's size in the file (90 IQ4_NL, 160 FP8), at most one page.
bool open(const std::string& path, uint64_t table_offset, uint64_t n_rows, uint32_t max_inflight,
uint64_t cache_rows, std::string& err, bool io_thread = true, uint32_t row_bytes = ROW_BYTES);
uint32_t row_bytes() const;
diff --git a/src/kernels/cuda/iq_kernels.cu b/src/kernels/cuda/iq_kernels.cu
index 128962ea8..3bf4e1e7c 100644
--- a/src/kernels/cuda/iq_kernels.cu
+++ b/src/kernels/cuda/iq_kernels.cu
@@ -611,7 +611,12 @@ template<> struct Fmt<8> { static constexpr int qk = 32, ipb = QI8_0 / VDR_Q8_0,
#define STRATA_D_FMTS(X) X(20) X(23) X(42) X(7) X(6) X(2) X(3) X(8)
#define STRATA_MMVQ_FMTS(X) X(16) X(17) X(18) X(20) X(21) X(22) X(23) X(29) X(42) X(12) X(13) X(7) X(6) X(2) X(3) X(8)
+
+#ifdef STRATA_Q6K_EXPERTS // opt-in build (-DSTRATA_Q6K_EXPERTS=ON): one more instance per kernel, loaded at start
#define STRATA_GU_FMTS(X) X(16) X(17) X(18) X(21) X(22) X(23) X(29) X(42) X(12) X(13) X(14) X(6) X(8)
+#else
+#define STRATA_GU_FMTS(X) X(16) X(17) X(18) X(21) X(22) X(23) X(29) X(42) X(12) X(13) X(6) X(8)
+#endif
#define STRATA_D_FMTS(X) X(20) X(23) X(42) X(7) X(6) X(8)
#define STRATA_MMVQ_FMTS(X) X(16) X(17) X(18) X(20) X(21) X(22) X(23) X(29) X(42) X(12) X(13) X(7) X(6) X(8)
@@ -1794,7 +1799,9 @@ __device__ __forceinline__ void dq_dispatch(int ty, const void* vx, int64_t ibs,
case 42: dq_q2_0(vx, ibs, y, tid); break;
case 12: dq_q4_k(vx, ibs, y, tid); break;
case 13: dq_q5_k(vx, ibs, y, tid); break;
+#ifdef STRATA_Q6K_EXPERTS
case 14: dq_q6_k(vx, ibs, y, tid); break;
+#endif
case 7: dq_q5_1(vx, ibs, y, tid); break;
case 6: dq_q5_0(vx, ibs, y, tid); break;
case 2: dq_q4_0(vx, ibs, y, tid); break;
@@ -1826,6 +1833,12 @@ bool is_iq(int t) {
t == 12 || t == 13 || t == 7 || t == 6 || t == 2 || t == 3 || t == 8;
t == 12 || t == 13 || t == 14 || t == 7 || t == 6 || t == 8;
+
+ t == 12 || t == 13 ||
+#ifdef STRATA_Q6K_EXPERTS
+ t == 14 ||
+#endif
+ t == 7 || t == 6 || t == 8;
}
// values per block of the types the grouped expert kernels take (0 = none)
int gu_qk(int t) {
diff --git a/src/kernels/native_grouped_parity.cpp b/src/kernels/native_grouped_parity.cpp
index f682f4f31..270de2cb6 100644
--- a/src/kernels/native_grouped_parity.cpp
+++ b/src/kernels/native_grouped_parity.cpp
@@ -341,7 +341,11 @@ int main(int argc, char** argv) {
cudaStream_t s;
ck(cudaStreamCreate(&s), "stream");
std::mt19937 rng(316);
- for (int gu : {16, 17, 18, 21, 22, 23, 29, 42, 12, 13, 14, 8}) // STRATA_GU_FMTS
+ for (int gu : {16, 17, 18, 21, 22, 23, 29, 42, 12, 13,
+#ifdef STRATA_Q6K_EXPERTS
+ 14,
+#endif
+ 8}) // STRATA_GU_FMTS
for (int dt : {20, 23, 42, 7, 8}) check(gu, dt, 512, 256, s, rng); // STRATA_D_FMTS; IQ4_XS: n_ff % 256
check(21, 20, 2560, 640, s, rng); // a model's shapes
check(21, 23, 2560, 768, s, rng);
diff --git a/src/kernels/ngram.cpp b/src/kernels/ngram.cpp
index 374475931..6b4217269 100644
--- a/src/kernels/ngram.cpp
+++ b/src/kernels/ngram.cpp
@@ -223,6 +223,7 @@ struct PleTable::Impl {
void decode(const uint8_t* row, float* out160) const { fmt->dequant(row, scale, out160); }
bool q8_0 = false; // Q8_0 rows (170 B): Unsloth's UD-Q6_K_XL ships the table as Q8_0
+
bool fp8 = false; // F8_E4M3 rows (tools/ple_fp8_pack.py); else IQ4_NL
float scale = 1.0f; // the FP8 table's one scale
uint32_t rb = PLE_ROW_BYTES; // bytes per row
@@ -230,8 +231,6 @@ struct PleTable::Impl {
if (fp8) fp8_e4m3_dequant_row(row, scale, out160);
else if (q5_0)
for (int b = 0; b < PLE_HEAD_DIM / 32; ++b) strata::dequantize_q5_0(row + (size_t) b * 22, out160 + b * 32);
- else if (q8_0)
- for (int b = 0; b < PLE_HEAD_DIM / 32; ++b) strata::dequantize_q8_0(row + (size_t) b * 34, out160 + b * 32);
else iq4nl_dequant_row(row, out160);
}
};
@@ -277,11 +276,12 @@ bool PleTable::open(const std::string& gguf_path, std::string& err, const PleIoO
// IQ4_NL (ISTA-DASLab's shard 2, the original's own GGUF), Q5_0 (#296: OrcaRouter's GGUF), Q8_0 (Unsloth's
// UD-Q6_K_XL), or the FP8 table as shipped: I8 bytes marked strata.ple.format = f8_e4m3 with strata.ple.scale
// (tools/ple_fp8_pack.py)
+
+ // IQ4_NL (ISTA-DASLab's shard 2, the original's own GGUF), Q5_0 (#296: OrcaRouter's GGUF), or the FP8 table as
+ // shipped: I8 bytes marked strata.ple.format = f8_e4m3 with strata.ple.scale (tools/ple_fp8_pack.py)
impl_->fp8 = false;
impl_->q5_0 = std::strcmp(t->type_name(), "Q5_0") == 0;
- impl_->q8_0 = std::strcmp(t->type_name(), "Q8_0") == 0;
- impl_->rb = impl_->q5_0 ? (PLE_HEAD_DIM / 32) * 22
- : impl_->q8_0 ? (PLE_HEAD_DIM / 32) * 34 : PLE_ROW_BYTES;
+ impl_->rb = impl_->q5_0 ? (PLE_HEAD_DIM / 32) * 22 : PLE_ROW_BYTES;
if (std::strcmp(t->type_name(), "I8") == 0) {
const MetaValue* f = impl_->file->get("strata.ple.format");
const MetaValue* s = impl_->file->get("strata.ple.scale");
@@ -293,8 +293,8 @@ bool PleTable::open(const std::string& gguf_path, std::string& err, const PleIoO
impl_->scale = (float) s->num();
impl_->rb = PLE_ROW_BYTES_FP8;
- } else if (!impl_->q5_0 && !impl_->q8_0 && std::strcmp(t->type_name(), "IQ4_NL") != 0) {
- err = std::string("per_layer_token_embd.weight is ") + t->type_name() + ", not IQ4_NL, Q5_0, Q8_0 or FP8 (I8)";
+ } else if (!impl_->q5_0 && std::strcmp(t->type_name(), "IQ4_NL") != 0) {
+ err = std::string("per_layer_token_embd.weight is ") + t->type_name() + ", not IQ4_NL, Q5_0 or FP8 (I8)";
close();
return false;
}
@@ -440,7 +440,6 @@ void PleTable::close() {
impl_->bytes_read = 0;
impl_->q5_0 = false;
- impl_->q8_0 = false;
impl_->fp8 = false;
}
@@ -449,6 +448,8 @@ bool PleTable::locked() const { return impl_->locked; }
const char* PleTable::format() const { return impl_->fmt->name; }
const char* PleTable::format() const { return impl_->fp8 ? "F8_E4M3" : impl_->q5_0 ? "Q5_0" : impl_->q8_0 ? "Q8_0" : "IQ4_NL"; }
+
+const char* PleTable::format() const { return impl_->fp8 ? "F8_E4M3" : impl_->q5_0 ? "Q5_0" : "IQ4_NL"; }
PleIo PleTable::mode() const { return impl_->mode; }
uint64_t PleTable::rows() const { return impl_->n_rows; }
uint64_t PleTable::bytes_read() const { return impl_->bytes_read; }
diff --git a/src/kernels/ple_q8_parity.cpp b/src/kernels/ple_q8_parity.cpp
deleted file mode 100644
index 899e6f2ec..000000000
--- a/src/kernels/ple_q8_parity.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// Real-artifact Q8_0 PLE rows against ggml's reference dequantizer.
-// The PLE table in Unsloth's UD-Q6_K_XL GGUF ships as Q8_0 (170-B rows) rather than IQ4_NL; this
-// mirrors ple_q5_parity.cpp so the Q8_0 read path is checked the same way, through BOTH I/O modes
-// (Mmap and Direct) like ple_fp8_parity does.
-#define NOMINMAX
-#include "strata/artifact/gguf_reader.hpp"
-#include "strata/kernels/ngram.hpp"
-#include "ggml.h"
-
-#include <algorithm>
-#include <cmath>
-#include <cstdio>
-#include <cstring>
-#include <string>
-#include <vector>
-
-int main(int argc, char** argv) {
- if (argc != 2) {
- std::fprintf(stderr, "usage: ple_q8_parity <gguf-containing-ple>\n");
- return 2;
- }
- strata::GgufFile gguf(argv[1]);
- const auto* tensor = gguf.find("per_layer_token_embd.weight");
- if (!tensor || tensor->type != 8 || tensor->shape.size() != 2 || tensor->shape[0] != 160) {
- std::fprintf(stderr, "expected Q8_0 PLE [160, N]\n");
- return 2;
- }
- const auto* traits = ggml_get_type_traits(GGML_TYPE_Q8_0);
- const uint8_t* bytes = gguf.tensor_data(*tensor);
- double max_abs_all = 0.0;
- size_t rows_checked = 0;
- for (const int direct : {0, 1}) {
- strata::kernels::PleIoOptions options;
- options.mode = direct ? strata::kernels::PleIo::Direct : strata::kernels::PleIo::Mmap;
- strata::kernels::PleTable table;
- std::string err;
- if (!table.open(argv[1], err, options)) {
- std::fprintf(stderr, "%s\n", err.c_str());
- return 1;
- }
- if (std::strcmp(table.format(), "Q8_0") != 0) {
- std::fprintf(stderr, "format() = %s, expected Q8_0\n", table.format());
- return 1;
- }
- rows_checked = (size_t) table.rows();
- // The real table's row 20000003 (the first head's vocab edge) only exists in a table that big; a
- // small synthetic fixture stands in for it so the same binary checks both.
- const uint32_t probes[] = {0, 1, 12345,
- table.rows() > 20000004 ? 20000003u : (uint32_t) (table.rows() / 2),
- (uint32_t) (table.rows() - 1)};
- double max_abs = 0.0;
- for (uint32_t row : probes) {
- float got[160], want[160];
- table.read_row(row, got);
- traits->to_float(bytes + (size_t) row * 170, want, 160);
- for (int i = 0; i < 160; ++i)
- max_abs = std::max(max_abs, (double) std::fabs(got[i] - want[i]));
- }
- uint32_t rows[16];
- for (int i = 0; i < 16; ++i) rows[i] = probes[i % 5];
- float batch[16 * 160];
- if (!table.issue(rows) || !table.collect(batch, err)) {
- std::fprintf(stderr, "collect: %s\n", err.c_str());
- return 1;
- }
- for (int h = 0; h < 16; ++h) {
- float want[160];
- traits->to_float(bytes + (size_t) rows[h] * 170, want, 160);
- for (int i = 0; i < 160; ++i)
- max_abs = std::max(max_abs, (double) std::fabs(batch[h * 160 + i] - want[i]));
- }
- if (direct) std::printf("Direct: ");
- else std::printf("Mmap: ");
- std::printf("%zu rows, max_abs %.3e\n", rows_checked, max_abs);
- max_abs_all = std::max(max_abs_all, max_abs);
- }
- std::printf("Q8_0 PLE: max_abs %.3e %s\n", max_abs_all, max_abs_all <= 1e-6 ? "PASS" : "FAIL");
- return max_abs_all <= 1e-6 ? 0 : 1;
-}
\ No newline at end of file
diff --git a/src/ngram/ple_reader_test.cpp b/src/ngram/ple_reader_test.cpp
index 41366f066..66a7c089d 100644
--- a/src/ngram/ple_reader_test.cpp
+++ b/src/ngram/ple_reader_test.cpp
@@ -247,6 +247,10 @@ void all_formats_round_trip(const std::string& dir) {
// 170 (Unsloth's UD-Q6_K_XL Q8_0 PLE rows) are run too, through the exact same generic row_bytes path --
// nothing here is IQ4_NL-specific, so extra row sizes run here are the correctness evidence for lifting
// ngram.cpp's format-specific refusals.
+
+// row_bytes: ng::ROW_BYTES (90, IQ4_NL) is the production default; 110 (#296, OrcaRouter's Q5_0 PLE rows) is
+// run too, through the exact same generic row_bytes path -- nothing here is IQ4_NL-specific, so a second row
+// size run here is the correctness evidence for lifting ngram.cpp's "Q5_0 PLE requires --ple-io mmap" refusal.
int selftest(const std::string& dir, uint32_t rb) {
const uint32_t N = 500000; // 45 MB: large enough for thousands of distinct pages
const std::string path = dir + "/ple_reader_selftest_" + std::to_string(rb) + ".bin";
@@ -466,9 +470,10 @@ int main(int argc, char** argv) {
// ng::ROW_BYTES (90, IQ4_NL, production default), 110 (#296, OrcaRouter's Q5_0 PLE rows) and 170
// (Unsloth's UD-Q6_K_XL Q8_0 PLE rows) through the same generic row_bytes path -- see the comment on
// selftest().
+
const int r90 = selftest(dir, ng::ROW_BYTES);
const int r110 = selftest(dir, 110);
- return r90 != 0 ? r90 : r110 != 0 ? r110 : selftest(dir, 170);
+ return r90 != 0 ? r90 : r110;
}
if (!make_path.empty()) { // a big synthetic table, for timing --ple-io ram's fault-in
for (int i = 0; i < k::ple_format_count(); ++i) {
diff --git a/tools/ple_q8_fixture.py b/tools/ple_q8_fixture.py
deleted file mode 100644
index 22d2e4212..000000000
--- a/tools/ple_q8_fixture.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python3
-"""tools/ple_q8_fixture.py - a small synthetic PLE table as Q8_0 in a one-tensor GGUF.
-
-Built for the Q8_0 PLE path (Unsloth's UD-Q6_K_XL ships per_layer_token_embd as Q8_0, 170-B rows)
-so ple_q8_parity can run without the real 54-GB shard 3. The bytes are random with a fixed seed:
-every Q8_0 block decodes as d * int8, so ANY bytes are valid input, and the point of the parity test
-is that Strata's dequantizer agrees with ggml's reference on whatever is there.
-
- python tools/ple_q8_fixture.py --out /tmp/ple_q8.gguf [--rows 131072] [--seed 7]
-
-Validate the file with tools/gguf_reader.py first; then
- ple_q8_parity /tmp/ple_q8.gguf
-"""
-import argparse
-import pathlib
-import struct
-
-import numpy as np
-
-BLOCK = 34 # Q8_0: f16 scale + 32 int8
-DIM = 160 # PLE_HEAD_DIM: the fast axis, one row = 5 blocks
-
-
-def main() -> None:
- ap = argparse.ArgumentParser()
- ap.add_argument('--out', required=True)
- ap.add_argument('--rows', type=int, default=131072) # >= 16 for gather_batch, small enough to be quick
- ap.add_argument('--seed', type=int, default=7)
- args = ap.parse_args()
-
- rng = np.random.default_rng(args.seed)
- n_block = args.rows * (DIM // 32)
- d = rng.uniform(-0.001, 0.001, n_block).astype(np.float16)
- # small scales and int8 values: products stay in exact-float range, no NaN/inf edge cases
- qs = rng.integers(-128, 128, (n_block, 32), dtype=np.int8)
- data = np.empty(n_block * BLOCK, dtype=np.uint8)
- view = data.view(np.uint8).reshape(n_block, BLOCK)
- view[:, 0:2] = d.view(np.uint8).reshape(n_block, 2)
- view[:, 2:] = qs.view(np.uint8)
- assert data.size == args.rows * DIM // 32 * BLOCK
-
- name = b'per_layer_token_embd.weight'
- buf = bytearray()
- buf += struct.pack('<4sIQQ', b'GGUF', 3, 1, 0) # magic, version, 1 tensor, 0 metadata kv
- buf += struct.pack('<Q', len(name)) + name # tensor name (v3: uint64 length)
- buf += struct.pack('<IQQI', 2, DIM, args.rows, 8) # n_dims, shape [160, rows], type Q8_0, offset 0
- hlen = len(buf)
- pad = (-len(buf)) % 32 # data_start is alignment-padded (default 32)
- buf += b'\0' * pad
- buf += data.tobytes()
- out = pathlib.Path(args.out)
- out.write_bytes(bytes(buf))
- # the tensor must fill the file from data_start exactly: PleTable asserts it when alone in its shard
- assert out.stat().st_size == len(buf) == hlen + pad + data.size
- print(f'{out}: {args.rows} rows x {DIM} elems x {BLOCK}+0 B blocks = {data.size} B data, header {pad + 4 + len(name) + 4 + 16 + 4 + 8} B (pad {pad})')
-
-
-if __name__ == '__main__':
- main()
\ No newline at end of file