llm2slm
A robust Python library and CLI tool for converting Large Language Models (LLMs) to optimized Small Language Models (SLMs). Streamline model deployment with provider integrations, containerization, and API access.
A robust Python library and CLI tool for converting Large Language Models (LLMs) to optimized Small Language Models (SLMs). Streamline model deployment with provider integrations, containerization, and API access.
Features
- CLI Interface: Command-line tools for seamless model conversion and management.
- Provider Integrations: Support for OpenAI, Anthropic, Google Gemini, and LiquidAI providers.
- Server API: FastAPI-based REST API for remote model operations.
- Docker Support: Containerized deployment for easy scaling.
- CI/CD Pipelines: Automated testing and deployment via GitHub Actions.
- Comprehensive Testing: High-coverage pytest suite with type hints and docstrings.
- Error Handling & Logging: Robust logging and exception management.
- Semantic Versioning: Predictable release cycles.
Installation
Prerequisites
- Python 3.8 or higher
- pip (Python package installer)
Install from PyPI
pip install llm2slm
Install from Source
git clone https://github.com/Kolerr-Lab/llm2slm-oss.git
cd llm2slm
pip install -e .
Docker Installation
docker build -t llm2slm .
docker run -p 8000:8000 llm2slm
Usage
CLI
Show version:
llm2slm version
List available providers:
llm2slm providers
Validate setup:
llm2slm validate
Convert an LLM to SLM:
# Using OpenAI (default)
llm2slm convert openai/gpt-4 ./my-slm --provider openai --compression-factor 0.5
# Using Anthropic Claude
llm2slm convert claude-3-opus-20240229 ./my-slm --provider anthropic --compression-factor 0.5
# Using Google Gemini
llm2slm convert gemini-pro ./my-slm --provider google --compression-factor 0.5
# Using LiquidAI
llm2slm convert liquid-1.0 ./my-slm --provider liquid --compression-factor 0.5
API Server
Start the server:
llm2slm serve --host 0.0.0.0 --port 8000
Example API request:
curl -X POST "http://localhost:8000/convert" \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-4", "output": "my-slm"}'
Python Library
from llm2slm import convert_model
# Convert a model using OpenAI
result = await convert_model(
input_model="openai/gpt-4",
output_path="./my-slm",
provider="openai",
compression_factor=0.5
)
# Convert using Anthropic
result = await convert_model(
input_model="claude-3-opus-20240229",
output_path="./my-slm",
provider="anthropic",
compression_factor=0.5
)
# Convert using Google Gemini
result = await convert_model(
input_model="gemini-pro",
output_path="./my-slm",
provider="google",
compression_factor=0.5
)
## Configuration
Configure providers via environment variables:
- `OPENAI_API_KEY`: Your OpenAI API key
- `ANTHROPIC_API_KEY`: Your Anthropic API key
- `GOOGLE_API_KEY`: Your Google API key
- `LIQUID_API_KEY`: Your LiquidAI API key
Or use the CLI config commands:
```bash
llm2slm config --set OPENAI_API_KEY your-openai-key-here
llm2slm config --set ANTHROPIC_API_KEY your-anthropic-key-here
llm2slm config --set GOOGLE_API_KEY your-google-key-here
llm2slm config --set LIQUID_API_KEY your-liquid-key-here
Development
Setup
pip install -r requirements-dev.txt
pre-commit install
Testing
pytest --cov=llm2slm
Building
python -m build
Project Structure
src/llm2slm/
├── __init__.py # Package initialization and version info
├── cli.py # Command-line interface
├── core/ # Core functionality
│ ├── __init__.py
│ ├── config.py # Configuration management
│ └── pipeline.py # Conversion pipeline
├── providers/ # LLM provider integrations
│ ├── __init__.py
│ ├── base.py # Base provider interface
│ └── openai.py # OpenAI provider implementation
├── server/ # FastAPI server
│ ├── __init__.py
│ └── app.py # FastAPI application
└── slm/ # Small Language Model components
├── __init__.py
├── benchmark.py # Performance benchmarking
├── export.py # Model export functionality
├── loaders.py # Model loading with factory pattern
├── metadata.py # Metadata creation
├── model.py # SLM model representation
└── runtime.py # SLM runtime management
Contact & Support
- Primary Author: Ricky Kolerr ricky@kolerr.com
- Community Support: Kolerr Lab lab.kolerr@kolerr.com
- Repository: https://github.com/Kolerr-Lab/llm2slm-oss
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Fork the repository.
- Create a feature branch.
- Add tests and ensure coverage.
- Submit a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for version history.
Metadata
Release files for llm2slm 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm2slm-0.1.0.tar.gz | 43.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm2slm-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 81.3 kB
Release files / llm2slm-0.1.0.tar.gz
| Download URL | llm2slm-0.1.0.tar.gz |
|---|---|
| Size | 43.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
895c3d711bd22c728fff86baa8c13ace6d1f446b10dba8f8e23de4215ab3f0d2
|
|
BLAKE2b-256 checksum How to use checksums |
3829aaa7987657eec07d0800f3a448ceaeabefcbfbd2f863191de2201f937bb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.6
|
Release files / llm2slm-0.1.0-py3-none-any.whl
| Download URL | llm2slm-0.1.0-py3-none-any.whl |
|---|---|
| Size | 38.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
197335917df8cba9d166c7db09a63895c3b1aadd774cc0fa6fa62e7b9144ab3e
|
|
BLAKE2b-256 checksum How to use checksums |
6f2c66e6e050ddd6dfb61d99d9d0c1c5aeda4a8d804fd3862c343fd03bcadffd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.6
|
Security for llm2slm 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.