Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"index":0,"content":" four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty.","tokens":[],"id_slot":1,"stop":true,"model":"eliza-1-2b-128k.gguf","tokens_predicted":35,"tokens_evaluated":16,"generation_settings":{"seed":4294967295,"temperature":0.0,"dynatemp_range":0.0,"dynatemp_exponent":1.0,"top_k":64,"top_p":0.949999988079071,"min_p":0.05000000074505806,"top_n_sigma":-1.0,"xtc_probability":0.0,"xtc_threshold":0.10000000149011612,"typical_p":1.0,"repeat_last_n":64,"repeat_penalty":1.0,"presence_penalty":0.0,"frequency_penalty":0.0,"dry_multiplier":0.0,"dry_base":1.75,"dry_allowed_length":2,"dry_penalty_last_n":8192,"dry_sequence_breakers":["\n",":","\"","*"],"repeat_line_window":0,"repeat_line_min_length":20,"repeat_line_delimiters":"\n.!?:","repeat_line_temp_boost":0.5,"mirostat":0,"mirostat_tau":5.0,"mirostat_eta":0.10000000149011612,"stop":[],"max_tokens":96,"n_predict":96,"n_keep":0,"n_discard":0,"ignore_eos":false,"stream":false,"logit_bias":[],"n_probs":0,"min_keep":0,"grammar":"","grammar_lazy":false,"grammar_triggers":[],"preserved_tokens":[],"chat_format":"Content-only","reasoning_format":"deepseek","reasoning_in_content":false,"generation_prompt":"","samplers":["penalties","dry","top_n_sigma","top_k","typ_p","top_p","min_p","xtc","temperature"],"speculative.types":"none,draft-mtp","timings_per_token":false,"post_sampling_probs":false,"backend_sampling":false,"lora":[]},"prompt":"<bos>Count from one to twenty in English words: one, two, three,","has_new_line":false,"truncated":false,"stop_type":"eos","stopping_word":"","tokens_cached":50,"timings":{"cache_n":15,"prompt_n":1,"prompt_ms":21.344,"prompt_per_token_ms":21.344,"prompt_per_second":46.85157421289355,"predicted_n":35,"predicted_ms":416.185,"predicted_per_token_ms":11.891,"predicted_per_second":84.09721638213774,"draft_n":72,"draft_n_accepted":16}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
gemma4-assistant E2B drafter (f16, converted from google/gemma-4-E2B-it-assistant)
target: /tmp/vision/gemma4/bundles/2b/text/eliza-1-2b-128k.gguf (eliza-1-2b, gemma4, n_embd 1536, Q8)
host: Apple M4 Max, Metal, llama-server (fork build-desktop-metal), greedy (temperature 0), n_predict 96, --cache-ram 0

baseline (no drafter):
counting-to-twenty : predicted_n=35 tok/s= 96.00
quick-brown-fox : predicted_n= 3 tok/s=143.44
weekdays : predicted_n=11 tok/s=103.99

-md drafter --spec-type draft-mtp --spec-draft-n-max 1 (catalog shipped window):
counting-to-twenty : predicted_n=35 tok/s=167.16 draft_n=18 accepted=16 (1.74x, 89%)
quick-brown-fox : predicted_n= 3 tok/s=200.51 draft_n= 1 accepted= 1 (1.40x, 100%)
weekdays : predicted_n=11 tok/s=150.11 draft_n= 6 accepted= 4 (1.44x, 67%)

aggregate acceptance: 21/25 = 0.84 ; mean speedup ~1.53x
(--spec-draft-n-max 4 run: draft_n=80 accepted=14 on counting; per-step server log lines
"accepted 1/4 draft tokens" in speculative-decode-server.log)
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
GGUF.version = 3
GGUF.tensor_count = 49
GGUF.kv_count = 42
general.architecture = gemma4-assistant
general.type = model
general.sampling.top_k = 64
general.sampling.top_p = 0.949999988079071
general.sampling.temp = 1.0
general.name = Model
general.size_label = 77M
gemma4-assistant.block_count = 4
gemma4-assistant.context_length = 131072
gemma4-assistant.embedding_length = 256
gemma4-assistant.feed_forward_length = 2048
gemma4-assistant.attention.head_count = 4
gemma4-assistant.attention.head_count_kv = 1
gemma4-assistant.rope.freq_base = 1000000.0
gemma4-assistant.rope.freq_base_swa = 10000.0
gemma4-assistant.attention.layer_norm_rms_epsilon = 9.999999974752427e-07
gemma4-assistant.attention.key_length = 512
gemma4-assistant.attention.value_length = 512
general.file_type = 1
gemma4-assistant.attention.sliding_window = 512
gemma4-assistant.attention.shared_kv_layers = 4
gemma4-assistant.embedding_length_per_layer_input = 0
gemma4-assistant.attention.sliding_window_pattern = [True, True, True, False]
gemma4-assistant.attention.key_length_swa = 256
gemma4-assistant.attention.value_length_swa = 256
gemma4-assistant.rope.dimension_count = 512
gemma4-assistant.rope.dimension_count_swa = 256
gemma4-assistant.embedding_length_out = 1536
gemma4-assistant.nextn_predict_layers = 1
general.quantization_version = 2
tokenizer.ggml.model = gemma4
tokenizer.ggml.bos_token_id = 2
tokenizer.ggml.eos_token_id = 1
tokenizer.ggml.unknown_token_id = 3
tokenizer.ggml.padding_token_id = 0
tokenizer.ggml.mask_token_id = 4
--- tensors ---
rope_freqs.weight [np.uint64(256)] F32
token_embd.weight [np.uint64(256), np.uint64(262144)] F16
blk.0.attn_norm.weight [np.uint64(256)] F32
blk.0.layer_output_scale.weight [np.uint64(1)] F32
blk.0.ffn_down.weight [np.uint64(2048), np.uint64(256)] F16
blk.0.ffn_gate.weight [np.uint64(256), np.uint64(2048)] F16
blk.0.ffn_up.weight [np.uint64(256), np.uint64(2048)] F16
blk.0.post_attention_norm.weight [np.uint64(256)] F32
blk.0.post_ffw_norm.weight [np.uint64(256)] F32
blk.0.ffn_norm.weight [np.uint64(256)] F32
blk.0.attn_output.weight [np.uint64(1024), np.uint64(256)] F16
blk.0.attn_q_norm.weight [np.uint64(256)] F32
blk.0.attn_q.weight [np.uint64(256), np.uint64(1024)] F16
blk.1.attn_norm.weight [np.uint64(256)] F32
blk.1.layer_output_scale.weight [np.uint64(1)] F32
blk.1.ffn_down.weight [np.uint64(2048), np.uint64(256)] F16
blk.1.ffn_gate.weight [np.uint64(256), np.uint64(2048)] F16
blk.1.ffn_up.weight [np.uint64(256), np.uint64(2048)] F16
blk.1.post_attention_norm.weight [np.uint64(256)] F32
blk.1.post_ffw_norm.weight [np.uint64(256)] F32
blk.1.ffn_norm.weight [np.uint64(256)] F32
blk.1.attn_output.weight [np.uint64(1024), np.uint64(256)] F16
blk.1.attn_q_norm.weight [np.uint64(256)] F32
blk.1.attn_q.weight [np.uint64(256), np.uint64(1024)] F16
blk.2.attn_norm.weight [np.uint64(256)] F32
blk.2.layer_output_scale.weight [np.uint64(1)] F32
blk.2.ffn_down.weight [np.uint64(2048), np.uint64(256)] F16
blk.2.ffn_gate.weight [np.uint64(256), np.uint64(2048)] F16
blk.2.ffn_up.weight [np.uint64(256), np.uint64(2048)] F16
blk.2.post_attention_norm.weight [np.uint64(256)] F32
blk.2.post_ffw_norm.weight [np.uint64(256)] F32
blk.2.ffn_norm.weight [np.uint64(256)] F32
blk.2.attn_output.weight [np.uint64(1024), np.uint64(256)] F16
blk.2.attn_q_norm.weight [np.uint64(256)] F32
blk.2.attn_q.weight [np.uint64(256), np.uint64(1024)] F16
blk.3.attn_norm.weight [np.uint64(256)] F32
blk.3.layer_output_scale.weight [np.uint64(1)] F32
blk.3.ffn_down.weight [np.uint64(2048), np.uint64(256)] F16
blk.3.ffn_gate.weight [np.uint64(256), np.uint64(2048)] F16
blk.3.ffn_up.weight [np.uint64(256), np.uint64(2048)] F16
blk.3.post_attention_norm.weight [np.uint64(256)] F32
blk.3.post_ffw_norm.weight [np.uint64(256)] F32
blk.3.ffn_norm.weight [np.uint64(256)] F32
blk.3.attn_output.weight [np.uint64(2048), np.uint64(256)] F16
blk.3.attn_q_norm.weight [np.uint64(512)] F32
blk.3.attn_q.weight [np.uint64(256), np.uint64(2048)] F16
output_norm.weight [np.uint64(256)] F32
nextn.post_projection.weight [np.uint64(256), np.uint64(1536)] F16
nextn.pre_projection.weight [np.uint64(3072), np.uint64(256)] F16
46 changes: 46 additions & 0 deletions .github/issue-evidence/gemma4-assistant-mtp/fused-ffi-bench.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
gemma4-assistant E2B drafter — FUSED PRODUCT-PATH proof (libelizainference.dylib, ABI v9)
==========================================================================================
This is the desktop product path — NOT llama-server. The harness
(fused-ffi-harness.ts) drives the plugin's own bun:ffi binding
(src/services/voice/ffi-bindings.ts loadElizaInferenceFfi) against the
freshly rebuilt build-desktop-metal/bin/libelizainference.dylib:
eliza_inference_llm_stream_open with mtp_drafter_path set -> the fused
separate-drafter DRAFT_MTP engine (LLAMA_CONTEXT_TYPE_MTP draft context,
ctx_other = target context, shared KV / target tok_embd).

host : Apple M4 Max, Metal, bun, greedy (temperature 0), maxTokens 96, ctx 4096
target : /tmp/vision/gemma4/bundles/2b/text/eliza-1-2b-128k.gguf (gemma4, n_embd 1536)
drafter : /tmp/mtp/bundles/2b/mtp/drafter-2b.gguf (gemma4-assistant, 49 tensors,
block_count 4, embedding_length 256 -> out 1536)
window : draftMin=1 draftMax=1 (the shipped catalog window)

capability probes: llmStreamSupported=true llmMtpSupported=true tokenizeSupported=true
drafter load : clean — no tensor/KV mismatch; "common_speculative_init: adding
speculative implementation 'draft-mtp'"; set_embeddings_pre_norm=1

prompt baseline MTP drafted accepted acceptance
counting-to-twenty 78-88 tok/s 96-106 tok/s 27 22 0.815
weekdays 75-77 tok/s 86-93 tok/s 11 10 0.909
------ ------ -----
TOTAL 38 32 0.842
speedup ~1.15-1.23x wall (prefill+decode) at draftMax=1; matches the
llama-server measurement (0.84 acceptance) in draft-acceptance-bench.txt.

output coherence: both MTP outputs coherent. weekdays output is byte-identical
to the greedy baseline across repeated runs.

HONEST FLAG — deterministic one-token tie-flip on counting-to-twenty:
the MTP run emits "... Fifteen, Sixteen,, Eighteen ..." (skips "Seventeen",
n=48 vs 49). Reproduced identically across 2 runs. All tokens after the flip
match the baseline exactly, so draft-rollback/KV retraction is correct; this
is the target's own batched-verify logits (n_tokens=2 Metal kernels) flipping
a near-tie argmax vs single-token decode — a known speculative-decode numerics
artifact, not a drafter tensor/KV mapping defect (a mapping defect produces
garbage + near-zero acceptance, not 84% acceptance with clean continuation).

teardown: streams + ctx close cleanly ("[harness] clean shutdown"); a known
GGML Metal residency-set assert fires later in __cxa_finalize at process exit
(ggml-metal-device.m:637), after all inference work completed — exit-time
only, upstream teardown-order issue, unrelated to MTP.

Full log: fused-ffi-run.txt. Harness: fused-ffi-harness.ts.
114 changes: 114 additions & 0 deletions .github/issue-evidence/gemma4-assistant-mtp/fused-ffi-harness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* Fused-lib product-path proof harness for the gemma4-assistant MTP drafter.
*
* Drives the EXACT desktop text path: libelizainference.dylib ABI-v9
* `eliza_inference_llm_stream_open` with `mtp_drafter_path` set (the
* separate-drafter MTP engine, ctx_other shared-KV), via the plugin's own
* `loadElizaInferenceFfi` binding — no mocks, no llama-server.
*
* Target : /tmp/vision/gemma4/bundles/2b/text/eliza-1-2b-128k.gguf (gemma4)
* Drafter: /tmp/mtp/bundles/2b/mtp/drafter-2b.gguf (gemma4-assistant)
*/
import { loadElizaInferenceFfi } from "/Users/shawwalters/eliza-workspace/milady/eliza/plugins/plugin-local-inference/src/services/voice/ffi-bindings";

const LIB =
"/Users/shawwalters/eliza-workspace/milady/eliza/plugins/plugin-local-inference/native/llama.cpp/build-desktop-metal/bin/libelizainference.dylib";
const BUNDLE_ROOT = "/tmp/vision/gemma4/bundles/2b";
const DRAFTER = "/tmp/mtp/bundles/2b/mtp/drafter-2b.gguf";
const MAX_TOKENS = 96;

const PROMPTS = [
"Count from one to twenty, writing each number as a word separated by commas.",
"List the seven days of the week in order, one per line.",
];

function gemmaPrompt(user: string): string {
return `<start_of_turn>user\n${user}<end_of_turn>\n<start_of_turn>model\n`;
}

const ffi = loadElizaInferenceFfi(LIB);
console.log(`[harness] lib=${LIB}`);
console.log(
`[harness] abi=${ffi.abiVersion?.() ?? "?"} llmStreamSupported=${ffi.llmStreamSupported?.()} llmMtpSupported=${ffi.llmMtpSupported?.()} tokenizeSupported=${ffi.tokenizeSupported?.()}`,
);

const ctx = ffi.create(BUNDLE_ROOT);
console.log(`[harness] fused ctx created over bundle root ${BUNDLE_ROOT}`);

interface RunResult {
text: string;
nGenerated: number;
ms: number;
drafted: number;
accepted: number;
}

function run(user: string, mtp: boolean): RunResult {
const tokens = ffi.tokenize({ ctx, text: gemmaPrompt(user) });
const stream = ffi.llmStreamOpen({
ctx,
config: {
maxTokens: MAX_TOKENS,
temperature: 0, // greedy so baseline and MTP outputs must match
topP: 1,
topK: 0,
repeatPenalty: 1,
slotId: -1,
promptCacheKey: null,
draftMin: mtp ? 1 : 0,
draftMax: mtp ? 1 : 0,
draftModelPath: mtp ? DRAFTER : null,
gpuLayers: -1,
contextSize: 4096,
},
});
let text = "";
let nGenerated = 0;
let drafted = 0;
let accepted = 0;
const t0 = performance.now();
try {
ffi.llmStreamPrefill({ stream, tokens });
for (;;) {
const step = ffi.llmStreamNext({ stream, maxTokensPerStep: 32 });
text += step.text;
nGenerated += step.tokens.length;
drafted += step.drafterDrafted;
accepted += step.drafterAccepted;
if (step.done || nGenerated >= MAX_TOKENS) break;
}
} finally {
ffi.llmStreamClose({ stream });
}
const ms = performance.now() - t0;
return { text, nGenerated, ms, drafted, accepted };
}

let totDrafted = 0;
let totAccepted = 0;
for (const p of PROMPTS) {
console.log(`\n=== prompt: ${JSON.stringify(p)}`);
const base = run(p, false);
console.log(
`[baseline] n=${base.nGenerated} ${(base.nGenerated / (base.ms / 1000)).toFixed(1)} tok/s (prefill+decode ${base.ms.toFixed(0)}ms)`,
);
console.log(`[baseline] text: ${JSON.stringify(base.text)}`);
const mtp = run(p, true);
totDrafted += mtp.drafted;
totAccepted += mtp.accepted;
console.log(
`[mtp] n=${mtp.nGenerated} ${(mtp.nGenerated / (mtp.ms / 1000)).toFixed(1)} tok/s (prefill+decode ${mtp.ms.toFixed(0)}ms) drafted=${mtp.drafted} accepted=${mtp.accepted} acceptance=${mtp.drafted > 0 ? (mtp.accepted / mtp.drafted).toFixed(3) : "n/a"}`,
);
console.log(`[mtp] text: ${JSON.stringify(mtp.text)}`);
console.log(
`[check] greedy outputs identical: ${mtp.text === base.text}`,
);
}

console.log(
`\n[TOTAL] drafted=${totDrafted} accepted=${totAccepted} acceptance=${totDrafted > 0 ? (totAccepted / totDrafted).toFixed(3) : "n/a"}`,
);

ffi.destroy(ctx);
ffi.close();
console.log("[harness] clean shutdown");
Loading
Loading