sageLLM backend provider abstraction (CPU/CUDA/Ascend)
Project description
sagellm-backend
Protocol Compliance (Mandatory)
- MUST follow Protocol v0.1: https://github.com/intellistream/sagellm-docs/blob/main/docs/specs/protocol_v0.1.md
- Any globally shared definitions (fields, error codes, metrics, IDs, schemas) MUST be added to Protocol first.
硬件抽象层 - 为 sageLLM 提供统一的硬件接口(CUDA/Ascend/Kunlun)
架构定位
┌─────────────────────────────────────────────────────────────┐
│ sagellm-core (引擎协调层) │
│ • LLMEngine (硬件无关的统一引擎) │
│ • 自动选择最佳后端 (cuda > ascend > cpu) │
├─────────────────────────────────────────────────────────────┤
│ sagellm-backend (硬件抽象层) ← 本仓库 │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ BackendProvider Interface │ │
│ │ • Stream/Event 异步流 │ │
│ │ • KVBlock 内存管理 │ │
│ │ • Collective 操作(all_reduce/all_gather) │ │
│ └─────────────────────────────────────────────────────┘ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ CUDA │ │ Ascend │ │ Kunlun │ │
│ │ Provider │ │ Provider │ │ Provider │ │
│ └──────────┘ └──────────┘ └──────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Hardware SDK Layer │
│ CUDA/cuDNN/NCCL │ CANN/HCCL │ XPU SDK │ DCU SDK │
└─────────────────────────────────────────────────────────────┘
职责分离(v0.2.0 重构):
- ✅ 本仓库负责:硬件抽象、设备管理、内存原语
- ❌ 不再包含:BaseEngine, EngineFactory(已移至 sagellm-core)
- 🔗 被使用于:sagellm-core 中的引擎实现
Features
- 统一硬件抽象:单一 API 支持多硬件后端
- CPU Backend:无 GPU 环境的默认后端
- CUDA Support:原生 CUDA 后端实现
- CPU Support:CPU-only 后端实现
- 能力发现:硬件能力查询与验证
Installation
pip install isagellm-backend
Quick Start
git clone git@github.com:intellistream/sagellm-backend.git
cd sagellm-backend
./quickstart.sh
# Run tests
pytest tests/ -v
Usage Examples
Basic Backend Usage
from sagellm_backend import CPUBackendProvider, DType
# Create backend
backend = CPUBackendProvider()
# Query capabilities
cap = backend.capability()
print(cap.supported_dtypes)
# Allocate KV block
block = backend.kv_block_alloc(128, DType.FP16)
Using with sagellm-core LLMEngine
Backend 现在专注于硬件抽象,引擎使用 sagellm-core 的 LLMEngine。
# LLMEngine 位于 sagellm-core
from sagellm_core import LLMEngine, LLMEngineConfig
# LLMEngine 自动选择最佳后端
config = LLMEngineConfig(
model_path="TinyLlama/TinyLlama-1.1B-Chat-v1.0",
backend_type="auto", # 自动选择: cuda > ascend > cpu
max_new_tokens=100,
)
engine = LLMEngine(config)
await engine.start()
# 推理
output = await engine.generate("Hello, world!")
print(output)
await engine.stop()
Extending with New Backends
# Create provider in providers/ directory
class AscendBackendProvider:
def capability(self) -> CapabilityDescriptor:
return CapabilityDescriptor(
supported_dtypes=[DType.FP16, DType.BF16, DType.INT8],
# ...
)
# Implement other interface methods...
# Register via entry point in pyproject.toml
[project.entry-points."sagellm.backends"]
ascend_cann = "sagellm_backend.providers.ascend:create_ascend_backend"
Documentation
🔄 贡献指南
请遵循以下工作流程:
-
创建 Issue - 描述问题/需求
gh issue create --title "[Bug] 描述" --label "bug,sagellm-backend"
-
开发修复 - 在本地
fix/#123-xxx分支解决git checkout -b fix/#123-xxx origin/main-dev # 开发、测试... pytest -v ruff format . && ruff check . --fix
-
发起 PR - 提交到
main-dev分支gh pr create --base main-dev --title "Fix: 描述" --body "Closes #123"
-
合并 - 审批后合并到
main-dev
更多详情见 .github/copilot-instructions.md
License
Proprietary
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 Distribution
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 isagellm_backend-0.4.0.9.tar.gz.
File metadata
- Download URL: isagellm_backend-0.4.0.9.tar.gz
- Upload date:
- Size: 85.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a91a4b7c50a3ef35b4f542daa9cc02ae92985cec514ea90238893982b36b1e58
|
|
| MD5 |
3e133d19e7b33967ecddf97d5728ddac
|
|
| BLAKE2b-256 |
cf2805942496795e9eda3c189e56d3c92071e7978188aa1677ffe69e3b244c7a
|
File details
Details for the file isagellm_backend-0.4.0.9-py2.py3-none-any.whl.
File metadata
- Download URL: isagellm_backend-0.4.0.9-py2.py3-none-any.whl
- Upload date:
- Size: 139.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01d7ed74e2c2392d289bf6df0a177466a859618e31681f04fa3bcb8459e99f61
|
|
| MD5 |
d6286874b1b74446253eec896be5dbf0
|
|
| BLAKE2b-256 |
440db36e166d108205e3f9dfeeec8c2d4d266dbb7dce253adf2e7491b3cd4ec1
|