Skip to main content

Browser-native LLM orchestration in JupyterLite

Project description

lmLite

Browser-native LLM orchestration in JupyterLite - run language models entirely in your browser using WebAssembly.

Features

  • Browser-native: Run LLMs entirely in the browser, no server required
  • Zero setup: No installation, no API keys, works offline
  • Privacy-first: All computation happens locally in your browser
  • Multiple models: Support for GPT-2, DistilGPT-2, and more via Transformers.js
  • Embeddings: Generate text embeddings for semantic search
  • Similarity search: Built-in cosine similarity for RAG applications
  • Model caching: Download once, use offline forever
  • Pythonic API: Clean, async Python interface

Usage

from lmlite import LLM

# Create LLM instance (downloads model on first run)
llm = await LLM.create(generator_model="gpt2")

# Generate text
text = await llm.generate("Python is a great language because")
print(text)

# Generate embeddings
embedding = await llm.embed("Hello world")
print(embedding[:5])  # First 5 dimensions

# Similarity search
docs = [
    "JupyterLite runs entirely in the browser.",
    "Python is widely used for machine learning.",
    "TypeScript is great for frontend applications.",
]

results = await llm.similarity_search(
    "Where does JupyterLite run?",
    docs
)

for doc, score in results:
    print(f"{score:.3f} -> {doc}")

Configuration Options

llm = await LLM.create(
    generator_model="gpt2",           # or "distilgpt2", etc.
    embedding_model="all-MiniLM-L6-v2",
    max_new_tokens=50,
    temperature=0.7,
    top_k=50,
    do_sample=True,
    use_local_models=False,           # Auto-detect local models
    local_models_path="/drive/models"
)

Export Models for Offline Use

After using models in the browser, you can export them for offline use:

# Export to zip file (default)
await llm.export_model_files("gpt2")

# Export to directory
await llm.export_model_files("gpt2", as_zip=False)

The exported files will be saved to /drive/models/ and can be downloaded from JupyterLite.

Development

Prerequisites

  • pixi - Package manager (required)
  • micromamba - Conda package manager (required for JupyterLite builds)

Supported Platforms: macOS (Intel/Apple Silicon) and Linux. Windows is not currently supported for development.

Setup

# Clone the repository
git clone https://github.com/decitre/lmlite.git
cd lmlite
pixi install

Development Tasks

# Run tests
pixi run test

# Quick tests (skip notebook tests)
pixi run quick-test

# Run linter
pixi run lint

# Check linting without fixing
pixi run lint-check

# Run tests with coverage
pixi run coverage

# Build wheel
pixi run wheel

Build JupyterLite Demo

pixi run lite-build

Follow the instructions provided by the command.

Run Tests in Different Python Versions

pixi run --environment py311 test
pixi run --environment py312 test
pixi run --environment py313 test

How It Works

LMLite bridges Python (via xeus-python or pyodide) and JavaScript (via Transformers.js):

  1. JavaScript Layer: Uses @huggingface/transformers to run ONNX models in the browser
  2. Python Bridge: Exposes JavaScript functionality through a Pythonic async API
  3. Kernel Support:
    • xeus-python (recommended): Full CPython in WebAssembly via emscripten
    • pyodide: Alternative WebAssembly Python runtime
  4. Model Loading:
    • First run: Downloads models from HuggingFace CDN
    • Cached: Uses browser's Cache API or IndexedDB
    • Local: Reads from virtual filesystem if available
  5. Execution: Models run entirely in-browser using WebAssembly (WASM)

Supported Models

Text Generation

  • gpt2 - GPT-2 (124M parameters)
  • distilgpt2 - Smaller, faster GPT-2 variant

Embeddings

  • all-MiniLM-L6-v2 - Sentence embeddings (384 dimensions)

For other models, check Xenova's model list.

Architecture

┌─────────────────────────────────────┐
│   Python (JupyterLite)              │
│   ├─ xeus-python (recommended)      │
│   └─ pyodide (alternative)          │
│                                     │
│   from lmlite import LLM            │
│   llm = await LLM.create()          │
│   text = await llm.generate(...)    │
└─────────────┬───────────────────────┘
              │ Bridge
              │ (pyodide.ffi / pjs)
┌─────────────▼───────────────────────┐
│   JavaScript (Browser)              │
│                                     │
│   Transformers.js                   │
│   ├─ Model loading                  │
│   ├─ ONNX Runtime (WASM)            │
│   └─ WebGPU (optional)              │
└─────────────────────────────────────┘

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Dependencies:

Note: Individual model licenses may vary. Check the model card on HuggingFace before use.

Acknowledgments

Troubleshooting

Models downloading every time?

Check browser console for Cache API availability. Some privacy settings may disable caching.

Out of memory errors?

Try smaller models like distilgpt2 or reduce max_new_tokens.

CORS errors?

Ensure you're running from http://localhost or a proper HTTPS domain, not file://.

Citation

If you use LMLite in your research, please cite:

@software{lmlite2026,
  author = {Decitre, Emmanuel},
  title = {LMLite: Browser-native LLM orchestration in JupyterLite},
  year = {2026},
  url = {https://github.com/decitre/lmlite}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lmlite-0.2.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lmlite-0.2.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file lmlite-0.2.1.tar.gz.

File metadata

  • Download URL: lmlite-0.2.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for lmlite-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a0be8154534b98a07eb44278bc43c8a1b4997cac82e4983a08b45392ee4964a6
MD5 acdc029a3a6a0791ef30a39ef2b1a1d6
BLAKE2b-256 94afc8a807018ca9495b882a03d4f6d0e4a2ba99055ede39ea0aace0159b28dd

See more details on using hashes here.

File details

Details for the file lmlite-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: lmlite-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for lmlite-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c149b2fd3f5443d96f5bc214b4a5ac87188b23832bae25705cdb1c2fd9f72185
MD5 7295868592263affb67b893bf42bfc9d
BLAKE2b-256 b818c752583a24bf459b757f25d7e46d7ef92045f67ce52c4e3ff0f3552f0805

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page