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

fix: --dump-logits must not promise rows it will never write

Constantin504579da127a
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index a02b3e3d3..11d473e88 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -3353,6 +3353,10 @@ int main(int argc, char** argv) {
}
std::FILE* dump = nullptr;
+ // The logits header is written WITH THE FIRST ROW, not at open: a native pack never reaches the
+ // per-token dump site, and a header promising rows that were never written is worse than no file.
+ int32_t hdr[2] = {0, 0};
+ bool hdr_written = false;
const int64_t dump_positions = (int64_t) o.tokens.size() - 1 + o.max_new;
if (!o.dump_logits.empty()) {
if (dump_positions > INT32_MAX || n_vocab > INT32_MAX) {
@@ -3372,12 +3376,7 @@ int main(int argc, char** argv) {
// of the size gets a wrong answer that looks authoritative. `tools/logits_identical.py` caught it by
// parsing the header and refusing the file.
const int32_t n_rows = (int32_t) strata::program::logits_selection::row_count(dump_positions, o.logits_stride);
- const int32_t hdr[2] = {(int32_t) n_vocab, n_rows};
- if (std::fwrite(hdr, sizeof hdr, 1, dump) != 1) {
- std::fprintf(stderr, "strata generate: cannot write logits header\n");
- std::fclose(dump);
- return 1;
- }
+ hdr[0] = n_vocab; hdr[1] = n_rows;
}
// ---- THE C1 ORACLE: ONE RESIDUAL SNAPSHOT PER LAYER PER POSITION, so the engine can be bisected against
@@ -6073,6 +6072,17 @@ int main(int argc, char** argv) {
(long long) n_vocab, (long long) pos);
return 1;
}
+ // THE HEADER IS WRITTEN WITH THE FIRST ROW, NOT AT OPEN. A native pack leaves the per-token
+ // loop at `if (native_pack) { spec_pos = pos; break; }` and never reaches this site, so a header
+ // written at open promised 64 or 66 rows for a file that would contain none - and a reader that
+ // trusted it reported "0 differing positions" from a file with no positions in it. Written here,
+ // a run that dumps nothing leaves an empty file, which is what actually happened.
+ if (emit_logits && !hdr_written && std::fwrite(hdr, sizeof hdr, 1, dump) != 1) {
+ std::fprintf(stderr, "strata generate: cannot write logits header\n");
+ std::fclose(dump);
+ return 1;
+ }
+ if (emit_logits) hdr_written = true;
if (emit_logits && std::fwrite(logits.data(), sizeof(float), (size_t) n_vocab, dump) != (size_t) n_vocab) {
std::fprintf(stderr, "strata generate: cannot write logits at position %lld\n", (long long) pos);
std::fclose(dump);