-
Notifications
You must be signed in to change notification settings - Fork 871
[CI] 完善ci脚本,优化映射文档生成代码 #7556
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
[CI] 完善ci脚本,优化映射文档生成代码 #7556
Conversation
|
感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7556.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html |
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_scripts/hooks/pre-doc-compile.sh
Outdated
| if ! download_file "${BACKUP_API_ALIAS_MAPPING_URL}" "${TOOLS_DIR}/api_alias_mapping.json"; then | ||
| echo "ERROR: API alias mapping download failed (both main and backup URLs). Exiting." | ||
| echo "INFO: API alias mapping download failed. Checking for cached file..." | ||
| if check_cached_file; then |
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.
这里的逻辑需要优化一下,如果有1个没下载成功。则复制cache,同时后面也不需要再下载文件,也不需要再跑 api_alias_mapping判断、get_api_difference_info、generate_pytorch_api_mapping这些冗余逻辑。
也就是要么走 自动生成generate_pytorch_api_mapping整体的逻辑、要么复制cache。两者二选一。
| @@ -0,0 +1,375 @@ | |||
| import argparse | |||
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.
可以使用generate_api_difference来刷新一下目前已有的 api_difference,第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.
已修改,后续generate_api_difference没问题了会加到CI里
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.
已修改,后续generate_api_difference没问题了会加到CI里
这个本地自动化处理就可以。不用在CI里处理。
📚 本次 PR 文档预览链接(点击展开)
|
ci_scripts/hooks/pre-doc-compile.sh
Outdated
| echo "ERROR: API alias mapping download failed (both main and backup URLs). Exiting." | ||
| echo "INFO: API alias mapping download failed. Checking for cached file..." | ||
| if check_cached_file; then | ||
| if ! copy_cached_file; then |
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.
如果copy_cached_file了,那么就不用继续下载其他的文件,也不用跑下面的get_api_difference_info、generate_pytorch_api_mapping这些逻辑。直接就结束了。
| @@ -29,8 +29,7 @@ | |||
| ### 1. API 完全一致 | |||
| **分类简介** | |||
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.
这么写:
简介:此类 API 没有转写成本,两者用法完全一致, 只需将代码中所有torch前缀替换为 paddle即可。(也可只在文件最上方插入一行 import paddle as torch)。示例如下。
# PyTorch 写法
torch.eye(5)
torch.einsum('ii->i', x)
torch.nn.Softplus(beta=0.5, threshold=15)
# Paddle 写法
paddle.eye(5) #仅替换torch前缀
paddle.einsum('ii->i', x) #仅替换torch前缀
paddle.nn.Softplus(beta=0.5, threshold=15) #仅替换torch前缀| | 序号 | Pytorch 最新 release | Paddle develop | 备注 | | ||
| |------|-------------------|---------------|------| | ||
| | 序号 | Pytorch 最新 release | Paddle develop | 映射分类 | 备注 | | ||
| |------|-------------------|---------------|----------|------| | ||
|
|
||
| ### 2. 仅 API 调用方式不一致 | ||
| **分类简介** |
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.
简介:此类 API 的转写成本较低,只需对 API 调用方式进行改写,无需转写 API 参数部分。示例如下。
# PyTorch 写法
(给几个例子)
# Paddle 写法
(给个例子) # 仅API名称不同
(给个例子) # 仅API路径不同
(给个例子) # Tensor类方法改普通方法
(给个例子) # Tensor类方法改属性
(给个例子) # Tensor类属性改方法|
|
||
| ```python | ||
| # PyTorch 写法 | ||
| torch.numel(x) |
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.
改成这种写法吧,更直观一点,后面用 #号 注释下,表明干了什么,例如Tensor方法转属性。第1类也这么写。
torch.numel(x) -> x.size
x.matrix_exp() -> paddle.linalg.matrix_exp(x)
x.to_sparse(1) -> x.to_sparse_coo(1)
ci_scripts/hooks/pre-doc-compile.sh
Outdated
| } | ||
|
|
||
| # Download API alias mapping file | ||
| echo "INFO: Downloading API alias mapping file" |
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.
简化下写法,这5个下载逻辑,以及handle_download_failure逻辑,可以都统一合download_file。
download_file调用5行,每次传入一个文件即可。
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.
done
| ```python | ||
| # PyTorch 写法 -> Paddle 写法 | ||
| torch.numel(x) -> x.size # Tensor 方法转属性 | ||
| out = x.matrix_exp() -> paddle.linalg.matrix_exp(x) # 函数转方法 |
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可以把out去掉



No description provided.