import { q as TokenizerData, f as InferenceBackend, B as BaseStorage, k as ModelMeta, l as ModelStatus, a as GenerateOptions, G as GenerateResult, C as ChatMessage, d as EngineInfo } from './base-storage-CfkDwX0r.js'; /** * BPE Tokenizer for SmolLM2 / LLaMA Models * * Implements byte-level BPE tokenization with special token handling. */ declare class Tokenizer { private encoder; private decoder; private bpeRanks; private specialTokens; private reverseSpecialTokens; private byteEncoder; private byteDecoder; private chatTemplate?; readonly bosId: number; readonly eosId: number; readonly padId: number; constructor(data: TokenizerData); /** * Get pairs of adjacent characters in a word */ private getPairs; /** * Apply BPE to a word */ private bpe; /** * Encode text to token IDs */ encode(text: string): number[]; /** * Encode ordinary text (no special tokens) */ private encodeOrdinary; /** * Decode token IDs to text */ decode(ids: number[]): string; /** * Format a conversation for chat */ formatChat(messages: Array<{ role: string; content: string; }>, addGenerationPrompt?: boolean): string; /** * Get vocabulary size */ get vocabSize(): number; } /** * Load tokenizer from storage */ declare function loadTokenizer(storage: { getTokenizer(modelId: string): Promise; }, modelId: string): Promise; /** * Base Inference Engine * * Abstract implementation for inference backends. */ declare abstract class BaseInference { abstract readonly backend: InferenceBackend; protected storage: BaseStorage; protected modelId: string; protected config: ModelMeta | null; protected tokenizer: Tokenizer | null; protected status: ModelStatus; protected lastHiddenState: Float32Array | null; constructor(storage: BaseStorage, modelId: string); /** * Initialize the inference engine */ initialize(): Promise; /** * Initialize backend-specific resources (WebGPU, WASM, etc.) */ protected abstract initializeBackend(): Promise; /** * Run forward pass on input tokens */ protected abstract forward(inputIds: number[], position: number): Promise; /** * Generate text from a prompt */ generate(prompt: string, options?: GenerateOptions): Promise; /** * Stream tokens from a prompt */ stream(prompt: string, options?: GenerateOptions): AsyncGenerator; /** * Chat with conversation history */ chat(messages: ChatMessage[], options?: GenerateOptions): Promise; /** * Get embeddings for text */ embed(text: string): Promise; /** * Get last hidden state (for RLHF) */ getLastHiddenState(): Float32Array | null; /** * Get engine info */ getInfo(): EngineInfo; /** * Sample from logits */ protected sample(logits: Float32Array, temperature: number, topP: number, topK: number): number; } /** * WebGPU Inference Engine * * Hardware-accelerated inference using WebGPU compute shaders. */ declare class WebGPUInference extends BaseInference { readonly backend: InferenceBackend; private device; private embeddings; private lmHead; private outputNorm; private currentLayer; private kvCache; constructor(storage: BaseStorage, modelId: string); /** * Initialize WebGPU device and resources */ protected initializeBackend(): Promise; /** * Load embedding and output projection weights */ private loadEmbeddings; /** * Combine tensor chunks into a single Float32Array */ private combineChunks; /** * Load a layer's weights */ private loadLayer; /** * Run forward pass */ protected forward(inputIds: number[], _position: number): Promise; /** * RMS Normalization */ private rmsNorm; /** * Self-attention with RoPE and KV caching */ private selfAttention; /** * Apply Rotary Position Embedding */ private applyRoPE; /** * FFN with SwiGLU activation */ private ffn; /** * Matrix-vector multiplication */ private matmul; /** * Reset KV cache (for new conversation) */ resetCache(): void; } /** * WASM Inference Engine * * Fallback inference using pure JavaScript/WASM. * Slower than WebGPU but works on all browsers. */ declare class WASMInference extends BaseInference { readonly backend: InferenceBackend; private embeddings; private lmHead; private outputNorm; private currentLayer; private kvCache; constructor(storage: BaseStorage, modelId: string); /** * Initialize WASM backend */ protected initializeBackend(): Promise; /** * Load embedding and output projection weights */ private loadEmbeddings; /** * Combine tensor chunks */ private combineChunks; /** * Load a layer's weights */ private loadLayer; /** * Run forward pass (same as WebGPU but pure JS) */ protected forward(inputIds: number[], _position: number): Promise; /** * RMS Normalization */ private rmsNorm; /** * Self-attention with RoPE and KV caching */ private selfAttention; /** * Apply RoPE */ private applyRoPE; /** * FFN with SwiGLU */ private ffn; /** * Matrix-vector multiplication */ private matmul; /** * Reset KV cache */ resetCache(): void; } /** * Inference Engine Factory * * Creates appropriate inference backend based on environment capabilities. */ interface InferenceOptions { /** Preferred inference backend */ backend?: InferenceBackend; /** Force the specified backend even if not optimal */ force?: boolean; /** Use SIMD-optimized WASM (default: true) */ useSIMD?: boolean; } /** * Detect the best available inference backend */ declare function detectBestBackend(): InferenceBackend; /** * Create an inference engine */ declare function createInferenceEngine(storage: BaseStorage, modelId: string, options?: InferenceOptions): Promise; /** * Get inference capabilities info */ declare function getInferenceCapabilities(): { webgpu: boolean; webnn: boolean; wasm: boolean; simd: boolean; recommended: InferenceBackend; }; export { BaseInference as B, type InferenceOptions as I, Tokenizer as T, WASMInference as W, WebGPUInference as a, createInferenceEngine as c, detectBestBackend as d, getInferenceCapabilities as g, loadTokenizer as l };