A lightweight LLM inference framework
Project description
light-llm-hp - 轻量级 LLM 推理框架
在 CPU 上运行的简化推理框架,支持 REST API 服务。
快速开始
from hllm import HLLM
# 初始化模型
model = HLLM(model_path="microsoft/Phi-3-mini-4k-instruct", device="cpu")
# 生成文本
result = model.generate("Write a short story about a robot.")
print(result)
REST API 服务
安装 API 依赖
pip install light-llm-hp[api]
启动服务
from hllm import HLLM
from hllm.server import Server
model = HLLM(model_path="./TinyLlama-1.1B-Chat-v1.0", device="cpu")
server = Server(model, host="0.0.0.0", port=8000)
server.start()
或通过命令行:
python -m hllm.server --model ./TinyLlama-1.1B-Chat-v1.0 --port 8000
API 端点
| 端点 | 方法 | 说明 |
|---|---|---|
/health |
GET | 健康检查 |
/models |
GET | 模型信息 |
/generate |
POST | 文本生成 |
/chat |
POST | 对话生成 |
/generate/stream |
POST | 流式生成 (SSE) |
使用客户端
from hllm.client import HLLMClient
client = HLLMClient("http://localhost:8000")
# 生成文本
response = client.generate("Hello, how are you?")
print(response.text)
# 对话
response = client.chat([
{"role": "user", "content": "What is AI?"}
])
print(response.message.content)
# 流式生成
for chunk in client.generate_stream("Tell me a story"):
print(chunk.token, end="", flush=True)
详细 API 文档见 docs/api.md。
目录结构
hllm/
├── hllm/ # 核心模块
│ ├── __init__.py
│ ├── model.py # 模型加载与推理
│ ├── tokenizer.py # 分词器封装
│ ├── generate.py # 生成逻辑
│ ├── server.py # REST API 服务端
│ └── client.py # REST API 客户端
├── tests/ # 测试
├── examples/ # 示例
└── docs/ # 文档
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file light_llm_hp-0.3.0-py3-none-any.whl.
File metadata
- Download URL: light_llm_hp-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f428f35b0e8e94de54d6ac52d459523d2a3597206cb3bf6b29abb85c5e9f8aa
|
|
| MD5 |
ab8a4c725c9dd80dd4e241fa4168faf5
|
|
| BLAKE2b-256 |
4cd7235ea50f40deaae29e3949fbe709333ef74eadf4eaa315800b31b6ae6323
|