-
Notifications
You must be signed in to change notification settings - Fork 295
【Hackathon 9th No.109】基于 Setuptools 80+ 版本自定义算子机制适配设计文档 #1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
SigureMo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
整体方案 OK,顺师傅太牛了!
|
|
||
| ``` | ||
|
|
||
| 在 `BuildExtension` 类中添加了 `_generate_python_api_file` 和 `custom_write_stub` 方法之后,实际上 `extension_utils.py` 中的 `bootstrap_context` 已经不需要了,因为每次 `BuildExtension` 都会执行构建,但是建议先保留 `bootstrap_context` 以防其他兼容性问题 (比如外部用户使用等): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
走不到的逻辑建议还是清理一下吧,按我理解现在是不走 bdist_egg 了是么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯~ 我测试是不需要了~ 因为 BuildExtension 的 _generate_python_api_file 会主动调用 custom_write_stub ~ 而 extension_utils.py 中的
@contextmanager
def bootstrap_context():
"""
Context to manage how to write `__bootstrap__` code in .egg
"""
origin_write_stub = bdist_egg.write_stub
bdist_egg.write_stub = custom_write_stub
yield
bdist_egg.write_stub = origin_write_stub
也没看到其他地方有用到 ~
| 总结: | ||
|
|
||
| - 增加兼容 `pip install .` 的方式安装 | ||
| - 增加兼容 `pip install .` 的方式安装之后,实际上已经解决了 setuptools 版本的兼容性问题,不需要针对 setuptools 的版本再进行判断 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
合理的方案,之前我也在考虑同时维护两套总是会有冗余的代码
|
|
||
| ``` | ||
|
|
||
| 改动之后,测试用例中需要修改 `len(custom_egg_path) == 2` 。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看了下前后的目录结构,目前认为是合理的
修改前,setuptools 79:
`-- mix_relu_extension-0.0.0-py3.10-linux-x86_64.egg
|-- EGG-INFO
| |-- PKG-INFO
| |-- SOURCES.txt
| |-- dependency_links.txt
| |-- native_libs.txt
| |-- not-zip-safe
| `-- top_level.txt
|-- mix_relu_extension.py
|-- mix_relu_extension_pd_.so
`-- version.txt
修改后,无论 setuptools 79 还是 80 都生成如下结构的代码
|-- mix_relu_extension
| |-- __init__.py
| `-- mix_relu_extension_pd_.so
`-- mix_relu_extension-0.0.0-py3.10.egg-info
|-- PKG-INFO
|-- SOURCES.txt
|-- dependency_links.txt
|-- not-zip-safe
`-- top_level.txt
修改前相当于一个目录既包含包信息也包含包实现,修改后两者分成两个目录了,都是合理的
这部分说明我觉得可以补充在 RFC 里
| ## 可行性分析 | ||
|
|
||
| 1. **技术可行性**:方案基于 setuptools 的标准扩展机制,技术上完全可行 | ||
| 2. **兼容性风险**:通过条件判断确保兼容 80.0- 的 Setuptools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该不需要判断了?
这里可以说明下是否影响已经生成的算子的加载,加载链路里的包结构与之前一致,应该不影响
另一方面是写好的代码是否需要修改构建系统(setup.py)以及是否需要修改算子注册逻辑,这里也是不影响的
SigureMo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
关联:
https://github.com/PaddlePaddle/community/blob/master/hackathon/hackathon_9th/%E3%80%90Hackathon_9th%E3%80%91%E4%B8%AA%E4%BA%BA%E6%8C%91%E6%88%98%E8%B5%9B%E2%80%94%E6%A1%86%E6%9E%B6%E5%BC%80%E5%8F%91%E4%BB%BB%E5%8A%A1%E5%90%88%E9%9B%86.md#no109-%E5%9F%BA%E4%BA%8E-setuptools-80-%E7%89%88%E6%9C%AC%E8%87%AA%E5%AE%9A%E4%B9%89%E7%AE%97%E5%AD%90%E6%9C%BA%E5%88%B6%E9%80%82%E9%85%8D
PaddlePaddle/Paddle#76008