Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Modal 18 min read Research hardMaster

Quail: Speeding up AI-SQL by jointly optimizing query planner and inference engine

Quail is a query-aware inference layer that jointly optimizes AI-SQL query planning and LLM inference. AI-SQL functions such as AI.IF and AI_JOIN produce large, structured batches of prefill-only requests that each need only a single output token. Because the planner sees the whole query plan up front, it can order requests to maximize KV-cache reuse and evict entries safely, using a revised Hydragen-style cascade attention and KV-aware Pareto join-order search with speed-of-light cost estimates. It also skips decode-specific machinery like sampling, CUDA graphs and speculative decoding. On one multi-join query Quail exceeds a billion tokens per minute per H100, over 10x a vLLM baseline at under 6¢ per billion tokens, and it averages 1.84x faster than vLLM on a new AI-SQL benchmark.

Related posts

  • AI for Systems: Using LLMs to Optimize Database Query Execution

    Together AI hardMaster

    LLMs can act as semantic cardinality estimators that fix join-order mistakes in database physical plans without modifying the engine. DBPlanBench exposes Apache DataFusion's physical operator graph to an LLM through a compact JSON serialization roughly 10x smaller than the native form. GPT-5 proposes localized RFC 6902 JSON Patch edits, such as swapping join sides, and an evolutionary loop keeps only the patches that cut latency. On generated TPC-H and TPC-DS workloads, median speedups were 1.1–1.2x, with up to 4.78x and a drop from 3.3 GB to 411 MB of hash-build memory on one multi-join query. Plans optimized on a small SF3 database transferred to SF10 with similar gains.

  • Accelerating Qwen3-8B Agent on Intel® Core™ Ultra with Depth-Pruned Draft Models

    Hugging Face mediumAdept

    Speculative decoding with a Qwen3-0.6B draft model speeds up 4-bit Qwen3-8B on an Intel Lunar Lake integrated GPU by about 1.3× using OpenVINO.GenAI. Depth-pruning the draft raises that to about 1.4×: 6 of its 28 layers are removed by picking low-contribution blocks via angular distance, then the draft is fine-tuned on Qwen3-8B outputs for 500k Infinity-Instruct prompts. The gain matches the speedup formula, since lower draft latency improves overall throughput. The accelerated pair is demonstrated as a local smolagents agent that uses web search and python-pptx to build a slide deck.

  • Assisted Generation: a new direction toward low-latency text generation

    Hugging Face mediumAdept

    Assisted generation cuts autoregressive LLM latency by letting a much smaller assistant model with the same tokenizer greedily draft candidate tokens, then verifying them all in a single forward pass of the large model. The large model keeps matching tokens plus the first divergent one. The draft length adapts: it grows by 2 when every candidate matches and shrinks by 1 otherwise. The approach exploits the fact that forward passes are memory-bandwidth bound. In 🤗 Transformers it is exposed through an `assistant_model` argument to `generate` (batch size 1 only) and yields up to 2x speedups, 3x with INT8, and up to 10x when the model relies on memory offloading. It works best on input-grounded tasks like ASR and summarization, and with sampling only at low temperatures.

  • Bypassing inference bottlenecks: Accelerating complex AI search with Retrieve-for-Train

    Google Research hardMaster

    Retrieve-for-Train replaces expensive inference-time LLM reasoning for query fan-out with a one-time offline RL stage. A 4B fan-out language model (Gemma3-4B or Qwen3-4B) is trained with Soft-GRPO on a composite set-level reward that combines groundedness to the database manifold, Vendi Score diversity and query alignment. The trained model then synthesizes query-to-target-set pairs, which are distilled into a 53.9M-parameter diffusion retriever that produces a whole slate of target embeddings in one non-autoregressive pass. On fashion (CLIP) and music playlist (MuLan) retrieval it beats zero-shot expansion and Best-of-N, with a 12–20x speedup, staying at sub-second to a few seconds where autoregressive fan-out reaches nearly 50 seconds. Ablations show that without the diversity term the policy reward-hacks into degenerate strings.

  • Continuous batching from first principles

    Hugging Face mediumAdept

    Continuous batching falls out naturally once you optimize LLM serving for throughput, and the post derives it step by step from attention, causal masking, KV caching and chunked prefill. The KV cache cuts the cost of generating each new token from O(n²) to O(n) at O(n) memory, about 16 KB per token per layer for Llama-2-7B in float16. Chunked prefill splits long prompts across forward passes. Padded batched generation wastes compute when prompts finish at different times, and dynamic batching needs heavy padding because newly inserted prompts must prefill while others decode, which motivates continuous batching's mixing of prefill and decode tokens in one forward pass.

The quest for software engineering knowledge.

Look:
Layout: