speculative_compat.cpp

src/inference/speculative_compat.cpp

@file speculative_compat.cpp @brief Implementation of the target/draft compatibility check.

Owners: @tvanfossen

build_compat_diagnostic

std::string entropic::speculative::anonymous_namespace{speculative_compat.cpp}::build_compat_diagnostic(const llama_model *target, const llama_model *draft)

Produce a diagnostic string for the target+draft pair, or empty on full success.

src/inference/speculative_compat.cpp:246

Show on the map →

Called by check_compat

Calls check_arch_gate, llama_model_get_vocab, run_vocab_checks

Source · 16 lines
std::string build_compat_diagnostic(
    const llama_model* target, const llama_model* draft) {
    std::string err;
    if (target == nullptr || draft == nullptr) {
        err = "null model handle (target or draft)";
    } else if (auto d = check_arch_gate(target); d.has_value()) {
        err = std::move(*d);
    } else {
        const llama_vocab* vt = llama_model_get_vocab(target);
        const llama_vocab* vd = llama_model_get_vocab(draft);
        err = (vt == nullptr || vd == nullptr)
                  ? std::string{"model vocab unavailable (target or draft)"}
                  : run_vocab_checks(vt, vd);
    }
    return err;
}
Activity · 11 steps
lines 248–248std::string err;lines 249–249◇ if (target == nullptr || draft == nullptr)lines 250–250err = "null model handle (target or draft)";lines 251–251elselines 251–251◇ if (auto d = check_arch_gate(target); d.has_value())lines 252–252err = std::move(*d);lines 253–253elselines 254–254const llama_vocab* vt = llama_model_get_vocab(target);lines 255–255const llama_vocab* vd = llama_model_get_vocab(draft);lines 256–258err = (vt == nullptr || vd == nullptr) ? std::string{"model vocab unavailable (target or draft)"} : run_vocab_checks(vt, vd);lines 260–260return err;

Requirements

REQ-INFER-016

check_arch_gate

std::optional< std::string > entropic::speculative::anonymous_namespace{speculative_compat.cpp}::check_arch_gate(const llama_model *target)

Refuse speculative pairing for recurrent OR hybrid target architectures.

src/inference/speculative_compat.cpp:59

Show on the map →

Called by build_compat_diagnostic

Calls llama_model_is_hybrid, llama_model_is_recurrent

Source · 18 lines
std::optional<std::string> check_arch_gate(
    const llama_model* target) {
    if (llama_model_is_recurrent(target)) {
        return std::string{
            "target model is recurrent (Mamba/RWKV) — speculative "
            "decoding is incompatible with recurrent architectures "
            "at the v2.1.11 llama.cpp pin"};
    }
    if (llama_model_is_hybrid(target)) {
        return std::string{
            "target model is hybrid (e.g., QWEN35/QWEN35MOE, "
            "NEMOTRON_H, JAMBA, GRANITE_HYBRID) — speculative "
            "decoding produces divergent state at split-prefill "
            "boundaries on hybrid SSM architectures at the v2.1.11 "
            "llama.cpp pin (see proposal Implementation Log, Gate A)"};
    }
    return std::nullopt;
}
Activity · 5 steps
lines 61–61◇ if (llama_model_is_recurrent(target))lines 62–65return std::string{ "target model is recurrent (Mamba/RWKV) — speculative " "decoding is incompatible with recurrent architectures " "at the v2.1.11 llama.cpp pin"};lines 67–67◇ if (llama_model_is_hybrid(target))lines 68–73return std::string{ "target model is hybrid (e.g., QWEN35/QWEN35MOE, " "NEMOTRON_H, JAMBA, GRANITE_HYBRID) — speculative " "decoding produces divergent state at split-prefill " "boundaries on hybrid SSM architectures at the v2.1.11 " "llama.cpp pin (see proposal Implementation Log, Gate A)"};lines 75–75return std::nullopt;

Requirements

REQ-INFER-016

check_compat

CompatResult entropic::speculative::check_compat(const llama_model *target, const llama_model *draft)

Check whether a draft model can pair with a target for sequential speculative decoding.

src/inference/speculative_compat.cpp:279

Show on the map →

Called by TEST_CASE, check_speculative_compat

Calls build_compat_diagnostic

Source · 5 lines
CompatResult check_compat(
    const llama_model* target, const llama_model* draft) {
    std::string err = build_compat_diagnostic(target, draft);
    return CompatResult{err.empty(), std::move(err)};
}
Activity · 2 steps
lines 281–281std::string err = build_compat_diagnostic(target, draft);lines 282–282return CompatResult{err.empty(), std::move(err)};

Requirements

REQ-INFER-016