How b10-tv/speculative-encoding works
The product encodes a document once with a source LLM, translates its hidden states into a target model’s KV cache, optionally compresses that cache for each question, then answers through Hugging Face or vLLM. The graph preserves checkpoint resolution, model/prompt preparation, translator execution, cache handoff and prefix operations, plus multi-target and chained encoding capabilities documented in the README. Several core modules are indexed but not excerpted; their documented roles are included, while unsupported call-level links are omitted.
Main entry points: api.py Encoder API · encode.py Document encoding · vllm_engine.py vLLM answer engine · cli.py CLI commands
Components 23
Encoding workflow
- CLI commands
speculative_encoding/cli.py - Encoder API
speculative_encoding/api.py - Checkpoint resolver
speculative_encoding/checkpoints.py - Model catalog
speculative_encoding/models.py - Questions and prompts
speculative_encoding/prompts.py - Document encoding
speculative_encoding/encode.py
Translation runtime
- Unified translator
speculative_encoding/translator/model.py - HF model boundary
speculative_encoding/translator/hf.py - Fast inference
speculative_encoding/translator/fast_inference.py - Triton kernels
speculative_encoding/translator/kernels.py - Query compressor
speculative_encoding/translator/compressor.py
Answer serving
- HF answer engine
speculative_encoding/serving/hf_engine.py - vLLM answer engine
speculative_encoding/serving/vllm_engine.py - KV cache connector
speculative_encoding/serving/vllm_connector.py - Transformers compatibility
speculative_encoding/serving/transformers_compat.py
Cache and reuse
- Token row handoff
speculative_encoding/handoff.py - Prefix algebra
speculative_encoding/prefix_ops.py - Runtime settings
speculative_encoding/settings.py - Saved cache items
speculative_encoding/api.py
Other components
- Engineer
- Hugging Face
- vLLM runtime
- Hugging Face Hub
Connections 27
- Engineer → CLI commands: runs commands
README.md - Engineer → Encoder API: calls API
README.md - CLI commands → Encoder API: dispatches encode
speculative_encoding/cli.py - CLI commands → Checkpoint resolver: resolves checkpoints
speculative_encoding/cli.py - Encoder API → Checkpoint resolver: loads checkpoint
README.md - Encoder API → Model catalog: loads models
speculative_encoding/api.py - Encoder API → Questions and prompts: builds questions
speculative_encoding/api.py - Encoder API → Document encoding: encodes document
speculative_encoding/api.py - Document encoding → Model catalog: reads source states
speculative_encoding/encode.py - Document encoding → Unified translator: translates states
speculative_encoding/encode.py - Document encoding → Query compressor: compresses per question
speculative_encoding/encode.py - Unified translator → HF model boundary: uses model boundary
speculative_encoding/translator/__init__.py - Unified translator → Fast inference: runs accelerated path
speculative_encoding/translator/fast_inference.py - Fast inference → Triton kernels: invokes kernels
speculative_encoding/translator/fast_inference.py - Encoder API → HF answer engine: answers with HF
speculative_encoding/api.py - HF answer engine → Hugging Face: runs generation
README.md - Encoder API → vLLM answer engine: answers with vLLM
README.md - vLLM answer engine → KV cache connector: registers cache
speculative_encoding/serving/vllm_engine.py - vLLM answer engine → vLLM runtime: submits requests
speculative_encoding/serving/vllm_engine.py - vLLM runtime → KV cache connector: injects KV blocks
speculative_encoding/serving/vllm_connector.py - Checkpoint resolver → Hugging Face Hub: downloads weights
README.md - Encoder API → Saved cache items: saves cache items
README.md - Saved cache items → vLLM answer engine: loads for answering
README.md - Encoder API → Token row handoff: accepts captured rows
README.md - Encoder API → Prefix algebra: supports prefix edits
README.md - Document encoding → Runtime settings: uses runtime controls
speculative_encoding/encode.py - Transformers compatibility → vLLM runtime: patches compatibility
README.md