Runtime

Exact Speculative and Assisted Decoding for TinyRustLM

Report summary

Recommendation: conditional go for a narrowly scoped experiment; no product adoption yet. TinyRustLM should first test exact, linear speculative decoding with one genuinely compatible tiny draft and the qualified champion, plus a model-free prompt-lookup baseline. Shipping should occur only if the i

Status
Research archive item
Category
Runtime
Length
8,015 words
Reading time
37 minutes
Report type
strategy

Key topics

  • Runtime
  • AI
  • Rust
  • Privacy
  • Semantic Systems
  • Research Archive
  • Audit
  • Architecture

Research provenance

Archive status
Research archive item
Content identity
sha256:b47b9f519c9d1e76a3a88aedece345fa03a5b4b3d5ca714f91956dd0e9897536

For citation, use the report title and canonical URL. Archival presence does not establish authorship or promote report statements into portfolio evidence.

Source availability: 40 citation markers in the source export have no recoverable source links. Those markers are omitted from this reader; any supplied bibliography and ordinary links remain. Check the original sources before relying on the cited claims.

This page renders the archived Markdown as safe, formatted HTML. It is background research and does not become a portfolio claim without evidence review.

Full report

On this page

Executive recommendation and evidence boundaries

Recommendation: conditional go for a narrowly scoped experiment; no product adoption yet. TinyRustLM should first test exact, linear speculative decoding with one genuinely compatible tiny draft and the qualified champion, plus a model-free prompt-lookup baseline. Shipping should occur only if the implementation preserves the champion’s declared distribution and wins preregistered end-to-end latency, memory, energy, and reliability gates. Published speedups are evidence that the technique can work, not estimates for TinyRustLM. The uploaded specification’s distinctions among artifact bytes, logical composition bytes, incremental bytes, physical deduplicated bytes, and peak resident bytes should be treated as mandatory accounting categories.

The original speculative-sampling and speculative-decoding papers prove that a cheaper proposal model can accelerate generation without changing the target model’s output distribution when proposals are accepted probabilistically and rejections use the correct residual distribution. Their measured speedups arose on particular models, devices, kernels, and workloads and therefore cannot be transferred to TinyRustLM without local measurement.

Evidence labels used below

LabelMeaning
Observed public factDirectly found in a cited paper, official documentation, standard, or public repository.
Externally reported resultA benchmark or conclusion reported by source authors but not independently validated for TinyRustLM.
InferenceA conclusion derived from cited facts and the stated TinyRustLM constraints.
Engineering recommendationA proposed design or gate, not an observed property of private TinyRustLM code.
AssumptionA temporary premise needed because private artifacts or hardware are unavailable.
Local verification requiredA claim that can be settled only with authorized TinyRustLM models, tokenizers, kernels, and machines.

Immediate decision

Decision areaRecommendationReason
Product rolloutDo not ship yetNo private model pair, tokenizer identities, target verification API, cache behavior, memory profile, or benchmark data were available.
Initial prototypeProceedExact linear speculation has a compact correctness argument and can be isolated behind a removable target API.
First proposal sourcesPrompt lookup and one same-tokenizer tiny draftThey minimize architectural change and provide a model-free control against which the draft’s extra bytes and energy can be judged.
Initial decoding modesGreedy first, exact stochastic secondGreedy provides strong token-identity oracles; stochastic mode adds residual sampling, probability storage, and RNG obligations.
Initial lookaheadSmall fixed values, including zero, one, two, and fourThis exposes batch-verification economics without prematurely adding an adaptive policy.
Cross-tokenizer assistanceDeferRetokenization, cache realignment, probability transport, and normalization create substantially larger correctness obligations.
Medusa, EAGLE, MTP, or LayerSkipDefer unless the champion already contains qualified supportThese methods require trained heads, architecture-specific modules, early-exit training, tree verification, or specialized checkpoints.
Browser rolloutAfter native correctness and cost proofBrowser memory, WebGPU dispatch, WASM kernels, adapter limits, worker failure, and duplicate model residency add independent risks.

Minimum adoption conditions

TinyRustLM should adopt exact speculation only when all of the following are simultaneously true:

  1. The target can score a proposed sequence in one prefill-like operation and return the target distributions for every proposed position plus the position after the proposal.
  2. The implementation has a transactional target and draft cache abstraction with logical rollback.
  3. The draft and champion compatibility manifest passes strict identity and tokenizer checks.
  4. Greedy output is token-identical to the champion baseline under the same declared decoding identity.
  5. Stochastic tests support distributional equivalence to the champion after accounting for the implementation’s declared finite-precision arithmetic.
  6. End-to-end gains include both model loads, both prefills, both KV caches, synchronization, rejection work, and memory pressure.
  7. The implementation can fail before output or fail visibly after output without silently restarting and duplicating answer text.
  8. An unsuccessful implementation can be deleted cleanly by removing the speculative orchestrator and optional target-verification API while leaving the champion baseline unchanged.

Likely outcome by topology. As an engineering inference, the strongest candidate is a native or native-companion configuration in which the champion remains resident and a truly tiny draft is resident on otherwise underused CPU capacity. A browser-only configuration may still win when the champion’s q_len > 1 kernels efficiently amortize weight access, but it is more likely to be constrained by duplicate weights, duplicate KV, WebGPU synchronization, and transient loading memory. Prompt lookup may therefore be the best browser-local acceleration even when a neural draft wins natively. Public GPU inference frameworks emphasize that speculative decoding is most beneficial at low batch sizes and depends on efficient collective verification.

No assertion in this report implies access to TinyRustLM source code, .slm files, models, routing logic, test cases, private prompts, outputs, or machines.

Exactness taxonomy and compatibility contracts

The central classification rule is not “small versus large.” It is whether the proposal mechanism and verifier preserve the champion’s declared token distribution after the complete decoding transformation: temperature, penalties, token suppression, top-\(k\), top-\(p\), grammar masks, stop rules, and any other versioned processor. A proposal source may be weak, deterministic, neural, retrieval-based, or architecturally embedded; exactness comes from verification and correction, not from the proposal’s name.

MethodDistributional statusMinimum target capabilityTinyRustLM assessment
Independent draft model, stochastic speculative samplingExact when acceptance and residual correction are implemented over the full processed target and proposal distributionsOne target verification producing distributions for all proposals and one extra position; transactional KVPrimary candidate with strict tokenizer and identity binding
Greedy assisted decodingExact for deterministic baseline when each proposal is accepted only if it equals the target argmax under identical numerical and tie-breaking behaviorBatched target logits for the proposal positionsImplement first
Dynamic speculation lengthInherits the underlying method’s exactness if it changes only how many tokens are proposedSame as underlying methodAdd only after fixed-\(k\) profiling
Prompt or generated-prefix n-gram lookupExact only when copied candidates remain proposals and are target-verified; not exact if copied blindlyBatched target verification; no draft modelRequired control and likely browser candidate
Self-speculative early exitPotentially exact when early layers propose and the complete target verifies; practical support generally requires compatible training and cache semanticsAbility to resume target layers and verify multiple positionsOnly if champion was trained and exported for it
Layer-skipping draftSame principle as self-speculation; exact only with full target verificationIntermediate hidden-state API and later-layer verificationNot a first implementation
Multi-token prediction headsPotentially exact when heads generate proposals that undergo exact target verification; relaxed acceptance is approximateHead execution plus linear or tree target verificationCheckpoint-dependent
Medusa-style heads and candidate treesExact under strict target-token matching or a proved exact rejection sampler; “typical” or relaxed acceptance is approximateTree attention or flattened branch verification and branch-aware cache commitHigh complexity; defer
EAGLE-style feature drafterPotentially exact when its outputs are proposals and the target performs the required exact acceptance procedureArchitecture-specific drafter and target verificationDefer absent qualified checkpoint
Lookahead/Jacobi candidate generationPotentially exact because candidates can be treated as target-verified proposalsSpecialized parallel target execution and n-gram candidate poolInteresting but outside minimal core
Grammar-forced tokenExact relative to the grammar-masked target when the valid support contains exactly one target tokenGrammar state plus target KV append; LM-head computation may sometimes be skippedWorth exploiting after grammar correctness is established
Static target–assistant distribution mixtureApproximate because it deliberately replaces the target distribution with a mixtureBoth distributionsMust be separately named and quality-budgeted
Lenient, top-\(k\), or “close enough” acceptanceApproximateTarget scores and custom acceptance ruleDo not expose as exact
Hidden best-of-\(N\) generationNot speculative decoding and changes system behaviorMultiple complete generations and selectorProhibited

The exact independent-draft algorithm is established by the original speculative-decoding and speculative-sampling work. Hugging Face currently documents assisted decoding, prompt lookup, self-speculative early exit, multi-token prediction, cross-tokenizer assistance, and an explicitly approximate static-ensemble mode. Medusa, LayerSkip, EAGLE, lookahead decoding, and MTP provide alternative proposal architectures, but each carries different training and verifier requirements.

Tokenizer compatibility contract

RelationshipExact greedy useExact stochastic useRequired treatment
Identical tokenizer artifact, vocabulary, IDs, normalization, special tokens, and added-token orderYes, subject to target numerical identityYesPreferred initial scope
Same base tokenizer but different added tokens or reordered IDsOnly after proving an active-support ID mapping and identical prompt encodingOnly after transporting complete proposal probabilities into the target vocabularyReject by default
Same decoded bytes but different token IDs or segmentationPossible only with a verified bridge and target-token acceptanceNot by naïve retokenization; requires probability-preserving transport across variable-length tokenizationsDefer
Retokenization with longest-common-subsequence cache repairCan be operationally useful, especially for greedy assistance, but requires target-output and cache proofOriginal token-level speculative correction does not automatically remain exactTreat as a separate algorithm
Universal byte-level bridgeExact in principle only if target-token sequence probabilities are correctly marginalized and the champion remains authoritativePotentially exact but algorithmically expensiveResearch path, not minimal implementation
Different or lossy Unicode normalizationNot generally safeNot generally safeIncompatible unless a formal reversible transform is proved
Different BOS/EOS or byte-fallback conventionsUnsafe without explicit mapping and stop-state proofUnsafeReject by default

Hugging Face’s Universal Assisted Generation translates context between tokenizers by decoding, re-encoding, identifying a common suffix, and realigning caches. Its later token-level-intersection work addresses heterogeneous-vocabulary sampling. These are material advances, but they should not be treated as evidence that an arbitrary pair of tokenizers is exact under TinyRustLM’s champion distribution. In particular, an ID-level residual distribution \([q-p]_+\) is undefined until both distributions have been expressed on a common sample space.

Engineering recommendation: the initial compatibility manifest should require byte-identical tokenizer artifacts and explicit equality of:

  • vocabulary size, token strings, token IDs, added-token order, merges or unigram scores, normalization, pre-tokenization, byte fallback, unknown-token behavior, and special-token map;
  • chat-template bytes and version;
  • rendered system, developer, and user prompt token IDs;
  • BOS, EOS, padding, stop-token, and stop-string policies;
  • context limit, sliding-window behavior, truncation side, RoPE parameters and scaling, position-ID generation, and cache origin;
  • model weights, quantization metadata, adapters in ordered composition, logits processors, grammar identity, and sampling policy.

A small output-vocabulary draft can still be exact if it consumes the champion’s tokenization and defines \(p(x)=0\) for omitted output tokens; the residual sampler then retains the champion’s missing mass. Remapping IDs or changing input segmentation is the dangerous part.

Model and prompt identity. The target and draft need not share weights, architecture, context length, or probability quality, but they must be evaluated on semantically and positionally aligned prefixes. A shorter draft context can be used only under a versioned draft truncation rule whose proposal probabilities are computed from that truncated prefix while target verification uses the complete champion prefix. Exactness can survive a poor proposal distribution because the draft is merely a proposal, but acceptance may collapse. By contrast, silently applying different chat templates, system prompts, adapter orders, BOS rules, or position IDs can cause both low acceptance and invalid cache alignment.

Different RoPE scaling policies do not mathematically invalidate a proposal model by themselves: the draft may use any proposal distribution. They do invalidate any attempt to share KV, hidden states, positions, or cached prompt transformations between models. Shared prompt prefill must therefore mean “run the same declared prompt independently through each model,” not “copy one model’s KV into the other,” unless a separately proved cache transform exists.

Current implementation landscape. As of retrieval on August 1, 2026:

  • Hugging Face Transformers documents assisted decoding for greedy and sampled generation, prompt lookup, self-speculative early exit, MTP, and cross-tokenizer assistance; documented restrictions and behavior vary by release.
  • TensorRT-LLM 1.3.0 release-candidate documentation covers draft/target, n-gram, EAGLE 3, MTP, suffix-automaton enhancement, parallel drafts, and user-provided drafters. Its relaxed MTP mode is explicitly not strict token-match acceptance.
  • vLLM’s current documentation covers multiple speculative techniques and warns that mathematical losslessness does not guarantee bitwise log-probability stability across batching and kernels.
  • llama.cpp publicly exposes local draft/target speculative decoding in its server tooling, making it a relevant native reference, but TinyRustLM should pin and audit a specific commit rather than treating changing master documentation as normative.
  • WebLLM and Transformers.js publicly provide browser-local inference through WebGPU, WASM, and ONNX-related stacks. In the reviewed public documentation, no implementation-grade exact speculative-sampling API was identified; that negative search result is not proof of absence.

Mathematical reconstruction and normative algorithms

Let \(h\) be the current authoritative target-token prefix. Define:

  • \(q_i(x)\): the champion’s complete processed next-token distribution at speculative position \(i\), conditioned on \(h,y_1,\ldots,y_{i-1}\);
  • \(p_i(x)\): the draft’s actual proposal distribution at that same logical position;
  • \(y_i\sim p_i\): the proposed token;
  • \(k\): maximum proposal length for this round.

“Processed” means after every declared temperature, mask, grammar, repetition penalty, top-\(k\), top-\(p\), suppression, and other policy transformation. The champion distribution \(q_i\), not the draft, is authoritative.

Exact stochastic step

For each proposal \(y_i\), accept it with

\[ a_i(y_i)=\min\left(1,\frac{q_i(y_i)}{p_i(y_i)}\right). \]

If the first rejection occurs at position \(j\), sample the replacement token from

\[ r_j(x)= \frac{[q_j(x)-p_j(x)]_+} {\sum_v [q_j(v)-p_j(v)]_+}, \qquad [z]_+=\max(z,0). \]

Stop the speculative round after that replacement. If every proposal is accepted, sample one additional token from \(q_{k+1}\). This is the algorithm reconstructed in the original papers.

Correctness argument

For one position, let

\[ A=\sum_x\min(p(x),q(x)). \]

The accepted path contributes probability \(\min(p(x),q(x))\) to output token \(x\). Rejection occurs with probability

\[ 1-A=\sum_x[q(x)-p(x)]_+. \]

The corrected path contributes

\[ (1-A)\frac{[q(x)-p(x)]_+}{1-A}=[q(x)-p(x)]_+. \]

Therefore,

\[ \Pr[\text{output}=x] =\min(p(x),q(x))+[q(x)-p(x)]_+ =q(x). \]

Conditioning this identity on every accepted prefix and applying induction gives the champion’s autoregressive joint distribution. The expected single-position acceptance is

\[ A=1-\operatorname{TV}(p,q), \]

so acceptance measures distributional overlap, not simply model size.

Normative greedy pseudocode

function greedy_assisted_round(state, requested_k):
    require state.identity_manifest_is_valid
    require state.target_cache.is_committed
    require state.draft_cache.is_committed

    remaining = state.max_new_tokens - state.emitted_token_count
    if remaining == 0:
        return FINISHED_MAX_LENGTH

    k = min(requested_k, remaining)

    if k == 0:
        token = target_baseline_argmax_one(state)
        commit_and_emit(token)
        return token

    tx_draft = draft_cache.begin_transaction()
    proposals = []

    for i in 0 .. k-1:
        draft_logits = draft.forward_pending_and_get_logits(tx_draft)
        draft_dist = apply_declared_draft_processors(draft_logits, state, i)

        if draft_dist.has_nan_or_no_valid_token:
            tx_draft.rollback()
            token = target_baseline_argmax_one(state)
            commit_and_emit(token)
            return token

        y = argmax_with_declared_tie_break(draft_dist)
        proposals.push(y)
        tx_draft.append_provisionally(y)

        if y is an active stop token:
            break

    tx_target = target_cache.begin_transaction()
    result = target.verify_linear(tx_target, proposals)
    # result.logits[i] predicts proposals[i]
    # result.logits[len(proposals)] predicts the extra token

    accepted = 0

    for i in 0 .. len(proposals)-1:
        q = apply_champion_processors(result.logits[i], state, i)

        if q.has_nan_or_no_valid_token:
            abort_round_without_emitting(tx_target, tx_draft)
            return FATAL_TARGET_NUMERIC_OR_MASK_ERROR

        target_token = argmax_with_declared_tie_break(q)

        if proposals[i] != target_token:
            tx_target.commit_proposal_prefix(accepted)
            tx_target.rollback_proposal_tail()
            tx_draft.rollback_to_authoritative_length(accepted)
            state.set_pending_authoritative_token(target_token)
            emit(proposals[0 .. accepted])
            emit(target_token)
            return accepted + 1 tokens

        accepted += 1

        if proposals[i] is an active stop token:
            tx_target.commit_proposal_prefix(accepted)
            tx_target.rollback_proposal_tail()
            tx_draft.commit_prefix(accepted)
            emit(proposals[0 .. accepted])
            mark_terminal_state()
            return accepted tokens

        if accepted == remaining:
            tx_target.commit_proposal_prefix(accepted)
            tx_target.rollback_proposal_tail()
            tx_draft.commit_prefix(accepted)
            emit(proposals)
            mark_finished_max_length()
            return accepted tokens

    q_extra = apply_champion_processors(
        result.logits[len(proposals)],
        state after proposals,
        len(proposals)
    )

    if q_extra.has_nan_or_no_valid_token:
        abort_round_without_emitting(tx_target, tx_draft)
        return FATAL_TARGET_NUMERIC_OR_MASK_ERROR

    z = argmax_with_declared_tie_break(q_extra)
    tx_target.commit_all_proposals()
    tx_draft.commit_all_proposals()
    state.set_pending_authoritative_token(z)
    emit(proposals)
    emit(z)
    return len(proposals) + 1 tokens

Normative stochastic pseudocode

function exact_speculative_round(state, requested_k, rng_contract):
    require state.identity_manifest_is_valid
    require state.target_cache.is_committed
    require state.draft_cache.is_committed

    remaining = state.max_new_tokens - state.emitted_token_count
    if remaining == 0:
        return FINISHED_MAX_LENGTH

    k = min(requested_k, remaining)

    if k == 0:
        z = target_baseline_sample_one(
            state,
            rng_contract.target_baseline(state.round_id)
        )
        commit_and_emit(z)
        return z

    tx_draft = draft_cache.begin_transaction()
    proposals = []
    proposal_log_probs = []

    for i in 0 .. k-1:
        draft_logits = draft.forward_pending_and_get_logits(tx_draft)
        p = apply_declared_draft_processors(draft_logits, state, i)

        if p.has_nan_or_no_valid_token:
            tx_draft.rollback()
            z = target_baseline_sample_one(
                state,
                rng_contract.target_baseline(state.round_id)
            )
            commit_and_emit(z)
            return z

        y = sample(
            p,
            rng_contract.draft_sample(state.round_id, i)
        )

        require log(p[y]) is finite
        proposals.push(y)
        proposal_log_probs.push(retain_or_checkpoint(p))
        tx_draft.append_provisionally(y)

        if y is an active stop token:
            break

    tx_target = target_cache.begin_transaction()
    result = target.verify_linear(tx_target, proposals)

    accepted = 0

    for i in 0 .. len(proposals)-1:
        q = apply_champion_processors(result.logits[i], state, i)

        if q.has_nan_or_no_valid_token:
            abort_round_without_emitting(tx_target, tx_draft)
            return FATAL_TARGET_NUMERIC_OR_MASK_ERROR

        p = recover_exact_proposal_distribution(proposal_log_probs[i])

        log_ratio = log(q[proposals[i]]) - log(p[proposals[i]])
        accept_probability = min(1, exp_clamped(log_ratio))

        u = uniform_open_closed(
            rng_contract.accept_uniform(state.round_id, i)
        )

        if u <= accept_probability:
            accepted += 1

            if proposals[i] is an active stop token:
                tx_target.commit_proposal_prefix(accepted)
                tx_target.rollback_proposal_tail()
                tx_draft.commit_prefix(accepted)
                emit(proposals[0 .. accepted])
                mark_terminal_state()
                return accepted tokens

            if accepted == remaining:
                tx_target.commit_proposal_prefix(accepted)
                tx_target.rollback_proposal_tail()
                tx_draft.commit_prefix(accepted)
                emit(proposals[0 .. accepted])
                mark_finished_max_length()
                return accepted tokens

            continue

        residual[x] = max(q[x] - p[x], 0) for every target token x
        residual_mass = stable_sum(residual)

        if residual_mass is not finite or residual_mass <= numeric_floor:
            abort_round_without_emitting(tx_target, tx_draft)
            return FATAL_RESIDUAL_INVARIANT_ERROR

        residual = residual / residual_mass
        z = sample(
            residual,
            rng_contract.correction_sample(state.round_id, i)
        )

        tx_target.commit_proposal_prefix(accepted)
        tx_target.rollback_proposal_tail()
        tx_draft.rollback_to_authoritative_length(accepted)
        state.set_pending_authoritative_token(z)

        emit(proposals[0 .. accepted])
        emit(z)
        return accepted + 1 tokens

    q_extra = apply_champion_processors(
        result.logits[len(proposals)],
        state after proposals,
        len(proposals)
    )

    if q_extra.has_nan_or_no_valid_token:
        abort_round_without_emitting(tx_target, tx_draft)
        return FATAL_TARGET_NUMERIC_OR_MASK_ERROR

    z = sample(
        q_extra,
        rng_contract.target_extra(state.round_id)
    )

    tx_target.commit_all_proposals()
    tx_draft.commit_all_proposals()
    state.set_pending_authoritative_token(z)

    emit(proposals)
    emit(z)
    return len(proposals) + 1 tokens

These algorithms follow the acceptance and correction construction in the foundational work, but add explicit cache, identity, stop, cancellation, and failure semantics needed for an implementation.

Normative edge-case behavior

CaseRequired behavior
\(k=0\)Execute exactly one champion baseline step. This is both a valid operating mode and a fallback control.
\(k=1\)Verify one proposal and obtain the target distribution for the proposal plus the extra position.
Full acceptanceCommit every proposal; sample or select the extra champion token unless max length or an accepted stop has already ended generation.
First-token rejectionCommit no proposal; sample the correction from \([q_1-p_1]_+\).
Later rejectionCommit only the proposals before the first rejection; discard every later draft token.
Proposal with \(p(y)=0\)Impossible under exact sampling. If observed because of underflow or corrupted state, treat it as an invariant failure rather than fabricating a ratio.
Numerical underflowCompute normalized logits and acceptance ratios in log space; compute residuals and sums in at least FP32 or a stronger declared accumulator.
All-masked draft logitsDisable speculation for that round and call the champion before emitting output.
All-masked target logitsFail visibly because the champion’s declared decoder has no valid next token; do not allow the draft to override it.
NaN or infinityAbort the uncommitted transaction; a target numerical error must not silently become a draft answer.
EOS inside proposalVerify sequentially. If accepted, commit through EOS, discard the tail, emit no extra token, and terminate. If rejected, sample the correction normally.
Rejected EOSIt is just a rejected proposal; the correction can be a non-EOS token.
Maximum-token limitNever emit beyond the limit. Proposals may fill the remaining budget; an extra token is omitted when generation ends by policy.
Stop string spanning tokensApply the champion’s declared stop-state machine after every committed token; do not emit proposal tokens beyond the first completed stop sequence.
Cancellation during draftingRoll back the draft transaction; target state remains untouched.
Cancellation during verificationCommit nothing from the round, roll back both provisional tails, and display “cancelled.”
Deterministic replayUse domain-separated, counter-addressed RNG streams and record the seed, round, proposal index, and RNG-policy version.
Baseline comparison under samplingDo not require ordinary baseline and speculative implementations to emit the same sample sequence when they consume random numbers differently; require distributional equivalence.
Cache after EOSEither materialize EOS KV explicitly or mark the terminal cache non-reusable. Do not leave an ambiguous reusable state.

RNG contract. A counter-based interface should derive independent draws for draft_sample, accept_uniform, correction_sample, target_extra, and target_baseline. This prevents changes in proposal length from shifting unrelated random draws and makes fault reproduction practical. The exact output distribution does not require the same draft and target random streams, but replay does require a stable, versioned mapping.

Finite-precision obligation. Mathematical exactness does not imply bitwise equality between a target’s q_len=1 and q_len=k kernels. Different matrix shapes, reductions, quantized deblocking, and device scheduling may perturb logits. A greedy argmax can flip near a tie; a stochastic probability vector can differ even when all token rankings remain unchanged. TinyRustLM must therefore define whether the champion’s declared distribution is the baseline single-token kernel or a broader numerically tolerated implementation family. The strongest policy is to treat the champion-alone kernel as authoritative and require batched verification to pass logit and output conformance tests against it. vLLM’s documentation similarly distinguishes algorithmic losslessness from floating-point and batching stability.

Verification, cache, residency, and browser architecture

Minimum target API

verify_linear(
    target_identity,
    committed_cache_handle,
    pending_authoritative_token?,
    proposed_target_ids[0..m],
    position_state,
    decoding_state_snapshots
) -> {
    logits_for_proposals[0..m-1],
    logits_after_all_proposals,
    provisional_cache_handle,
    numerical_metadata,
    cancellation_epoch
}

The API’s positional contract must be explicit:

  • logits_for_proposals[0] predicts proposed_target_ids[0] from the committed prefix.
  • logits_for_proposals[i] predicts proposal \(i\) after proposals \(0\ldots i-1\).
  • logits_after_all_proposals predicts the extra token after every proposed token.
  • The target forward pass must use ordinary causal masking, not permit any proposal token to attend to a future proposal.
  • The result is provisional until the orchestrator commits an accepted prefix.
  • A request identity, sequence number, and cancellation epoch must accompany every worker or native-companion message.

This k+1-distribution interface is the key performance prerequisite identified by the original algorithms: the target scores the proposal block in parallel, turning repeated decode operations into a prefill-like verification pass.

Cache transaction model

A cache transaction should expose:

checkpoint = cache.begin(committed_length)
cache.append_provisional(tokens)
cache.commit_prefix(token_count)
cache.rollback_to(logical_length)
cache.finalize()

The logical state should distinguish:

  1. Committed KV length: tokens whose K/V tensors are materialized and authoritative.
  2. Pending authoritative token: a sampled or selected token already emitted but not yet consumed by the next model forward.
  3. Provisional verification tail: target K/V for proposed tokens that may be accepted or rolled back.
  4. Terminal marker: EOS, stop, cancellation, or max-length state.
  5. Content identity: model, tokenizer, template, adapters, positional policy, prompt, cache layout, and quantization identity.

Suppose proposals \(y_1,\ldots,y_k\) are verified and rejection occurs at \(j\). The target may retain K/V only for \(y_1,\ldots,y_{j-1}\). The replacement token is usually “pending”: it has been sampled from the target-derived residual but has not yet passed through the target transformer. The next target call first consumes that token. The draft must similarly roll back rejected proposals and ingest the authoritative replacement before proposing again.

With paged KV, rollback can be logical: pages containing rejected tokens may remain allocated for reuse, but their token ranges must become unreachable. Page references must not be returned to a pool until all in-flight device work and message epochs that could address them have completed. TensorRT-LLM’s public implementation documentation illustrates request-level rewind and paged-cache handling as a concrete reference, though TinyRustLM must independently validate its own layout.

Separate-cache rule. A target and independent draft require separate KV caches. Even if both consume the same token IDs, their layers, hidden widths, head counts, head dimensions, quantization, RoPE, and cache layouts generally differ. Prompt computation may be scheduled together, but cache tensors are not interchangeable.

For a model with \(L\) layers, \(H_{\mathrm{KV}}\) KV heads, head dimension \(D\), sequence length \(S\), and \(b\) bytes per KV element, an approximate batch-one KV payload is

\[ M_{\mathrm{KV}} = 2SLH_{\mathrm{KV}}Db, \]

before page tables, alignment, allocator fragmentation, metadata, and provisional speculative tails. TinyRustLM’s peak memory must include \(M_{\mathrm{KV,target}}+M_{\mathrm{KV,draft}}\).

Logit and residual scratch. Returning all full-vocabulary distributions requires approximately

\[ M_{\mathrm{target\ logits}}=(k+1)Vb_\ell. \]

Retaining all draft distributions costs roughly \(kVb_\ell\). Exact rejection correction needs the full \(p_j\) and \(q_j\) at the rejected position. TinyRustLM can trade memory for recomputation by storing only draft checkpoints and recomputing \(p_j\) after rejection, but that recomputation belongs in the latency and energy model. Sparse top-\(k\) representations are exact only when omitted proposal probabilities are known to be zero and the residual calculation still covers all target-supported tokens.

Suggested architecture visualization — place here

sequenceDiagram
    participant UI as Browser UI
    participant O as Speculation Orchestrator
    participant D as Draft Worker
    participant T as Champion Worker or Native Companion

    UI->>O: Generate(request identity, seed, policy)
    O->>D: Synchronize authoritative prefix and pending token
    D-->>O: Proposals y[1..k], proposal probabilities, draft checkpoint
    O->>T: Verify prefix + y[1..k], transaction epoch
    T-->>O: q[1..k+1], provisional target KV

    loop In proposal order
        O->>O: Accept with min(1, q(y)/p(y))
    end

    alt First rejection at j
        O->>O: Sample residual [q_j - p_j]+
        O->>T: Commit y[1..j-1], rollback tail
        O->>D: Roll back tail, queue correction token
        O-->>UI: Emit accepted prefix + correction
    else All accepted
        O->>O: Sample target extra token
        O->>T: Commit all proposals
        O->>D: Commit proposals, queue extra token
        O-->>UI: Emit proposals + extra token
    else Cancellation or stale epoch
        O->>T: Roll back provisional state
        O->>D: Roll back provisional state
        O-->>UI: Cancelled or visible error
    end

Kernel implications

  • Quantized target kernels: verification changes the target’s query length from one to a small \(k\). This may convert weight-dominated matrix-vector work into a better-amortized small matrix multiplication, but only if the q4 kernel is optimized for these shapes.
  • WASM SIMD: standardized 128-bit SIMD can accelerate packed low-bit unpacking and dot products, but it does not eliminate the extra draft weight stream or cache traffic.
  • WebGPU: use fixed, preallocated maximum-\(k\) buffers and query actual adapter limits at runtime. Avoid returning \((k+1)V\) logits to JavaScript when acceptance and residual computation can occur on-device; CPU readback and synchronization can erase verification gains. WebGPU remained on the W3C Candidate Recommendation track in 2026, so implementation and limit variability must remain part of the compatibility matrix.
  • Native CPU: the principal opportunity is amortizing a full champion-weight traversal across several token positions. The main risks are a draft that also saturates memory bandwidth and a target kernel whose \(q_len=k\) path performs worse than repeated decode.
  • CPU draft plus GPU champion: proposal IDs and selected probabilities are small transfers, but the GPU cannot verify until drafting completes. This topology helps only when the CPU draft is fast and does not contend with GPU command preparation or unified memory.
  • Tree methods: Medusa- or EAGLE-style branches require tree attention masks, node-to-parent position maps, branch-aware logit extraction, and more complex cache commit. Linear verification should precede them.

Residency topology comparison

TopologyFixed and peak costsLatency profilePrivacy boundaryAssessment
Both models residentHighest weight and KV residency; lowest switching overheadBest steady-state candidateSingle local process/device boundaryPreferred when memory headroom is proven
Draft resident, champion streamed each roundChampion loading or weight streaming dominatesUsually untenable for interactive decodingLocal but high I/O exposureReject except unusual mapped-weight hardware
Champion resident, draft loaded on demandAdditional first-use delay and transient peak memoryMay work only for long sessions with warm draftLocalMeasure session-length break-even
Sequential reuse of one arenaLow nominal arena count but repeated weight swaps and cache invalidationPoor unless model loading is nearly freeLocalUnlikely to win
CPU draft, GPU championDuplicate residency across devices; small proposal transferPromising when CPU is spare and GPU target is underfilledLocal device boundaryStrong native candidate
Browser draft, native-companion championBrowser draft bytes plus native target; IPC synchronizationCan preserve responsive UI if IPC is low-latencyExplicit browser/native consent boundaryPromising, but protocol-hard
Browser-only WebGPU target and draftHighest browser GPU allocation and loading peakPotentially fast after warm-upEntirely browser-localHigh memory and device-loss risk
Prompt lookup, champion residentNo neural draft weights or draft KVExcellent when text is repetitiveEntirely localMandatory baseline

Required byte reporting

MeasureDefinition
Artifact bytesSum of stored files as distributed, including champion, draft, tokenizer, adapters, and metadata.
Logical composition bytesSum of logical components selected for the configuration, even where components reference identical content.
Incremental bytesAdditional artifact and runtime bytes attributable to speculation over champion-alone operation.
Physical deduplicated bytesUnique content-addressed blocks actually stored after deduplication.
Peak resident bytesMaximum simultaneous weights, KV, provisional tails, logits, scratch, worker heaps, GPU buffers, and transient load overlap during the full lifecycle.

Peak resident accounting must be timeline-based. Loading a draft while the champion and its old scratch arena remain resident may create a larger peak than steady-state decoding.

Cost model, scheduling, grammar, and draft selection

Let:

  • \(L_t,L_d\): target and draft load costs;
  • \(P_t(S),P_d(S)\): prompt-prefill costs for prompt length \(S\);
  • \(d_i\): cost to generate proposal \(i\);
  • \(V_t(k)\): target cost to verify \(k\) proposals and produce the extra distribution;
  • \(C_{\mathrm{sync}}(k)\): worker/device/IPC synchronization and transfer;
  • \(C_{\mathrm{rollback}}(j,k)\): logical and physical rollback after rejection at \(j\);
  • \(C_{\mathrm{residual}}(j)\): probability recovery, positive-part subtraction, normalization, and sampling;
  • \(a_i\): conditional acceptance probability at proposal position \(i\);
  • \(S_i=\Pr(\text{first }i\text{ proposals accepted})\), with \(S_0=1\).

No independence assumption is needed for \(S_i\). Empirically,

\[ S_i=\prod_{j=1}^{i}a_j \]

when \(a_j\) is defined conditionally on survival to position \(j\).

Ignoring terminal truncation, every round emits one authoritative token, plus one token for every accepted proposal. Thus

\[ \mathbb{E}[G(k)] = 1+\sum_{i=1}^{k} S_i = \sum_{i=0}^{k}S_i. \]

Under a constant conditional acceptance \(\alpha\),

\[ \mathbb{E}[G(k)] = \frac{1-\alpha^{k+1}}{1-\alpha}. \]

This is the standard speculative-decoding throughput structure; TinyRustLM should estimate the position-dependent \(S_i\) rather than assume a constant rate.

An implementation-grade expected round cost is

\[ \begin{aligned} \mathbb{E}[C_{\mathrm{round}}(k)] =& \sum_{i=1}^{k} d_i +V_t(k) +C_{\mathrm{sync}}(k) \\ &+ \sum_{j=1}^{k} S_{j-1}(1-a_j) \left[ C_{\mathrm{rollback}}(j,k) +C_{\mathrm{residual}}(j) \right] \\ &+ S_kC_{\mathrm{full\ accept}} +C_{\mathrm{cache\ append}} +C_{\mathrm{telemetry}}. \end{aligned} \]

The steady-state per-token cost is

\[ \bar C_{\mathrm{spec}}(k) = \frac{\mathbb{E}[C_{\mathrm{round}}(k)]} {\mathbb{E}[G(k)]}. \]

If \(C_t(1)\) is the measured champion-alone cost per generated token, the necessary steady-state break-even condition is

\[ \bar C_{\mathrm{spec}}(k)<C_t(1). \]

For a session expected to generate \(N\) tokens, define fixed incremental cost

\[ F=L_d+P_d(S)+C_{\mathrm{draft\ initialization}} +C_{\mathrm{extra\ allocation}}. \]

A rough minimum generation length is then

\[ N_{\min}

\frac{F} {C_t(1)-\bar C_{\mathrm{spec}}(k)} \]

when the denominator is positive. If it is nonpositive, no amount of session length amortizes the draft under that configuration.

The full end-to-end comparison should measure

\[ T_{\mathrm{baseline}} = L_t+P_t(S)+T_{\mathrm{decode,target}}, \]

\[ T_{\mathrm{spec}} = L_t+L_d+P_t(S)+P_d(S) +T_{\mathrm{draft}} +T_{\mathrm{verify}} +T_{\mathrm{reject}} +T_{\mathrm{sync}} +T_{\mathrm{rollback}} +T_{\mathrm{finalize}}. \]

A reported “tokens per second” that begins after both models and prompts are warm is therefore only one of several views.

Adaptive speculation length

PolicyExactnessAdvantagesRisksRecommendation
Fixed \(k\)Inherits verifier exactnessReproducible, easy to benchmark and TDDSuboptimal across tasksStart here
Acceptance-history heuristicExact if it changes only future proposal countVery cheapSlow adaptation; workload oscillationAdd after fixed-\(k\) study
Draft-confidence thresholdExact if confidence only terminates proposal generationResponds within a roundConfidence may be poorly calibrated to target acceptanceCandidate second policy
Learned acceptance predictorExact if it only schedules and does not alter target probabilitiesCan combine task, length, and recent outcomesAdded model, privacy, versioning, training contaminationDefer
Oracle lookaheadOffline upper bound onlyQuantifies scheduling headroomRequires future target results and is not freeEvaluation tool, never production claim

Hugging Face changed its default assisted-generation scheduling toward confidence-based dynamic lookahead in Transformers 4.45 and reported gains over static schedules on its tested model pairs and hardware. Those results support testing the idea but do not determine TinyRustLM’s policy.

The scheduler must be content-identity-bound and versioned. It may use local counters such as recent position-wise acceptance, draft entropy, remaining context, and measured device timings. It should not upload private prompts or outputs, retain hidden user-history features, or optimize against sealed answer quality. An online policy update that changes behavior during a preregistered evaluation should invalidate the run.

Grammar and deterministic opportunities

A grammar mask replaces the unmasked champion distribution \(q\) with

\[ q_G(x)= \frac{q(x)\mathbf 1[x\in A_G]} {\sum_v q(v)\mathbf 1[v\in A_G]}, \]

where \(A_G\) is the valid-token set in the current grammar state. Exact speculation is then exact relative to \(q_G\), provided the grammar state and masking order are identical in baseline and speculative execution.

Target probability verification can be skipped only when the declared target decoder has exactly one valid next target token. Even then, the forced token must eventually pass through the target transformer to create KV for subsequent prediction. TinyRustLM may batch a sequence of grammar-forced tokens as a prefill-like append and may omit unnecessary LM-head projection at intermediate forced positions if the target API supports it. It may not skip target state advancement.

Prompt copies, whitespace predictions, closing braces, indentation, and syntax continuations are not automatically forced. Unless the validated grammar’s target-token support is a singleton, they remain proposals and require target verification. Public guided-decoding systems support JSON Schema, regular expressions, and EBNF-like constraints, demonstrating the operational value of grammar masks, but TinyRustLM must qualify its own parser and token-mask generation.

Draft training and selection

Draft optionLikely benefitExactness implicationMain qualification requirement
Generic tiny instruct modelLowest acquisition effortExact if probabilities and tokenizer mapping are validAcceptance and prompt-format compatibility
Draft-specialized modelBetter champion overlap for the same sizeExact under normal verifierProven provenance and representative training
Champion distillationCan directly reduce \(TV(p,q)\)Exact under verifierNo sealed evaluation answers; champion data rights
Output-vocabulary trimmingSmaller head and artifactsExact if omitted tokens receive \(p=0\) in champion vocabularyPreserve target IDs and residual support
Domain specialistHigh acceptance in narrow strataExact but may collapse elsewhereRouter-independent evaluation and fallback
Online adaptationCould learn local styleExactness can remain, but behavior becomes nonstationaryPrivacy, poisoning, reproducibility, rollback
MTP or self-distilled headsLow draft overhead and shared representationExact only with strict target verificationArchitecture changes and trained checkpoints
Early-exit draftShares weights and may reduce resident bytesExact only with full-layer verificationEarly-exit training and hidden-state API

LayerSkip specifically combines layer dropout and early-exit training to support self-speculative execution, while MTP and Medusa add future-token heads. EAGLE drafts at a feature level. These are not drop-in properties of an arbitrary champion checkpoint.

Contamination boundary. Draft training may use appropriately licensed public data, nonsealed synthetic prompts, and champion probability traces generated under an authorized process. It must not use sealed product evaluation answers, hidden human-preference labels from the final test, private user prompts without explicit consent, or test-set-derived routing rules. Provenance receipts should bind dataset versions, filters, champion identity, training code, and draft artifact hash.

Preregistered evaluation, metrics, and promotion gates

Comparison arms

ArmPurpose
Qualified champion aloneAuthoritative output, latency, memory, energy, and failure baseline
Champion plus prompt lookupModel-free assisted-decoding control
Champion plus one generic tiny draftTests whether “small” actually produces useful overlap
Champion plus draft-specialized modelTests whether specialization justifies extra artifact and training cost
Self-speculative mode, if the champion supports itTests shared-weight alternative
Incompatible-tokenizer expected-failure controlConfirms compatibility rejection or explicitly tested bridge behavior
Approximate method, if consideredKept in a separately named quality-budgeted experiment

Every paired run must bind the same champion artifact, tokenizer, template, rendered prompt IDs, adapters, decoding profile, grammar, stop policy, seed family, context limit, hardware, browser version, worker topology, and thermal/power condition. Speculative policy and draft identity are the intended independent variables.

Workload strata

The preregistered corpus should include casual chat, ambiguous requests, source conflict, current-preference questions, prompts requiring distrust of model memory, summaries, rewrites, structured JSON, extraction, code, repetitive text, multilingual text, long context, and adversarial low-acceptance inputs. Each stratum should report acceptance and quality separately; a high aggregate rate dominated by repetitive copying is insufficient evidence for conversational deployment.

Long-context tests should cross page boundaries, draft context limits, target context limits, sliding-window thresholds, and browser-memory pressure points. Multilingual tests should include combining marks, composed and decomposed Unicode, emoji sequences, right-to-left text, CJK segmentation, byte fallback, and scripts in which tokenizer normalization differs.

Metrics

CategoryRequired measures
Proposal efficiencyAccepted proposals per target pass; survival \(S_i\); first-rejection position; acceptance by task, language, context length, and draft confidence
Calls and workTarget verification calls; target single-token calls; draft calls; recomputed distributions; cache rollbacks; bytes transferred
LatencyCold start; model load; target prefill; draft prefill; first-token latency; steady decode; total completion; p50, p95, and worst retained case
ThroughputUser-visible generated tokens per second and champion-forward-equivalent work, not merely accepted tokens
MemoryArtifact, logical, incremental, deduplicated, peak resident, target KV, draft KV, provisional tail, logits, scratch, and transient loading peak
EnergyCPU package, GPU/device, and whole-system energy where measurable; energy per completed token
ExactnessGreedy token identity; stop position; raw byte output; target-processor state; stochastic sequence-distribution tests
QualityTask success, schema validity, code tests, semantic score, blinded human preference, severe-regression count
ReliabilityLoad failures, OOM, device loss, cancellation latency, stale-message rejection, cache-recovery success, duplicate-output incidence
Context behaviorMaximum usable context, truncation equivalence, page rollback, position and RoPE conformance
PrivacyReceipt fields emitted, prohibited-field scans, prompt/output leakage tests

Exactness tests

For deterministic champion decoding, the acceptance criterion is zero token mismatches against champion-alone output across all retained matched-identity cases. The comparison must include EOS and stop positions, not only visible decoded text.

For stochastic exactness:

  1. Build synthetic vocabularies of two to six tokens with rational or exactly representable probabilities.
  2. Enumerate all short target and draft distributions, including disjoint supports, equal distributions, tiny overlap, zero target probability, zero proposal probability, and masked tokens.
  3. Compare exact sequence probabilities by exhaustive state enumeration.
  4. Run Monte Carlo tests against target probabilities with preregistered confidence intervals and correction for multiple comparisons.
  5. Test the distribution of first rejection positions and corrected tokens.
  6. Test transformed distributions after temperature, top-\(k\), top-\(p\), penalties, and grammar masks.
  7. Compare q_len=1 and q_len=k target logits and resulting distributions on the real kernels.
  8. Maintain deterministic golden vectors for the reference speculative interpreter and its RNG domains.

Deterministic replay is useful for debugging, but ordinary champion-alone and speculative runs need not produce the same sampled answer because they use random draws differently. Distributional equivalence is the mathematical criterion.

Suggested promotion gates

These values are engineering recommendations to preregister before seeing final results, not claimed industry standards.

GateProposed requirement
Greedy correctnessZero mismatched target token IDs, stop decisions, or raw output bytes across the complete matched suite
Stochastic correctnessAll exhaustive tests exact within declared arithmetic; Monte Carlo tests remain inside preregistered simultaneous confidence bounds
Numerical conformanceBatched-verification distributions remain within a declared tight tolerance of champion-alone distributions, with no argmax flips in deterministic mode
End-to-end performanceAt least 10% median completion-latency improvement in each designated adoption stratum after cold and warm costs are separately reported
Tail latencyNo more than 5% p95 regression in a stratum where speculation remains enabled
First-token latencyNo material regression under the product’s preregistered threshold; otherwise draft loading/prefill must be deferred or amortized
MemoryNo OOM; at least 15% measured headroom below the enforced device or browser budget during worst-case transient peak
EnergyNo statistically supported energy-per-completed-token regression in designated hardware classes
Exact-mode qualityZero quality budget: outputs must follow the champion decoder, not a semantic approximation
Approximate-mode qualityNo severe safety regression; no more than one percentage point absolute automated-task regression and a preregistered human noninferiority margin, such as two preference points
ReliabilityNo duplicate answer streams; all injected failures produce the specified visible state
MaintenanceSpeculation can be disabled and deleted without changing champion-alone code paths or serialized conversation semantics

The performance gate should be applied separately to browser-only, browser/native, and native-only classes. It is acceptable for the scheduler to disable speculation on known low-acceptance strata, but that disabling policy must itself be frozen before the final evaluation.

Suggested result visualizations

Place these immediately after the preregistered results table:

  • A survival curve showing \(S_i\) by proposal position and workload stratum.
  • A latency decomposition waterfall with load, both prefills, draft, verification, correction, synchronization, and output handling.
  • A break-even plot with session output length on the horizontal axis and total latency ratio on the vertical axis.
  • A scatter plot of peak resident bytes versus median completion latency for every topology.
  • An acceptance-versus-draft-entropy calibration plot.
  • A heat map of method by workload stratum, with separate panels for performance and quality.
  • An empirical cumulative distribution of per-request speedup so that regressions are not hidden by a mean.
  • A Pareto frontier of latency, energy, and peak resident memory.

Fault tolerance, privacy, implementation backlog, and deletion rules

Fault-injection matrix

Injected conditionDetectionRequired state transitionFallback behavior
Draft load failureArtifact I/O or hash failureDestroy partial draft stateChampion baseline is allowed only before speculative output begins
Target load failureArtifact I/O, allocation, or hash failureDestroy all generation stateVisible failure; draft must never answer alone
Tokenizer mismatchCompatibility-manifest failureDisable speculative configurationChampion baseline before output
Chat-template or adapter mismatchContent-identity checkInvalidate both cachesRe-render and prefill under one identity or fail
Cache corruptionBounds, checksum, generation epoch, or oracle mismatchQuarantine cache and terminate transactionVisible error; retry only as a new answer
Rejected EOSNormal acceptance pathRoll back EOS proposal and later tailEmit correction token normally
NaN or infinityDistribution validatorAbort uncommitted roundVisible target error; no invented token
All-masked distributionMask validatorTerminate or grammar errorNo draft override
Proposal beyond contextPreflight capacity checkReduce \(k\) or disable speculation before draftingApply champion’s declared context policy
Cancellation during verificationCancellation epochRoll back provisional target and draft tailsDisplay cancelled; emit no round output
WebGPU device lossDevice-lost callback and epoch invalidationInvalidate GPU buffers and cachesVisible failure; new explicit retry may use baseline
Worker deathHeartbeat or message-port closeReject all outstanding sequence numbersVisible failure; no silent duplicate restart
Stale proposal messageRequest ID, round ID, and prefix hashDrop messageContinue only with current epoch
Model or adapter switchIdentity changeInvalidate KV and proposal stateRe-prefill; never reuse old state
Insufficient memoryAllocation preflight or OOMRelease draft/provisional resourcesChampion baseline only if champion fits and nothing was emitted
Residual mass numerical failureInvariant checkAbort transactionFatal exactness error, not silent target sampling
Native-companion disconnectAuthenticated channel stateInvalidate remote handlesVisible disconnect; a fresh baseline answer requires new user-visible transaction

No-duplicate-output rule. Fallback to champion-alone execution may be silent only before the answer has emitted its first token. Once output has been streamed, an unrecoverable speculative failure must terminate that answer visibly. Automatically restarting from the prompt could repeat or contradict already displayed text and obscure the failure.

Privacy-safe receipt

A local receipt may contain:

receipt_version
request_nonce
champion_artifact_hash
draft_artifact_hash or "none"
tokenizer_hash
chat_template_hash
adapter_chain_hash
sampling_policy_hash
grammar_hash
position_policy_hash
scheduler_policy_hash
hardware_class
browser/runtime version
seed commitment or local replay seed
target-call count
draft-call count
proposal count
accepted-count histogram
rejection-position histogram
cold and warm timing aggregates
peak resident byte categories
bounded numeric errors
failure and fallback code

It should exclude prompts, outputs when private, model bytes, decoded token strings, local filesystem paths, credentials, peer identifiers, hidden user history, raw KV, and unrestricted device fingerprints. A receipt intended for sharing can hash or bucket hardware information more coarsely than a local diagnostic receipt.

Implementation components

ComponentMinimum responsibility
Identity manifestContent-address every model, tokenizer, template, adapter order, position policy, sampling policy, and grammar
Target verifierProduce position-aligned target logits and provisional KV for a linear proposal
Cache transactionCheckpoint, append, commit prefix, rollback, epoch invalidation, and terminal state
RNG contractCounter-addressed domain separation and replay metadata
Probability engineStable processor ordering, log-softmax, acceptance ratio, residual normalization, and sampling
Tokenizer compatibility checkerByte-level artifact comparison and active ID-map validation
SchedulerVersioned fixed and later adaptive \(k\); local-only statistics
Worker protocolRequest, round, prefix identity, cancellation epoch, stale-message rejection
UI state machineLoading draft, baseline, accelerating, fallback-before-output, cancelled, failed
Test oracleSimple high-precision reference implementation independent from optimized kernels
Metrics recorderSeparated cold, prefill, verify, rollback, memory, energy, and output timings

Zero-third-party-crate Rust assessment. A same-tokenizer, linear greedy implementation is feasible in a minimal Rust core. Exact stochastic sampling is also feasible but requires careful implementations of stable log-softmax, categorical sampling, residual arithmetic, and RNG. The following are poor initial fits for a zero-third-party-crate core:

  • cross-tokenizer Unicode normalization and retokenization bridges;
  • complete JSON Schema, regex, or EBNF grammar compilation;
  • GPU portability layers and shader toolchains;
  • tree-attention construction for Medusa or EAGLE;
  • statistical test frameworks;
  • arbitrary model-format parsing and compression;
  • cryptographic content hashing if TinyRustLM does not already contain a qualified implementation.

A clean architecture can keep the exact orchestration core dependency-free while generating tokenizer manifests, grammar automata, and test fixtures in audited build tools. Runtime use of an external grammar or GPU component must still be explicitly qualified; “zero crates” must not motivate an improvised, under-tested Unicode or cryptographic implementation.

TDD and adoption sequence

StageTests and deliverableExit criterion
Probability kernelTiny rational distributions; exhaustive acceptance and correctionExact enumerated output probabilities
Reference interpreterSlow scalar greedy and stochastic implementationStable golden vectors and replay
Cache simulatorSynthetic append, commit, rollback, EOS, cancellation, stale epochState invariants under property-based operation sequences
Target verifierChampion synthetic model returning known logitsCorrect k+1 alignment for \(k=0,1,\ldots,K\)
Greedy real modelsOne same-tokenizer draft/champion pairZero baseline token mismatches
Stochastic real modelsFull-vocabulary residual and RNG contractDistributional tests and numeric conformance pass
Prompt lookupN-gram proposals through same verifierExactness plus model-free performance baseline
Native benchmarkCPU and GPU/native-companion topologiesEnd-to-end break-even gate
Browser WASMWorker cancellation, memory pressure, SIMD kernelsReliability and memory gates
Browser WebGPUq_len=k target kernels, device loss, readback minimizationKernel and tail-latency gates
Adaptive schedulerFixed-policy comparison, then frozen adaptive policyImprovement over best fixed \(k\) without regression
Sealed quality studyFull workload strata and approximate arms, if anyPreregistered quality budget
PromotionFeature flag and clean baseline fallbackAll exactness, performance, memory, privacy, and fault gates
DeletionRemove unsuccessful path and optional artifactsChampion baseline remains bit-for-bit qualified

Clean deletion criteria

Delete rather than retain the speculative path when any of these remains true after the preregistered optimization budget:

  • the target lacks an efficient batched-verification path;
  • greedy mismatches persist under matched identities;
  • stochastic distribution tests fail;
  • draft loading and prefill do not amortize over expected sessions;
  • peak memory violates the product’s supported hardware envelope;
  • the draft raises energy per completed token without an accepted compensating product benefit;
  • gains occur only on repetitive benchmarks and not on designated conversational strata;
  • the scheduler must inspect private content in an unapproved way;
  • cache rollback or cancellation remains unreliable;
  • cross-tokenizer complexity exceeds its demonstrated incremental benefit;
  • the feature cannot be cleanly disabled without branching the champion decoder throughout the codebase.

Unknowns and annotated primary-source bibliography

Facts requiring authorized local verification

The following determine adoption and cannot be resolved from public sources:

  • champion and candidate draft parameter counts, artifact encodings, quantization layouts, tokenizer hashes, vocabulary IDs, templates, adapters, and licenses;
  • whether the target runtime can compute position-aligned \(k+1\) logits in one call;
  • numerical differences between TinyRustLM’s single-token and multi-token q4 kernels;
  • draft and target KV layouts, page sizes, rollback costs, and pending-token semantics;
  • actual browser and native loading peaks, allocator fragmentation, GPU allocation limits, and OOM behavior;
  • prompt-prefill cost for both models and whether either prefill can overlap loading;
  • acceptance \(S_i\) by the required workload strata;
  • whether the draft is bandwidth-bound on the same CPU resources needed by the champion;
  • WebGPU command-submission, synchronization, device-loss, and CPU-readback costs;
  • WASM SIMD availability and fallback behavior across supported browsers;
  • native-companion IPC latency, authentication, cancellation, and privacy boundaries;
  • model artifact deduplication at file, tensor, and content-block levels;
  • actual session-length distribution needed to amortize draft load and prefill;
  • energy measurement availability;
  • exact champion stop-string, grammar, top-\(p\), repetition-penalty, and processor order;
  • whether a self-speculative, MTP, Medusa, or EAGLE-compatible champion artifact exists;
  • whether continuation after EOS requires reusable final KV or always creates a new templated prompt;
  • whether private evaluation permits storing token IDs or only aggregate receipts.

Annotated primary and official sources Retrieval date for every web source below: August 1, 2026.

Source and direct linkRevision or publicationRelevance and caveat
Leviathan, Kalman, and Matias, “Fast Inference from Transformers via Speculative Decoding”ICML/PMLR 2023; original arXiv work began in 2022Foundational exact speculative-decoding algorithm, correctness, expected-token formula, and target-parallelism argument. Reported speedups are not TinyRustLM estimates.
Chen et al., “Accelerating Large Language Model Decoding with Speculative Sampling”arXiv:2302.01318, initially February 2023Foundational stochastic algorithm with draft proposals, target acceptance, positive-part correction, and extra token; primary source for normative reconstruction.
Hugging Face Transformers generation strategiesStable documentation identified as Transformers 5.14.0 at retrievalOfficial current overview of assisted decoding, prompt lookup, self-speculation, MTP, universal assistance, and approximate static ensembling. Exact runtime behavior must be pinned to the version TinyRustLM studies.
Hugging Face, “Faster Assisted Generation with Dynamic Speculation”October 8, 2024; tied to Transformers 4.45.0Official implementation account of confidence-based dynamic lookahead. Its benchmarks are model- and hardware-specific.
Hugging Face Universal Assisted Generation implementation noteOctober 29, 2024; associated with Transformers 4.46.0Describes two-way tokenizer translation, re-encoding, common-suffix alignment, and draft-cache discard. Useful engineering reference, not blanket proof of stochastic exactness across tokenizers.
Hugging Face token-level-intersection updateMarch 24, 2025; associated with Transformers 4.50.0 and arXiv:2502.05202Addresses heterogeneous-vocabulary sampling through vocabulary intersection. TinyRustLM would still need a formal mapping and local conformance proof.
Cai et al., “Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads”arXiv 2024Primary source for multiple future-token heads and tree candidates. Distinguish strict acceptance from typical or relaxed acceptance.
Elhoushi et al., “LayerSkip”2024 paper and Meta public releasePrimary source for early-exit training and self-speculative decoding. Requires checkpoint-level support rather than arbitrary layer skipping.
Gloeckle et al., “Better & Faster Large Language Models via Multi-token Prediction”2024; ICML 2024Primary source for multiple future-token prediction heads. Reported acceleration does not establish compatibility with a TinyRustLM champion.
Li et al., “EAGLE”2024Primary source for feature-level speculative drafting with target verification. Requires model-specific training and integration.
Fu et al., “Lookahead Decoding”2024Primary source for Jacobi-style parallel candidate discovery and verification without an independent small draft model. Higher implementation complexity than linear speculation.
TensorRT-LLM speculative decoding documentationVersion 1.3.0rc20, current release-candidate documentation at retrievalOfficial native/GPU implementation reference covering draft/target, n-gram, EAGLE 3, MTP, suffix automata, and custom drafters. One official example page pins source commit 61cef212a8c59e843521881f45eee262c8f0525d.
vLLM speculative decoding documentationCurrent documentation, reported updated June 23, 2026; repository retrieval also exposed SHA 652ba59229499eb65fc4115b7feadeddf9bcb75d for a contemporaneous code viewUseful reference for current serving-oriented methods and the distinction between algorithmic losslessness and numerical/log-probability stability. Pin the exact feature implementation before reuse.
@@MKREPORTTOKEN0@@Public repository as retrieved August 1, 2026; reviewed speculative documentation was not tied to a sufficiently clear immutable commitRelevant local/native implementation exposing target plus draft operation. Must be commit-pinned before serving as a test oracle.
WebLLM and MLC-LLMPublic repositories retrieved August 1, 2026; changing main branchesRelevant browser-local WebGPU and universal-deployment references. No reviewed source established an exact speculative-sampling implementation suitable as TinyRustLM’s oracle.
Transformers.jsPublic repository retrieved August 1, 2026; changing main branchRelevant browser inference reference using JavaScript, ONNX-related runtimes, WASM, and WebGPU. No reviewed source established the required transactional exact verifier.
W3C WebGPU publication history and WebGPU specificationCandidate Recommendation Draft series through May 21, 2026 in the publication historyAuthoritative browser GPU API reference. TinyRustLM must query actual adapter limits and qualify supported browser/device combinations rather than hard-code specification minima.
WebAssembly specificationsWebAssembly 2.0 generation and SIMD documentation current at retrievalAuthoritative basis for 128-bit SIMD availability and semantics; performance remains browser- and kernel-specific.

Final adoption position. TinyRustLM should implement a removable research branch containing a scalar reference algorithm, transactional cache interface, same-tokenizer greedy mode, and exact stochastic mode. It should compare that branch against champion-alone and prompt lookup before investing in cross-tokenizer assistance, trained heads, self-speculation, or trees. The feature should be promoted only when local evidence shows that a clean implementation preserves the qualified champion and wins the full product cost function—not merely a warm tokens-per-second benchmark.