Lepton AI Platform
The LeptonAI Python library is a framework designed to simplify AI service building, enabling developers to convert research and modeling code into production-ready services with minimal Python. It provides abstractions for launching models from platforms like HuggingFace, includes AI-tailored features such as autobatching and background jobs, and offers a Python client for interacting with deployed services as native functions. The library also comes with a command-line interface (`lep`) for local and cloud service management. Currently at version 0.27.0, it maintains an active development and release cadence with frequent updates.
Warnings
- gotcha Not all HuggingFace models are supported out-of-the-box. Models containing custom code or non-standard pipelines may not function directly with LeptonAI's abstractions.
- gotcha When attempting to use Llama2 models, it is crucial to specify the HuggingFace-compatible version (e.g., `hf:meta-llama/Llama-2-7b-chat-hf`) to ensure proper integration with LeptonAI's pipelines.
- gotcha While `pip install leptonai` installs the core library, many advanced examples or specific AI models (e.g., for image generation, specific LLMs) require additional Python dependencies. These are often not automatically installed with the base package.
- gotcha Accessing remote Lepton AI services or certain gated HuggingFace models often requires authentication. This typically involves using the `lep login` command via the CLI or setting API tokens (e.g., `LEPTON_API_TOKEN`, `HUGGING_FACE_HUB_TOKEN`) as environment variables.
- breaking Reports indicate a potential acquisition of Lepton AI by Nvidia and rebranding to DGX Cloud Lepton. This may lead to changes in platform access, features, and pricing models for standalone users in future versions.
Install
-
pip install -U leptonai
Imports
- Client, local
from leptonai.client import Client, local
- Photon
from leptonai.photon import Photon
Quickstart
import os
from leptonai.client import Client, local
# NOTE: This example assumes you have run 'lep photon runlocal --name gpt2 --model hf:gpt2' in your terminal.
# It also requires the Lepton AI CLI to be installed and potentially HuggingFace credentials
# if you're using models that require them (set HUGGING_FACE_HUB_TOKEN env var).
# Initialize client for local service running on port 8080
c = Client(local(port=8080))
# Check available paths (endpoints) of the deployed service
print(f"Available paths: {c.paths()}")
# Call the 'run' method of the gpt2 model
response = c.run(inputs="I enjoy walking with my cute dog, and")
print(f"Model response: {response}")
# Example of using a remote client (replace with your actual workspace/token/deployment)
# from leptonai.client import Client
# LEPTIN_API_TOKEN = os.environ.get('LEPTON_API_TOKEN', 'YOUR_LEPTON_API_TOKEN')
# # If you have a specific workspace_id and deployment_id
# # remote_client = Client(f"workspace_id", "deployment_id", token=LEPTIN_API_TOKEN)
# # Or if using a direct URL:
# # remote_client = Client("https://your-deployment-url.lepton.run/api", token=LEPTIN_API_TOKEN)
# # response = remote_client.run(inputs="What is Lepton AI?")
# # print(f"Remote model response: {response}")