-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Typing] bump mypy
version to 1.11.2
and fix many typing errors in cinn binding
#68372
[Typing] bump mypy
version to 1.11.2
and fix many typing errors in cinn binding
#68372
Conversation
Update 20240923
|
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.
CI 里貌似还有点因为切 PIR 导致的新问题和这两天因为没监控带来的新问题(比如 from_dlpack
那个我是肉眼没注意到的)~
tools/gen_pybind11_stub.py
Outdated
def post_process(output_dir: str): | ||
for root, _, files in os.walk(output_dir): | ||
if files: | ||
for f in files: | ||
if f.endswith('.pyi'): | ||
replace_bad_attr(str(Path(root) / f)) | ||
insert_import_modules(str(Path(root) / f)) |
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.
def post_process(output_dir: str): | |
for root, _, files in os.walk(output_dir): | |
if files: | |
for f in files: | |
if f.endswith('.pyi'): | |
replace_bad_attr(str(Path(root) / f)) | |
insert_import_modules(str(Path(root) / f)) | |
def post_process(output_dir: str): | |
for root, _, files in os.walk(output_dir): | |
if not files: | |
continue | |
for f in files: | |
if not f.endswith('.pyi'): | |
continue | |
replace_bad_attr(str(Path(root) / f)) | |
insert_import_modules(str(Path(root) / f)) |
这样可以有效减少两层缩进
tools/gen_pybind11_stub.py
Outdated
# python/paddle/_typing/libs/libpaddle/cinn/ir.pyi | ||
'cinn::ir::_paddle.Tensor_': 'typing.Any', | ||
# python/paddle/_typing/libs/libpaddle/cinn/common.pyi | ||
'None: typing.ClassVar[Type.cpp_type_t]': '# None: typing.ClassVar[Type.cpp_type_t]', |
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.
这里作为临时解决方案可以,但是如果考虑未来其他人再加一些新的符号导致挂了,可能仍然因为没有调试能力而关掉
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.
本 PR 可以暂时这样,因为我目前也没有更好的方案
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.
确实没啥好办法 ... ... 其实吧,我觉得我们是在给 c++ 接口拓展(如 pybind11)的不规范使用擦屁股 ... ... 不然为啥有的接口就转换的很好,有的就不行 ~
而出现 None
作为 python 成员变量的名称这种问题,应该在接口审核的时候就提出来,不然下游也没法用的 ~
唉 ... ... 俺是人微言轻,只能见招拆招了 ~
我在想,能不能在 post process 的时候做一步语法检查,检查出来语法错误就直接删掉那一行?
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.
c++ 接口拓展(如 pybind11)的不规范使用
这里我觉得是可以规范一下的,只是我现在不清楚,需要怎么修改才能规范化呢?就比如这里的 cinn::ir::_paddle.Tensor_
是怎么搞出来的呢?要怎么修改呢?(目前还没有去关注相关代码
None
这个问题比较明确,其实这里可以修改的,因为 cinn 的 python 端没啥用了,可以改成 None_
,这个感觉是否可以有一个什么拦截机制?(嵌套这么多层还真不是很好检测)
>>> paddle.base.core.cinn.common.Type.cpp_type_t.Const
<cpp_type_t.Const: 1>
>>> paddle.base.core.cinn.common.Type.cpp_type_t.None
File "<stdin>", line 1
paddle.base.core.cinn.common.Type.cpp_type_t.None
^^^^
SyntaxError: invalid syntax
>>> getattr(paddle.base.core.cinn.common.Type.cpp_type_t, "None")
<cpp_type_t.None: 0>
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.
cinn::ir::paddle.Tensor 是怎么搞出来的呢?要怎么修改呢?
这个确实比较奇怪,pybind11_stubgen 本来是可以拦截这类不合法的类型,比如之前 PYBIND11_ATTR_MAPPING
里面的那一堆东西 ~ 但是这个却拦截不了 ~
需要怎么修改才能规范化呢?
比如:
https://pybind11.readthedocs.io/en/latest/advanced/misc.html#avoiding-cpp-types-in-docstrings
导致出现此类问题的原因可能还有很多,只是目前木有精力去一一分析 ... ...
None 这个问题比较明确
确实是这样,本来问题不应该留到 python 这里才发现 ~
tools/gen_pybind11_stub.py
Outdated
@@ -43,6 +43,27 @@ | |||
if TYPE_CHECKING: | |||
from collections.abc import Generator | |||
|
|||
# some invalid attr can NOT be parsed. | |||
# to avoid sytax error, we can only do plain replacement. |
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.
# to avoid sytax error, we can only do plain replacement. | |
# to avoid syntax error, we can only do plain replacement. |
Update 20240924
|
python/paddle/utils/dlpack.py
Outdated
@@ -116,7 +117,9 @@ def to_dlpack(x: Tensor) -> CapsuleType: | |||
return x._to_dlpack() | |||
|
|||
|
|||
def from_dlpack(dlpack: SupportDLPack | CapsuleType) -> Tensor: | |||
def from_dlpack( | |||
dlpack: SupportDLPack | CapsuleType | npt.NDArray[Any], |
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.
mypy
版本至 1.11.2
mypy
version to 1.11.2
and fix many typing errors in cinn binding
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.
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.
LGTM
PR Category
User Experience
PR Types
Bug fixes
Description
mypy
版本至1.11.2
关联 #68278
@SigureMo