PLE table: STRATA_PLE_CHECK=1 names the first row that decodes to an implausible value and says whether the delivered bytes are the file's (#3602)
The report asks for the first data mismatch between the GGUF row bytes and what the direct reader delivered, and for an early check of the gathered values; neither exists. Its trace stops at "the embedding has 96 non-finite values" without saying whether the reader gave a wrong row or the table holds one. With STRATA_PLE_CHECK=1 (a tester switch, off by default; one static flag read per gather call when off) every direct-mode decode (read_row, collect, gather_batch, also from the prefetched slots) checks the row's 160 values. For a value that is not finite or beyond 1e5 (an IQ4_NL row cannot decode beyond 8.3e6; real PLE values are orders smaller) it re-reads that row from the file with a buffered read and prints one line to stderr (at most 8 per table): the row, its file offset and page offset, the value, and either "the delivered bytes ARE the file's bytes" or "THE DELIVERED BYTES DIFFER FROM THE FILE from byte N" with the first 8 bytes of each. That separates a reader fault (the bug) from a damaged table. gates/3602-ple-direct.sh sets it in its direct arms. Checked: ple_reader_test --selftest on z440 with the switch on prints the "ARE the file's bytes" line for the synthetic table's random rows (which decode to huge values); with it off the output and the bytes are unchanged (ple_reader_selftest passes). Not checked: the "DIFFER" branch has no natural trigger (that is the point); it was read, not run.
This commit is contained in:
1 parent
7d1016f3f4
commit
8dd297d0f1
1 file changed
+65
-1
+65
-1
@@ -11,7 +11,9 @@
|
||||
#include <cerrno>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/mman.h>
|
||||
@@ -243,6 +245,55 @@ struct PleTable::Impl {
|
||||
float scale = 1.0f; // the FP8 table's one scale
|
||||
uint32_t rb = PLE_ROW_BYTES; // bytes per row
|
||||
void decode(const uint8_t* row, float* out160) const { fmt->dequant(row, scale, out160); }
|
||||
// STRATA_PLE_CHECK=1 (a diagnostic for #3602, off by default): the file and the table's offset, to re-read a row whose decoded
|
||||
// values are not plausible and compare the bytes the direct reader delivered with the file's own
|
||||
std::string path;
|
||||
uint64_t table_offset = 0;
|
||||
mutable int check_reports = 0;
|
||||
static bool check_on() {
|
||||
static const bool on = [] { const char* v = std::getenv("STRATA_PLE_CHECK"); return v != nullptr && std::atoi(v) != 0; }();
|
||||
return on;
|
||||
}
|
||||
/// One decoded row (`out160`, from `raw`): when a value is not finite or beyond 1e5 (a real PLE value is orders smaller; the
|
||||
/// largest an IQ4_NL row can decode to is 8.3e6), say which row, where, and whether the delivered bytes are the file's.
|
||||
void check_row(const char* where, uint32_t row, const uint8_t* raw, const float* out160) const {
|
||||
if (check_reports >= 8 || row >= n_rows) return;
|
||||
int bad = -1;
|
||||
for (int j = 0; j < PLE_HEAD_DIM; ++j)
|
||||
if (!std::isfinite(out160[j]) || std::fabs(out160[j]) > 1e5f) { bad = j; break; }
|
||||
if (bad < 0) return;
|
||||
++check_reports;
|
||||
const uint64_t at = table_offset + (uint64_t) row * rb;
|
||||
std::vector<uint8_t> file(rb, 0);
|
||||
bool read = false;
|
||||
{
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (f) {
|
||||
f.seekg((std::streamoff) at);
|
||||
f.read((char*) file.data(), (std::streamsize) rb);
|
||||
read = (uint32_t) f.gcount() == rb;
|
||||
}
|
||||
}
|
||||
std::fprintf(stderr, "strata ple check: %s: row %u (file offset %llu, page offset %llu): value %d of 160 decodes to %g", where,
|
||||
row, (unsigned long long) at, (unsigned long long) (at % 4096), bad, (double) out160[bad]);
|
||||
if (!read) {
|
||||
std::fprintf(stderr, "; the file could not be re-read\n");
|
||||
return;
|
||||
}
|
||||
uint32_t first = rb;
|
||||
for (uint32_t b = 0; b < rb; ++b)
|
||||
if (raw[b] != file[b]) { first = b; break; }
|
||||
if (first == rb) {
|
||||
std::fprintf(stderr, "; the delivered bytes ARE the file's bytes (the table itself holds this value)\n");
|
||||
} else {
|
||||
std::fprintf(stderr, "; THE DELIVERED BYTES DIFFER FROM THE FILE from byte %u (delivered 0x%02x, file 0x%02x); first 8 delivered:", first,
|
||||
raw[first], file[first]);
|
||||
for (int b = 0; b < 8 && (uint32_t) b < rb; ++b) std::fprintf(stderr, " %02x", raw[b]);
|
||||
std::fprintf(stderr, "; first 8 of the file:");
|
||||
for (int b = 0; b < 8 && (uint32_t) b < rb; ++b) std::fprintf(stderr, " %02x", file[b]);
|
||||
std::fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
PleTable::PleTable() : impl_(new Impl) {}
|
||||
@@ -342,6 +393,8 @@ bool PleTable::open(const std::string& gguf_path, std::string& err, const PleIoO
|
||||
// the table can enter this process's working set or the file cache through it.
|
||||
const uint64_t table_offset = impl_->file->data_start() + t->offset;
|
||||
const uint64_t n_rows = impl_->n_rows;
|
||||
impl_->path = gguf_path;
|
||||
impl_->table_offset = table_offset;
|
||||
delete impl_->file;
|
||||
impl_->file = nullptr;
|
||||
impl_->data = nullptr;
|
||||
@@ -483,6 +536,7 @@ void PleTable::read_row(uint32_t row, float* out160) const {
|
||||
return;
|
||||
}
|
||||
impl_->decode(raw, out160);
|
||||
if (Impl::check_on()) impl_->check_row("read_row", row, raw, out160);
|
||||
impl_->bytes_read += impl_->rb;
|
||||
return;
|
||||
}
|
||||
@@ -529,6 +583,9 @@ bool PleTable::collect(float* out2560, std::string& err) {
|
||||
if (!impl_->reader.collect(impl_->ticket, err)) return false;
|
||||
for (int h = 0; h < PLE_N_HEADS; ++h)
|
||||
impl_->decode(impl_->raw + (size_t) h * impl_->rb, out2560 + (size_t) h * PLE_HEAD_DIM);
|
||||
if (Impl::check_on())
|
||||
for (int h = 0; h < PLE_N_HEADS; ++h)
|
||||
impl_->check_row("collect", impl_->rows[h], impl_->raw + (size_t) h * impl_->rb, out2560 + (size_t) h * PLE_HEAD_DIM);
|
||||
impl_->bytes_read += (uint64_t) PLE_N_HEADS * impl_->rb;
|
||||
return true;
|
||||
}
|
||||
@@ -567,6 +624,10 @@ bool PleTable::gather_batch(const uint32_t* rows, size_t n_tokens, float* out, s
|
||||
for (int h = 0; h < PLE_N_HEADS; ++h) {
|
||||
impl_->decode(impl_->prefetch_raw[matched[t]] + (size_t) h * impl_->rb,
|
||||
out + (t * PLE_N_HEADS + (size_t) h) * PLE_HEAD_DIM);
|
||||
if (Impl::check_on())
|
||||
impl_->check_row("gather_batch (prefetched)", rows[t * PLE_N_HEADS + (size_t) h],
|
||||
impl_->prefetch_raw[matched[t]] + (size_t) h * impl_->rb,
|
||||
out + (t * PLE_N_HEADS + (size_t) h) * PLE_HEAD_DIM);
|
||||
}
|
||||
}
|
||||
impl_->bytes_read += (uint64_t) n * impl_->rb;
|
||||
@@ -577,7 +638,10 @@ bool PleTable::gather_batch(const uint32_t* rows, size_t n_tokens, float* out, s
|
||||
std::vector<uint8_t> raw(n * impl_->rb);
|
||||
const auto ticket = impl_->reader.issue(rows, n, raw.data());
|
||||
if (!impl_->reader.collect(ticket, err)) return false;
|
||||
for (size_t i = 0; i < n; ++i) impl_->decode(raw.data() + i * impl_->rb, out + i * PLE_HEAD_DIM);
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
impl_->decode(raw.data() + i * impl_->rb, out + i * PLE_HEAD_DIM);
|
||||
if (Impl::check_on()) impl_->check_row("gather_batch", rows[i], raw.data() + i * impl_->rb, out + i * PLE_HEAD_DIM);
|
||||
}
|
||||
impl_->bytes_read += (uint64_t) n * impl_->rb;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user