Skip to content

Commit 571b240

Browse files
authored
[Docs] adding new backends when using MMDeploy as a third package (#482)
* update doc * refine expression * cn doc
1 parent 32482e7 commit 571b240

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/en/tutorials/how_to_support_new_backends.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,20 @@ Although the backend engines are usually implemented in C/C++, it is convenient
229229
```
230230

231231
5. Add docstring and unit tests for new code :).
232+
233+
234+
### Support new backends using MMDeploy as a third party
235+
Previous parts show how to add a new backend in MMDeploy, which requires changing its source codes. However, if we treat MMDeploy as a third party, the methods above are no longer efficient. To this end, adding a new backend requires us pre-install another package named `aenum`. We can install it directly through `pip install aenum`.
236+
237+
After installing `aenum` successfully, we can use it to add a new backend through:
238+
```python
239+
from mmdeploy.utils.constants import Backend
240+
from aenum import extend_enum
241+
242+
try:
243+
Backend.get('backend_name')
244+
except Exception:
245+
extend_enum(Backend, 'BACKEND', 'backend_name')
246+
```
247+
248+
We can run the codes above before we use the rewrite logic of MMDeploy.

docs/zh_cn/tutorials/how_to_support_new_backends.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,19 @@ MMDeploy 中的后端必须支持 ONNX,因此后端能直接加载“.onnx”
229229
```
230230

231231
5. 为新后端引擎代码添加相关注释和单元测试 :).
232+
233+
234+
### 将MMDeploy作为第三方库时添加新后端
235+
前面的部分展示了如何在 MMDeploy 中添加新的后端,这需要更改其源代码。但是,如果我们将 MMDeploy 视为第三方,则上述方法不再有效。为此,添加一个新的后端需要我们预先安装另一个名为 `aenum` 的包。我们可以直接通过`pip install aenum`进行安装。
236+
237+
成功安装 `aenum` 后,我们可以通过以下方式使用它来添加新的后端:
238+
```python
239+
from mmdeploy.utils.constants import Backend
240+
from aenum import extend_enum
241+
242+
try:
243+
Backend.get('backend_name')
244+
except Exception:
245+
extend_enum(Backend, 'BACKEND', 'backend_name')
246+
```
247+
我们可以在使用 MMDeploy 的重写逻辑之前运行上面的代码,这就完成了新后端的添加。

0 commit comments

Comments
 (0)