Skip to main content

A toolkit for managing and testing LM Studio models with automatic context limit discovery

Project description

LMStrix is a professional, installable Python toolkit designed to supercharge your interaction with LM Studio. It provides a powerful command-line interface (CLI) and a clean Python API for managing, testing, and running local language models, with a standout feature: the Adaptive Context Optimizer.

Current version: 1.0.53 - Enhanced CLI features, full synchronous architecture, and improved safety controls.

For the full documentation, please visit the LMStrix GitHub Pages site.

Key Features

  • Automatic Context Optimization: Discover the true context limit of any model with the test command, featuring safety thresholds and batch testing.
  • Full Model Management: Programmatically list available models with sorting and multiple output formats, and scan for newly downloaded ones.
  • Flexible Inference Engine: Run inference with a powerful two-phase prompt templating system that separates prompt structure from its content.
  • Rich CLI: A beautiful and intuitive command-line interface built with rich and fire.
  • Modern Python API: A fully synchronous API for reliable and straightforward integration.

Installation

# Using pip
pip install lmstrix

# Using uv (recommended)
uv pip install lmstrix

For more detailed installation instructions, see the Installation page.

Quick Start

Command-Line Interface (CLI)

# First, scan for available models in LM Studio
lmstrix scan

# List all models with their test status
lmstrix list

# Test the context limit for a specific model
lmstrix test "model-id-here"

# Test all untested models with enhanced safety controls
lmstrix test --all --threshold 102400

# Test all models at a specific context size
lmstrix test --all --ctx 32768

# Sort and filter model listings
lmstrix list --sort size_gb  # Sort by model size descending
lmstrix list --show json --sort name  # Export as JSON sorted by model name
lmstrix list --show id  # Get plain list of model IDs
lmstrix list --show path  # Get newline-delimited paths

# Run inference on a model
lmstrix infer "Your prompt here" --model "model-id" --max-tokens 150

Python API

import asyncio
from lmstrix import LMStrix

async def main():
    # Initialize the client
    lms = LMStrix()
    
    # Scan for available models
    lms.scan_models()
    
    # List all models
    models = lms.list_models()
    print(models)
    
    # Test a specific model's context limits
    model_id = models[0].id if models else None
    if model_id:
        result = lms.test_model(model_id)
        print(result)
    
    # Run inference
    if model_id:
        response = await lms.infer(
            prompt="What is the meaning of life?",
            model_id=model_id,
            max_tokens=100
        )
        print(response.content)

if __name__ == "__main__":
    asyncio.run(main())

For more detailed usage instructions and examples, see the Usage page and the API Reference.

Enhanced Testing Strategy

LMStrix uses a sophisticated testing algorithm to safely and efficiently discover true model context limits:

Safety Features

  • Threshold Protection: Default 102,400 token limit prevents system crashes from oversized contexts.

Testing Algorithm

  1. Initial Verification: Tests at a small context size (1024) to verify the model loads correctly.
  2. Threshold Test: Tests at the min(threshold, declared_limit) to safely assess the initial context window.
  3. Binary Search: If the threshold test fails, it performs an efficient binary search to find the exact context limit.
  4. Progress Persistence: Saves results after each test for resumable operations.

Multi-Model Optimization

  • Batch Processing: The --all flag allows for testing multiple models sequentially.
  • Rich Output: Displays results in a clear table, showing the tested context size and status.

Development

# Clone the repository
git clone https://github.com/twardoch/lmstrix
cd lmstrix

# Install in development mode with all dependencies
pip install -e ".[dev]"

# Run the test suite
pytest

Changelog

All notable changes to this project are documented in the CHANGELOG.md file.

License

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

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

lmstrix-1.0.54.tar.gz (68.9 kB view details)

Uploaded Source

Built Distribution

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

lmstrix-1.0.54-py3-none-any.whl (58.2 kB view details)

Uploaded Python 3

File details

Details for the file lmstrix-1.0.54.tar.gz.

File metadata

  • Download URL: lmstrix-1.0.54.tar.gz
  • Upload date:
  • Size: 68.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for lmstrix-1.0.54.tar.gz
Algorithm Hash digest
SHA256 34daaaadc4a77c3118a747ec2201a1dbe05e8c56067a938d7263a6d9c3562748
MD5 3875c73b8f4939c47d709354525053e7
BLAKE2b-256 64d8c900d241fac4f17db9b34efa225c160c606f39ba3caaf5c741ce5e2f12e0

See more details on using hashes here.

File details

Details for the file lmstrix-1.0.54-py3-none-any.whl.

File metadata

  • Download URL: lmstrix-1.0.54-py3-none-any.whl
  • Upload date:
  • Size: 58.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for lmstrix-1.0.54-py3-none-any.whl
Algorithm Hash digest
SHA256 a11210d4b912a555cf9a314ef42b90e30e28055e932092d08096959810043f7e
MD5 559ebbed0d941fa8ea1566dea3a670d2
BLAKE2b-256 0483e77b18313fcc909786cfca2fc0fc2f315a234b5a8ac996b81569dc9aee4a

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