Skip to content

Commit 7e35222

Browse files
committed
增加返回码
1 parent ff38f64 commit 7e35222

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

ci_scripts/hooks/pre-doc-compile.sh

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,38 +121,26 @@ else
121121
handle_failure
122122
fi
123123

124-
echo "INFO: Validating API difference format "
125-
VALIDATION_OUTPUT=$(python "${APIMAPPING_ROOT}/tools/validate_api_difference_format.py" 2>&1)
126-
VALIDATION_EXIT_CODE=$?
124+
python "${APIMAPPING_ROOT}/tools/validate_api_difference_format.py"
127125

128-
# Check if validation output contains "100.00%"
129-
if [[ "$VALIDATION_EXIT_CODE" -eq 0 && "$VALIDATION_OUTPUT" == *"100.00%"* ]]; then
130-
echo "INFO: Validation passed successfully (100.00%)"
126+
# 获取上一条命令的退出状态码
127+
exit_code=$?
128+
129+
# 根据退出状态码决定后续操作
130+
if [ $exit_code -eq 0 ]; then
131+
echo "API DIFFERENCE FORMAT VALIDATE SUCCESS!"
132+
# 在这里继续添加您需要执行的命令
131133
else
132-
echo "ERROR: API difference validation failed. Expected 100.00%, got: '$VALIDATION_OUTPUT'"
134+
echo "ERROR: API DIFFERENCE FORMAT VALIDATE FAILURE! error code: $exit_code" >&2
133135
exit 1
134136
fi
135137

136-
echo "INFO: Validating PyTorch API mapping with --skip-url-check"
137-
VALIDATE_CMD="python ${APIMAPPING_ROOT}/tools/validate_pytorch_api_mapping.py --skip-url-check"
138-
VALIDATION_OUTPUT=$(eval "$VALIDATE_CMD" 2>&1)
139-
VALIDATION_EXIT_CODE=$?
138+
python "${APIMAPPING_ROOT}/tools/validate_pytorch_api_mapping.py" --skip-url-check
139+
exit_code=$?
140140

141-
# Check if script execution failed
142-
if [ $VALIDATION_EXIT_CODE -ne 0 ]; then
143-
echo "ERROR: validate_pytorch_api_mapping.py execution failed with exit code $VALIDATION_EXIT_CODE"
144-
echo "ERROR: Script output:"
145-
echo "$VALIDATION_OUTPUT"
146-
exit 1
141+
if [ $exit_code -eq 0 ]; then
142+
echo "PYTORCH API MAPPING VALIDATE SUCCESS!"
147143
else
148-
# Get last line of output
149-
LAST_LINE=$(echo "$VALIDATION_OUTPUT" | tail -n 1)
150-
151-
# Check if last line matches error string
152-
if [ "$LAST_LINE" = "VALIDATE PYTORCH_API_MAPPING ERROR!" ]; then
153-
echo "ERROR: Validation detected error: $LAST_LINE"
154-
exit 1
155-
else
156-
echo "INFO: API mapping validation passed successfully"
157-
fi
144+
echo "ERROR: PYTORCH API MAPPING VALIDATE FAILURE! error code: $exit_code" >&2
145+
exit 1
158146
fi

docs/guides/model_convert/convert_from_pytorch/tools/validate_api_difference_format.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
import re
5+
import sys
56
import traceback
67

78

@@ -798,12 +799,14 @@ def main():
798799
print(error)
799800
f.write(f"{error}\n")
800801
print(f"error log saved to: {error_file}")
802+
validator.print_results()
803+
return 1
801804
else:
802805
if os.path.exists(error_file):
803806
os.remove(error_file)
804-
805-
validator.print_results()
807+
validator.print_results()
808+
return 0
806809

807810

808811
if __name__ == "__main__":
809-
main()
812+
sys.exit(main())

docs/guides/model_convert/convert_from_pytorch/tools/validate_pytorch_api_mapping.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import random
55
import re
6+
import sys
67
import time
78
from collections import defaultdict
89
from urllib.parse import urlparse
@@ -27,6 +28,13 @@
2728
"composite_implement": "组合替代实现",
2829
}
2930

31+
white_list = [
32+
"torch.nn.Linear",
33+
"torch.nn.functional.linear",
34+
"torch.nn.ZeroPad1d",
35+
"torch.nn.ZeroPad3d",
36+
]
37+
3038
# 反向映射(中文到英文)
3139
REVERSE_CATEGORY_MAP = {v: k for k, v in CATEGORY_MAP.items()}
3240

@@ -388,6 +396,10 @@ def check_diff_doc_consistency(categories, base_dir):
388396
torch_api = torch_api.replace(r"\_", "_")
389397
if not torch_api:
390398
continue
399+
if not torch_api.startswith("torch."):
400+
continue
401+
if torch_api in white_list:
402+
continue
391403

392404
expected_apis[category_name].add(torch_api)
393405

@@ -418,6 +430,9 @@ def check_diff_doc_consistency(categories, base_dir):
418430
if filename.endswith(".md"):
419431
torch_api = filename[:-3] # 去掉.md后缀
420432

433+
if torch_api in white_list:
434+
continue
435+
421436
# 检查这个API是否在对应类别的表格中
422437
api_found = False
423438
for category in categories:
@@ -781,8 +796,10 @@ def main():
781796
f"校验完成,共发现 {total_warnings} 个警告,请查看生成的警告文件。"
782797
)
783798
if total_errors > 0:
784-
print("VALIDATE PYTORCH_API_MAPPING ERROR!")
799+
return 1
800+
801+
return 0
785802

786803

787804
if __name__ == "__main__":
788-
main()
805+
sys.exit(main())

0 commit comments

Comments
 (0)