1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// emelex patch (not upstream): this entire module is an emelex addition —
// the generic multi-token-prediction (MTP) surface for self-speculative
// decoding. Upstream deletes MTP weights at load time.
//! Architecture-neutral types for multi-token-prediction (MTP)
//! speculative-decoding support.
//!
//! The concrete v1 implementation lives in the Qwen3.5 module
//! (`qwen3_5::Qwen35Mtp`); the types here are the shared vocabulary the
//! [`super::Model`] fan-outs (`forward_hidden`, `forward_mtp`,
//! `new_mtp_caches`, `has_mtp`) and the decode loop speak.
use LayerCache;
use crate;
/// One backbone forward pass, split at the layer-loop → final-norm → head
/// boundary.
///
/// `hidden_pre_norm` is the decoder-stack output BEFORE the final norm;
/// `logits = head(norm(hidden_pre_norm))`. The MTP module consumes the
/// pre-norm hidden rows (`prev_hidden` in `forward_mtp`), so both must
/// come out of a single pass with identical op order to the plain
/// `forward` path.
/// One MTP draft/priming step.
///
/// `recycle_hidden = mtp.norm(mtp_stack)` — the POST-norm MTP-stack
/// output. It is what the next *recursive* draft call consumes as
/// `prev_hidden`; committed pairs always use verified target backbone
/// hiddens instead. `logits` is the shared head projected over
/// `recycle_hidden`.
/// The live working cache of the MTP module (v1: exactly one
/// full-attention, non-windowed [`super::cache::KvCache`]).
;
/// Poolable MTP snapshot for the prompt cache.
///
/// `frontier` must be a DETACHED array (contiguous + eval'd) — an
/// evaluated slice still pins its `[1, L, H]` parent, so the caller
/// enforces detachment before constructing an `MtpState`.
/// Outcome of pre-sanitize MTP detection on the raw checkpoint key set,
/// handed to `qwen3_5::sanitize` so it can preserve and canonicalize MTP
/// keys instead of deleting them.