/**
 * Speculative Decoding Support
 *
 * Implements speculative decoding for faster inference:
 * - Uses a small "draft" model to propose tokens quickly
 * - Uses the main "target" model to verify/correct proposals
 * - Can achieve 2-3x speedup for autoregressive generation
 *
 * Based on: "Fast Inference from Transformers via Speculative Decoding"
 * (Leviathan et al., 2023)
 */
import { EventEmitter } from 'events';
export interface SpeculativeConfig {
    /** Draft model identifier */
    draftModel: string;
    /** Target model identifier */
    targetModel: string;
    /** Number of tokens to speculate ahead */
    speculationLength: number;
    /** Minimum acceptance rate to keep using speculation */
    minAcceptanceRate: number;
    /** Whether to enable adaptive speculation length */
    adaptiveLength: boolean;
    /** Temperature for draft model */
    draftTemperature: number;
    /** Temperature for target model */
    targetTemperature: number;
}
export interface SpeculativeStats {
    /** Total tokens generated */
    totalTokens: number;
    /** Tokens accepted from draft */
    acceptedTokens: number;
    /** Tokens rejected (replaced by target) */
    rejectedTokens: number;
    /** Current acceptance rate */
    acceptanceRate: number;
    /** Average tokens per speculation round */
    avgTokensPerRound: number;
    /** Speedup factor compared to target-only */
    estimatedSpeedup: number;
    /** Total speculation rounds */
    speculationRounds: number;
}
export interface DraftProposal {
    /** Proposed token IDs */
    tokens: number[];
    /** Log probabilities from draft model */
    logprobs: number[];
    /** Time taken for draft (ms) */
    draftTimeMs: number;
}
export interface VerificationResult {
    /** Number of accepted tokens (0 to speculationLength) */
    accepted: number;
    /** Final tokens after verification */
    finalTokens: number[];
    /** Time taken for verification (ms) */
    verifyTimeMs: number;
    /** Whether all tokens were accepted */
    fullAccept: boolean;
}
export type DraftModelCallback = (prompt: string, numTokens: number) => Promise<DraftProposal>;
export type TargetModelCallback = (prompt: string, draftTokens: number[]) => Promise<VerificationResult>;
export declare const DEFAULT_SPECULATIVE_CONFIG: SpeculativeConfig;
export interface ModelPair {
    draft: string;
    target: string;
    description: string;
    expectedSpeedup: number;
}
export declare const RECOMMENDED_PAIRS: ModelPair[];
export declare class SpeculativeDecoder extends EventEmitter {
    private config;
    private stats;
    private isRunning;
    private currentSpecLength;
    constructor(config?: Partial<SpeculativeConfig>);
    private initStats;
    /**
     * Run speculative decoding for a generation task
     */
    generate(prompt: string, maxTokens: number, draftCallback: DraftModelCallback, targetCallback: TargetModelCallback, onToken?: (token: number) => void): Promise<{
        tokens: number[];
        stats: SpeculativeStats;
    }>;
    /**
     * Update statistics after a speculation round
     */
    private updateStats;
    /**
     * Adapt speculation length based on acceptance rate
     */
    private adaptSpeculationLength;
    /**
     * Update prompt with new tokens (placeholder - actual implementation depends on tokenizer)
     */
    private updatePrompt;
    /**
     * Check if speculative decoding is beneficial for current context
     */
    shouldUseSpeculation(): boolean;
    /**
     * Get recommended model pair for a target model
     */
    static getRecommendedDraft(targetModel: string): ModelPair | null;
    /**
     * Generate llama.cpp speculative decoding arguments
     */
    generateLlamaCppArgs(): string[];
    /**
     * Get current configuration
     */
    getConfig(): SpeculativeConfig;
    /**
     * Update configuration
     */
    updateConfig(config: Partial<SpeculativeConfig>): void;
    /**
     * Get current statistics
     */
    getStats(): SpeculativeStats;
    /**
     * Reset statistics
     */
    resetStats(): void;
    /**
     * Format statistics for display
     */
    formatStats(): string;
    /**
     * Dispose and clean up resources
     */
    dispose(): void;
}
/**
 * Create a mock draft callback for testing
 */
export declare function createMockDraftCallback(_acceptanceRate?: number): DraftModelCallback;
/**
 * Create a mock target callback for testing
 */
export declare function createMockTargetCallback(acceptanceRate?: number): TargetModelCallback;
export declare function getSpeculativeDecoder(config?: Partial<SpeculativeConfig>): SpeculativeDecoder;
export declare function resetSpeculativeDecoder(): void;
