Archived
radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves every shipped container - Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime - /v1/messages works with Claude Code as it ships (gearwave00001) - a long agent conversation keeps its cached history when the client rewrites its last turn (manueloverride) - a stream's first event goes out with the first token, so llama-benchy measures prefill right - opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42) - four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b) - NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA adapters (baKon) - many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool arguments and the CPU's vision and audio encoders - plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
1 parent
b068190326
commit
1e968f6e1d
739 files changed
+128447
-84632
No files matched your search
+27
-37
@@ -1,18 +1,15 @@
|
||||
/* gguf.h -- a reader for the GGUF container, and nothing else.
|
||||
/* gguf.h -- a reader for the GGUF container.
|
||||
*
|
||||
* spec §12 lists `ggml/src/gguf.cpp` as a lift, but that file is a reader, a writer and a
|
||||
* ggml_context builder welded together: it fills `struct ggml_tensor`, calls `ggml_blck_size`,
|
||||
* and pulls in `ggml.h` for both. Taking it whole would mean taking ggml, which §12 says
|
||||
* explicitly we do not. So the reader is rewritten here under our own name -- the wire format is
|
||||
* a header, a KV table, a tensor directory and a padded blob, and that is a page of code -- and
|
||||
* `vendor/UPSTREAM` records the file it was read from rather than copied from.
|
||||
* A rewrite of `ggml/src/gguf.cpp` (spec §12), not a lift: that file is also a writer and a
|
||||
* ggml_context builder (it fills `struct ggml_tensor` and needs `ggml.h`), and §12 excludes ggml.
|
||||
* The format is a header, a KV table, a tensor directory and a padded data blob. `vendor/UPSTREAM`
|
||||
* records the file it was written against.
|
||||
*
|
||||
* What we keep from upstream is the one thing that is genuinely data rather than code: the block
|
||||
* geometry of every ggml dtype, without which a tensor's byte size cannot be computed. That table
|
||||
* is transcribed from `ggml_blck_size`/`ggml_type_size` and is marked as such below.
|
||||
* The only thing taken from upstream is data: the block geometry of every ggml dtype, needed to
|
||||
* compute a tensor's byte size (GgufDtype).
|
||||
*
|
||||
* The file is mmapped whole and never copied. rad-convert walks the directory, reads what it
|
||||
* wants through `tensor_data()`, and writes the .rad; nothing here interprets tensor CONTENT.
|
||||
* The file is mmapped whole and never copied. rad-convert walks the directory, reads tensors
|
||||
* through `tensor_data()` and writes the .rad; nothing here interprets tensor content.
|
||||
*/
|
||||
#pragma once
|
||||
#include "rad_internal.h"
|
||||
@@ -24,34 +21,29 @@
|
||||
|
||||
namespace rad {
|
||||
|
||||
/* GGUF's own value type numbering. These are wire values -- fixed by the format, not by us. */
|
||||
/* GGUF's value type numbering (wire values, fixed by the format). */
|
||||
enum GgufType {
|
||||
GGUF_U8 = 0, GGUF_I8 = 1, GGUF_U16 = 2, GGUF_I16 = 3, GGUF_U32 = 4, GGUF_I32 = 5,
|
||||
GGUF_F32 = 6, GGUF_BOOL = 7, GGUF_STR = 8, GGUF_ARR = 9, GGUF_U64 = 10,
|
||||
GGUF_I64 = 11, GGUF_F64 = 12
|
||||
};
|
||||
|
||||
/* One metadata entry.
|
||||
*
|
||||
* A scalar is stored as a one-element vector, so a caller reading `tokenizer.ggml.tokens` and a
|
||||
* caller reading `general.name` write the same code and neither branches on `is_array`. The cost
|
||||
* is one heap allocation per scalar KV at open, against a KV table that is a few hundred rows;
|
||||
* the benefit is that the every-caller path has no special case in it, and a special case in a
|
||||
* metadata reader is where a truncated vocab comes from. */
|
||||
/* One metadata entry. A scalar is stored as a one-element vector, so callers read scalars and
|
||||
* arrays the same way without branching on `is_array`. */
|
||||
struct GgufKV {
|
||||
std::string key;
|
||||
uint32_t type = GGUF_U8; /* for an array, the ELEMENT type; GGUF_ARR never appears here */
|
||||
uint32_t type = GGUF_U8; /* for an array, the element type; never GGUF_ARR */
|
||||
bool is_array = false;
|
||||
|
||||
/* Populated according to `type`: integers and bools widen into `i`, floats into `f`,
|
||||
* strings into `s`. The other two stay empty. */
|
||||
/* By `type`: integers and bools widen into `i`, floats into `f`, strings into `s`. The
|
||||
* other two stay empty. */
|
||||
std::vector<int64_t> i;
|
||||
std::vector<double> f;
|
||||
std::vector<std::string> s;
|
||||
};
|
||||
|
||||
/* One tensor directory row. `offset` is from the start of the data section, which is where GGUF
|
||||
* puts it; `data_off() + offset` is the file offset, and `tensor_data()` does that arithmetic. */
|
||||
/* One tensor directory row. `offset` is relative to the data section; the file offset is
|
||||
* `data_off() + offset` (see `tensor_data()`). */
|
||||
struct GgufTensor {
|
||||
std::string name;
|
||||
uint32_t ggml_type = 0;
|
||||
@@ -61,9 +53,9 @@ struct GgufTensor {
|
||||
uint64_t bytes = 0; /* computed from ne and the block geometry */
|
||||
};
|
||||
|
||||
/* Block geometry for a ggml dtype. Transcribed from ggml.c's `type_traits` at llama.cpp
|
||||
* 06938ac12 -- see vendor/UPSTREAM. `blck` of 0 marks a removed or unknown type, and a tensor
|
||||
* carrying one is refused at open rather than silently mis-sized. */
|
||||
/* Block geometry for a ggml dtype, transcribed from ggml.c's `type_traits` at llama.cpp
|
||||
* 06938ac12 (vendor/UPSTREAM). `blck` 0 marks a removed or unknown type; open() refuses a tensor
|
||||
* of that type rather than mis-size it. */
|
||||
struct GgufDtype {
|
||||
int blck; /* logical elements per stored block */
|
||||
size_t block_bytes; /* bytes per stored block */
|
||||
@@ -71,9 +63,8 @@ struct GgufDtype {
|
||||
};
|
||||
const GgufDtype* gguf_dtype(uint32_t ggml_type); /* null if out of range */
|
||||
|
||||
/* Map a ggml dtype onto RAD_* where the two agree exactly. Returns RAD_DT_INVALID for the
|
||||
* k-quants and the iq-quants: those have no RAD_* equivalent, and rad-convert has to dequantise
|
||||
* or refuse rather than reinterpret the bytes. */
|
||||
/* Map a ggml dtype onto RAD_* where the bytes agree exactly. RAD_DT_INVALID for block-quantised
|
||||
* types (k-quants, iq-quants), which rad-convert must dequantise or refuse, never reinterpret. */
|
||||
uint32_t gguf_to_rad_dtype(uint32_t ggml_type);
|
||||
|
||||
class GgufFile {
|
||||
@@ -83,8 +74,8 @@ public:
|
||||
GgufFile(const GgufFile&) = delete;
|
||||
GgufFile& operator=(const GgufFile&) = delete;
|
||||
|
||||
/* RAD_OK, or a negative RAD_E_*: RAD_E_IO if the file will not open or map,
|
||||
* RAD_E_FORMAT if the magic, version, or directory does not hold together. */
|
||||
/* RAD_OK, RAD_E_IO if the file will not open or map, or RAD_E_FORMAT if the magic, version
|
||||
* or directory is invalid. */
|
||||
int open(const char* path);
|
||||
void close();
|
||||
bool is_open() const { return base_ != nullptr; }
|
||||
@@ -103,8 +94,7 @@ public:
|
||||
const GgufTensor* tensor(std::string_view name) const;
|
||||
|
||||
/* Typed reads. Each returns false and leaves *out untouched when the key is absent or holds
|
||||
* the wrong shape of value -- absence and a type mismatch are the same thing to a caller that
|
||||
* has a default, and the ones that do not have a default check the return. */
|
||||
* the wrong kind of value; a caller with a default treats both the same. */
|
||||
bool get_i64(std::string_view key, int64_t* out) const;
|
||||
bool get_f64(std::string_view key, double* out) const;
|
||||
bool get_str(std::string_view key, std::string* out) const;
|
||||
@@ -112,8 +102,8 @@ public:
|
||||
bool get_i64s(std::string_view key, std::vector<int64_t>* out) const;
|
||||
bool get_f32s(std::string_view key, std::vector<float>* out) const;
|
||||
|
||||
/* A pointer into the mmap. Null if the tensor's extent leaves the file, which is a corrupt
|
||||
* container rather than a caller error -- open() already refused those, so this is belt. */
|
||||
/* A pointer into the mmap, or null if the tensor's extent leaves the file (a corrupt
|
||||
* container, which open() already refuses). */
|
||||
const void* tensor_data(const GgufTensor& t) const;
|
||||
|
||||
private:
|
||||
|
||||
Reference in new issue
Block a user