lmql  by eth-sri

LMQL: Language for constraint-guided LLM programming

Created 3 years ago
4,120 stars

Top 11.9% on SourcePulse

GitHubView on GitHub
Project Summary

LMQL is a Python-based programming language designed for efficient and constraint-guided interaction with Large Language Models (LLMs). It allows developers to seamlessly integrate LLM calls within traditional Python code, offering fine-grained control over model output through a declarative constraint language and advanced decoding strategies.

How It Works

LMQL treats top-level strings as LLM queries, enabling direct integration of LLM interactions into Python programs. It supports features like multi-variable templates, conditional distributions, and data type constraints via logit masking. The language leverages speculative execution and tree-based caching for optimized runtime performance, supporting synchronous and asynchronous APIs for parallel query execution.

Quick Start & Requirements

  • Install via pip: pip install lmql
  • For local GPU support (PyTorch >= 1.11): pip install lmql[hf]
  • Running the playground IDE requires Node.js.
  • OpenAI API key configuration is necessary for using OpenAI models.
  • Tested OS: Ubuntu 22.04 (CUDA 12.0), Windows 10 via WSL2 (CUDA 11.7) for GPU; Ubuntu 22.04, macOS 13.2, Windows 10 via WSL2 for non-GPU.
  • Documentation: Explore Examples, Playground IDE

Highlighted Details

  • Python syntax integration for LLM queries.
  • Advanced decoding techniques (beam search, best_k).
  • Logit masking for output constraints (token length, data types, stopping phrases).
  • Optimized runtime with speculative execution and constraint short-circuiting.
  • Multi-model support (OpenAI, Azure OpenAI, Hugging Face Transformers).
  • Integrates with LangChain and LlamaIndex.
  • Offers an interactive Playground IDE and VS Code Extension.

Maintenance & Community

  • Community-centric project with contribution guidelines.
  • Discord server available for community interaction.

Licensing & Compatibility

  • License: MIT.
  • Compatible with commercial use and closed-source linking.

Limitations & Caveats

The bleeding-edge development version installed via pip install git+https://github.com/eth-sri/lmql is not continuously tested and may be less stable. The non-GPU version only supports API-integrated models.

Health Check
Last Commit

7 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
30 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Sebastian Raschka Sebastian Raschka(Author of "Build a Large Language Model (From Scratch)"), and
11 more.

optillm by algorithmicsuperintelligence

0.5%
3k
Optimizing inference proxy for LLMs
Created 1 year ago
Updated 2 weeks ago
Feedback? Help us improve.