Merge branch 'f-140' into f-140-j

This commit is contained in:
Niko1221 committed 2026-10-05 13:24:21 +02:00
commit 0fff115dfd
52 files changed
+3698 -183

No files matched your search

+16
View File
@@ -109,6 +109,22 @@ inline void dequantize_q5_0(const uint8_t* block, float* out) {
out[j + 16] = (float)(x1 - 16) * d;
}
}
// ---- Q5_1: 32 elements from a 24-byte block: fp16 d, fp16 m, then Q5_0's qh[4] and qs[16]. The 5-bit codes are
// unsigned and the block's minimum m is added instead of Q5_0's fixed -16 offset (dequantize_row_q5_1).
inline void dequantize_q5_1(const uint8_t* block, float* out) {
const float d = fp16_to_fp32(read_u16(block));
const float m = fp16_to_fp32(read_u16(block + 2));
const uint8_t* qh = block + 4;
const uint8_t* qs = block + 8;
const uint32_t h =
(uint32_t)qh[0] | ((uint32_t)qh[1] << 8) | ((uint32_t)qh[2] << 16) | ((uint32_t)qh[3] << 24);
for (int j = 0; j < 16; ++j) {
const int x0 = (int)(qs[j] & 0x0F) | (int)(((h >> j) & 1u) << 4);
const int x1 = (int)(qs[j] >> 4) | (int)(((h >> (j + 16)) & 1u) << 4);
out[j] = (float)x0 * d + m;
out[j + 16] = (float)x1 * d + m;
}
}
// ---- IQ4_NL: 32 elements from an 18-byte block. Non-linear 4-bit codebook, NOT a linear grid, so
// the table must be exact. Copied verbatim from ggml-common.h `kvalues_iq4nl` at 3cf03257:
// -127, -104, -83, -65, -49, -35, -22, -10, 1, 13, 25, 38, 53, 69, 89, 113
+37 -2
View File
@@ -46,7 +46,35 @@ inline constexpr float NG_RMS_EPS = 1e-6f;
inline constexpr uint64_t PLE_TABLE_ROWS = 320001536ull;
inline constexpr int PLE_ROW_BYTES = (PLE_HEAD_DIM / 32) * 18; // 90: an IQ4_NL row
inline constexpr int PLE_ROW_BYTES_FP8 = PLE_HEAD_DIM; // 160: an F8_E4M3 row, one byte a value
inline constexpr int PLE_ROW_BYTES_MAX = PLE_ROW_BYTES_FP8;
inline constexpr int PLE_ROW_BYTES_Q5_1 = (PLE_HEAD_DIM / 32) * 24; // 120: a Q5_1 row (a Q5_K_M finetune)
inline constexpr int PLE_ROW_BYTES_Q8_0 = (PLE_HEAD_DIM / 32) * 34; // 170: a Q8_0 row (UD-Q6_K_XL, Swift-1.5 Q4_K_L)
inline constexpr int PLE_ROW_BYTES_BF16 = PLE_HEAD_DIM * 2; // 320: a BF16 row, two bytes a value
inline constexpr int PLE_ROW_BYTES_MAX = PLE_ROW_BYTES_BF16; // the widest row any format in `ple_formats()` has
/// THE FORMATS OF THE TABLE, ONE ROW EACH. A table type is one entry here (its GGUF type name, the bytes of one
/// 160-value row, how to turn a row into floats) and nothing else: `PleTable::open`, `format()`, the reader's row size,
/// the error string and the buffers' size all read this list, so a new format cannot be in one switch and missing from
/// another. A row is always `PLE_HEAD_DIM` = 160 values = 5 blocks of 32 for the block formats.
enum class PleFormat : uint8_t { IQ4_NL, Q5_0, F8_E4M3, Q5_1, Q8_0, Q4_0, BF16 };
struct PleFormatInfo {
PleFormat id;
const char* name; ///< what `PleTable::format()` returns
const char* gguf_type; ///< `TensorInfo::type_name()` of the table tensor ("I8" for F8_E4M3: GGUF has no FP8 type)
uint32_t row_bytes; ///< bytes of one 160-value row in the file
bool needs_scale; ///< the table has one scale in the GGUF metadata (`strata.ple.scale`), F8_E4M3 only
void (*dequant)(const uint8_t* row, float scale, float* out160);
};
/// Every format, in the order of `PleFormat`; `ple_format_count()` entries.
const PleFormatInfo* ple_formats();
int ple_format_count();
const PleFormatInfo& ple_format_info(PleFormat f);
/// The format whose table tensor has this GGUF type name, or nullptr. F8_E4M3's name is "I8"; the caller checks the
/// `strata.ple.format` marker and the scale.
const PleFormatInfo* ple_format_for_type(const char* gguf_type_name);
/// "IQ4_NL, Q5_0 or FP8 (I8)": the formats for an error message, built from the list.
std::string ple_format_list();
/// The artifact's own hash constants, transcribed from `docs/gguf-dump-shard1.txt`:
///
@@ -103,6 +131,12 @@ void iq4nl_dequant_row(const uint8_t* row, float* out160);
/// `weight_scale`), kept byte for byte by tools/ple_fp8_pack.py; IQ4_NL is 8% off it per row.
void fp8_e4m3_dequant_row(const uint8_t* row, float scale, float* out160);
/// One BF16 row -> 160 floats, EXACTLY: bfloat16 is the top half of a float32, so this is a shift and a copy with no
/// rounding anywhere. It is the other published form of this same table - the full checkpoint stores
/// `...ngram_embedding.shard_k` as BF16 (2 B a value, 102.4 GB), the source of record rather than a re-quantization.
/// There is no scale, because BF16 values are the values.
void bf16_dequant_row(const uint8_t* row, float* out160);
/// How the table's rows are read (plan v0.3 P2). `Direct` is the default: unbuffered 4 KiB reads from the SSD,
/// so the table never occupies RAM or the OS file cache. `Mmap` is the earlier memory-mapped path, kept as the
/// A/B arm; it returns the same bytes.
@@ -115,7 +149,8 @@ enum class PleIo { Direct, Mmap };
struct PleIoOptions {
PleIo mode = PleIo::Direct;
uint32_t max_inflight = 256; ///< outstanding SSD reads (decode needs 16; a prompt chunk saturates the SSD at 256)
uint64_t cache_rows = 1u << 20; ///< bounded row cache: 1,048,576 rows x 90 B ~ 95 MB; 0 disables
uint64_t cache_rows = 1u << 20; ///< bounded row cache, in ROWS: 1,048,576 x 90 B ~ 95 MB (IQ4_NL), ~160 MB (FP8),
///< ~335 MB (BF16); 0 disables
bool io_thread = true; ///< reads submitted by a worker thread, not the caller
/// Mmap mode only (`--ple-io ram`): lock the whole mapped table in RAM at open, so no SSD read ever sits on
/// the prompt or token path. Needs RAM for the full table. POSIX only (mlock); `locked()` reports the outcome.