Class SpeculativeDecoding

java.lang.Object
smile.llm.engine.SpeculativeDecoding

public final class SpeculativeDecoding extends Object
Greedy speculative accept/reject helpers (Leviathan-style prefix match).

Given draft tokens d[0..N) and target samples t[0..N] (length N+1, where t[i] is the target sample at draft depth i and t[N] is the bonus after a full accept), accept the longest prefix where t[i] == d[i] and always emit the bonus token t[r] for r accepted drafts.

  • Method Details

    • acceptGreedy

      public static SpeculativeDecoding.AcceptResult acceptGreedy(int[] drafts, int[] targetSamples)
      Greedy accept: exact match between draft and target samples.
      Parameters:
      drafts - draft token ids [N] (N >= 1).
      targetSamples - target samples [N+1] (greedy argmax per verify position).
      Returns:
      accept result with r+1 tokens.