Skip to content

feat: add hardware platform and plugin support - #1565

Open
zhangts20 wants to merge 1 commit into
mainfrom
hardware-platform-plugin
Open

feat: add hardware platform and plugin support#1565
zhangts20 wants to merge 1 commit into
mainfrom
hardware-platform-plugin

Conversation

@zhangts20

Copy link
Copy Markdown
Collaborator

No description provided.

@zhangts20

Copy link
Copy Markdown
Collaborator Author

简介

把硬件抽象和第三方插件拆成两层,方便后续其他硬件以及 pip 的注册,当前提交不涉及现有推理路径。对外入口是 get_hardware_backend,当前还未被调用,启动服务不会涉及本地提交代码。

lightllm/platform/
├── __init__.py
├── backends
│   ├── __init__.py
│   └── cuda_like
│       ├── __init__.py
│       ├── graph.py
│       └── runtime.py
├── base
│   ├── __init__.py
│   ├── backend.py
│   ├── graph.py
│   ├── registry.py
│   └── runtime.py
└── plugin
    ├── __init__.py
    ├── att.py
    ├── common.py
    └── ops.py

backends 下面放置具体的硬件后端时间,包括 graphruntime 等;base 是所有基类以及 HardwareBackend 的注册;plugin 实现 pip-installed 包的注册;__init__.py 提供对外接口 get_hardware_backend 用来初始化全局实例。

做法

  • 硬件 backendHardwareBackend + @register_platform,现以注册 cudaCudaLikeBackend)为例。
  • Plugin 加载pip entry point -> CLI 匹配 -> register 返回 modules -> import module -> 写入注册表。
  • CLI--extra_ops / --extra_att(逗号分隔,对应 entry point 的左边名字)。

入口只有 get_hardware_backend():先 configure_plugins(),再按 hardware_platform 构造 backend。

用法

[build-system]
requires = ["setuptools>=61"]
build-backend = "setuptools.build_meta"

[project]
name = "lightllm-example-plugin"
version = "0.0.1"
description = "Example LightLLM ops and att plugins"
requires-python = ">=3.10"

[project.entry-points."lightllm.ops_plugin"]
example_ops = "lightllm_example_plugin.register:register_ops"

[project.entry-points."lightllm.att_plugin"]
example_att = "lightllm_example_plugin.register:register_att"

[tool.setuptools.packages.find]
where = ["."]
include = ["lightllm_example_plugin*"]

同时注册 lightllm.ops_pluginlightllm.att_plugin。过程如下:

  1. pip install xxx 安装包
  2. ops 的 modules 由 lightllm_example_plugin.register:register_ops 函数返回
  3. att 的 modules 由 lightllm_example_plugin.register:register_att 函数返回
  4. 在实现的 module 中分别使用 register_opregister_att_backend 装饰器修饰函数和类
  5. 配合启动参数 --extra_ops example_ops--extra_att example_att 完成注册并使用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant