Archived
DeepEncoder (arch/common/rad_block_sam.h): the checkpoint's SAM ViT-B/16, neck and CLIP ViT-L/14 producing its 16x17+1 row layout, with a new `sam_attn` op for the windowed, zero-padded SAM attention and its decomposed relative-position bias (libref oracle, libavx kernel, libr4d kernel and selftest). The plugin declares the tower when the container records `radiance.encoder`, and splices its rows over the placeholders after embed_lookup. BOS: the chat path adds BOS when the rendered template does not already start with it. This checkpoint's template is a bare concatenation and its tokenizer states add_bos_token, so without it every position was off by one and the det boxes came out wrong. A media run's placeholders shift with it. R-SWA: RAD_KV_RING, paged like a window group but with a per-sequence floor armed at admission. adv_groups now computes the same clamped seqused and modulo ring slots the builder stages; the mismatch read the block table's -1 padding and faulted the card. Prefill stays causal; prefix cache, checkpoints and speculation are off for the group. Sampling: sample_ngram_ban in libref/libavx/libr4d and the host chain, the request knobs, and the container's generation config (35 over 128). Processor: the checkpoint's grid/mode selection, its tall-last tie order, Pillow's bicubic pass order, and goldens generated from its own code. Tools: --mm-max-patches auto-detection accepts a tower stated as per-width tables under vision_config.image_size, and rad-convert records radiance.encoder. Verified: tower stages match the checkpoint's code (rows cos 0.9998), the device sam_attn selftest is within tolerance, the R-SWA device repro returns text, a GPU e2e reproduces the reference's first det block, and the host suite is 88/89 (known webp decode baseline).
69 lines
3.5 KiB
C++
69 lines
3.5 KiB
C++
/* gen_config.h -- the sampling a checkpoint states for itself (generation_config.json), read in
|
|
* its three forms: a file named on the command line, a sidecar beside the container, and the
|
|
* `generation.*` metadata rad-convert flattened into the container.
|
|
*
|
|
* These values set what a request sending no sampler fields gets. Without them SamplingParams'
|
|
* defaults sample the whole vocabulary at temperature 1, and a model tuned with a truncated tail
|
|
* occasionally draws end-of-turn early: replies stop short, and agent turns arrive with text and
|
|
* no tool call. A separate component so this can be tested.
|
|
*
|
|
* Nothing here refuses: values come with the model, so an out-of-range field is warned about and
|
|
* dropped. Command-line overrides are checked in core/config.cpp.
|
|
*/
|
|
#pragma once
|
|
#include "rad_core.h"
|
|
|
|
#include <functional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace rad {
|
|
|
|
/* One config's sampler fields. -1 means "not stated", since 0 is a legal value of each (greedy
|
|
* temperature, top_k off, min_p off, n-gram ban off). */
|
|
struct GenSampling {
|
|
float temp = -1.0f, top_p = -1.0f, min_p = -1.0f;
|
|
int top_k = -1;
|
|
/* The windowed no-repeat-n-gram ban (transformers' no_repeat_ngram_size /
|
|
* no_repeat_ngram_window_size; Unlimited-OCR ships 35 over the last 128). `ngram_window` is
|
|
* normalized to 0, this sampler's "the whole sequence", when the config states it negative. */
|
|
int ngram_ban_n = -1, ngram_window = -1;
|
|
|
|
bool any() const {
|
|
return temp >= 0.0f || top_p >= 0.0f || min_p >= 0.0f || top_k >= 0 ||
|
|
ngram_ban_n >= 0 || ngram_window >= 0;
|
|
}
|
|
|
|
/* Overlay onto `base` field by field; unstated fields keep base's, so sources stack. */
|
|
SamplingParams onto(SamplingParams base) const;
|
|
|
|
/* "temperature 0.70, top_k 20 (off), top_p 0.95, min_p 0.00, ngram ban n 35 over the last 128
|
|
* tokens", for the startup log line (the last part only when a ban is on). */
|
|
static std::string describe(const SamplingParams& sp);
|
|
};
|
|
|
|
/* Where each of the four served fields came from, for the startup report (core/diag/diag.h): one
|
|
* entry per field no flag set, with its option, the served value and why. `stated` is what the
|
|
* source in force read and `src` its name ("" for none). Reasons are per field, since a source may
|
|
* state only some fields and the rest take SamplingParams' defaults. */
|
|
struct GenFieldSource { std::string flag, value, why; };
|
|
std::vector<GenFieldSource> gen_sampling_sources(const GenSampling& stated, const std::string& src,
|
|
const SamplingParams& served, const Config& cfg);
|
|
|
|
/* Parse the sampler fields from generation_config.json text. `src` names the origin in warnings.
|
|
* Returns whether anything was taken; unparseable text warns and takes nothing. */
|
|
bool gen_sampling_parse(const std::string& json_text, const char* src, GenSampling* out);
|
|
|
|
/* The same from a file. Absent is not an error unless `required`. */
|
|
bool gen_sampling_from_file(const std::string& path, bool required, GenSampling* out);
|
|
|
|
/* The same from the container's `generation.*` metadata (string values). `get` takes a bare field
|
|
* name ("top_k") and returns null when absent. */
|
|
bool gen_sampling_from_kv(const std::function<const char*(const char*)>& get, GenSampling* out);
|
|
|
|
/* `<model>.rad` -> `<model>.generation.json`: a sidecar that supplies or corrects a container's
|
|
* sampling without reconverting it. */
|
|
std::string gen_sidecar_path(const std::string& model_path);
|
|
|
|
} /* namespace rad */
|