Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
简介
把硬件抽象和第三方插件拆成两层,方便后续其他硬件以及 pip 的注册,当前提交不涉及现有推理路径。对外入口是
get_hardware_backend,当前还未被调用,启动服务不会涉及本地提交代码。lightllm/platform/ ├── __init__.py ├── ops │ ├── __init__.py │ ├── act.py │ ├── norm.py │ └── sampling.py ├── backends │ ├── __init__.py │ ├── cuda_like │ │ ├── __init__.py │ │ ├── graph.py │ │ ├── runtime.py │ │ └── ops │ │ ├── __init__.py │ │ ├── act.py │ │ ├── norm.py │ │ └── sampling.py │ └── ascend │ └── ... ├── base │ ├── __init__.py │ ├── backend.py │ ├── graph.py │ ├── registry.py │ └── runtime.py └── plugin ├── __init__.py ├── att.py ├── common.py └── ops.pybackends下面放置具体的硬件后端实现,包括graph、runtime和ops;platform/ops只定义各后端共用的算子(当前是部分,仅包含norm、act和sampling),不是具体的某个硬件实现。base是所有基类以及HardwareBackend的注册;plugin实现pip-installed包的注册;__init__.py提供对外接口get_hardware_backend,用来初始化全局实例(后续接入主推理流程时,可在确定具体硬件后端时立即调用以提早暴露错误)。做法
register_platform时只登记类(HardwareBackend子类)的路径,后续调用get_hardware_backend时才真正初始化。pip entry point-> CLI 匹配 ->register返回modules->import module-> 写入注册表。ops为默认值,再用已登记的 pip 字段替换。未登记的字段保持内置实现。--extra_ops/--extra_att(逗号分隔,对应 entry point 的左边名字)。入口只有
get_hardware_backend():先configure_plugins(),再按hardware_platform构造 backend。用法
同时注册
lightllm.ops_plugin和lightllm.att_plugin。过程如下:lightllm_example_plugin.register:register_ops函数返回lightllm_example_plugin.register:register_att函数返回--extra_ops example_ops和--extra_att example_att完成注册并使用新增 backend 和算子
和算子注册不同,这部分需修改
lightllm/platform代码。backends下新增目录,存放runtime、graph和ops。HardwareBackend子类,类上标明platform_name,构造时传入自己的runtime、graph和ops或者使用已有定义。register_platform注册类路径,参考上述说明,实际使用时检查正确性。如果实现和 CUDA 一样,可以不新建目录,像沐曦类似继承
CudaLikeBackend,只改platform_name并登记类的路径。最后,为启动参数--hardware_platform增加启动选项。对于新增的 backend,可以部分继承 CUDA 实现,但只能按照
runtime、graph和ops来组合。如runtime和graph分别使用CudaLikeRuntime和CudaLikeGraph;算子可以整体使用CUDA_LIKE_OPS,也可以部分使用如norm用CUDA_LIKE_NORM_OPS、act和sampling等用自己定义的。在
platform/ops新增dataclasses类,再给PlatformOps新增字段。每个平台的PlatformOps初始化都要带上这个新增算子。