Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
63 lines
3.2 KiB
C++
63 lines
3.2 KiB
C++
// include/strata/spec/draft_source.hpp - a source of draft tokens beside the MTP layer (--lookup-chain).
|
|
//
|
|
// A source proposes how the context continues; the verify window checks the proposal, so a source can only change
|
|
// the speed, never the output. The engine asks its sources after the MTP has drafted: the context it passes ends
|
|
// with those MTP drafts (not yet verified), and whatever a source returns is appended to the same window.
|
|
//
|
|
// The built-in source is the request's own text (PromptLookupSource: the suffix drafter over prompt + output).
|
|
// Other sources (a retrieval store over a codebase or earlier conversations) register with
|
|
// extra_draft_sources() before the first request; the engine takes the proposal with the longest match.
|
|
#pragma once
|
|
|
|
#include "strata/spec/suffix_drafter.hpp"
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace strata::spec {
|
|
|
|
class DraftSource {
|
|
public:
|
|
virtual ~DraftSource() = default;
|
|
virtual const char* name() const = 0;
|
|
/// A new request starts (its prompt follows through append()).
|
|
virtual void reset() {}
|
|
/// Committed context, in order: the request's prompt, then every token the verify windows accept.
|
|
virtual void append(const int32_t* tokens, size_t n) { (void) tokens; (void) n; }
|
|
/// Propose up to `max_k` tokens that follow the context. `tail` holds the context's last `n_tail` tokens (at most
|
|
/// 64); its last `n_pending` are drafts not yet verified (never passed to append()). Writes `out`, returns how
|
|
/// many (0 = nothing to propose) and sets `*match` to the number of trailing context tokens the proposal is based
|
|
/// on (its confidence: the engine requires --lookup-chain-min and prefers the longest).
|
|
virtual int propose(const int32_t* tail, int n_tail, int n_pending, int max_k, int32_t* out, int* match) = 0;
|
|
};
|
|
|
|
/// The request's own text: the suffix drafter (prompt lookup) behind the DraftSource interface.
|
|
class PromptLookupSource final : public DraftSource {
|
|
public:
|
|
explicit PromptLookupSource(SuffixDrafter& d) : d_(d) {}
|
|
const char* name() const override { return "prompt-lookup"; }
|
|
void reset() override { d_.reset(); }
|
|
void append(const int32_t* tokens, size_t n) override { d_.append(tokens, n); }
|
|
int propose(const int32_t* tail, int n_tail, int n_pending, int max_k, int32_t* out, int* match) override {
|
|
n_pending = n_pending < n_tail ? n_pending : n_tail;
|
|
const int k = d_.propose_after(tail + (n_tail - n_pending), n_pending, max_k, out);
|
|
*match = k > 0 ? d_.last_match() : 0;
|
|
return k;
|
|
}
|
|
|
|
private:
|
|
SuffixDrafter& d_;
|
|
};
|
|
|
|
/// Sources besides the request's own text, asked after it (empty unless something registered one at startup).
|
|
std::vector<std::unique_ptr<DraftSource>>& extra_draft_sources();
|
|
|
|
/// Ask `own` and then every extra source; the proposal with the longest match of at least `min_match` wins
|
|
/// (ties keep the earlier source). Returns its length (0 = none); `*match` and `*source` (index: 0 = own) describe it.
|
|
int propose_from_sources(DraftSource& own, const int32_t* tail, int n_tail, int n_pending, int max_k, int min_match,
|
|
int32_t* out, int* match, int* source);
|
|
|
|
} // namespace strata::spec
|